『R画图脚本进阶』单个基因结构绘制.docxVIP

  • 4
  • 0
  • 约7.18千字
  • 约 5页
  • 2023-07-21 发布于陕西
  • 举报

『R画图脚本进阶』单个基因结构绘制.docx

『R画图脚本进阶』单个基因结构绘制 ... 果然需求是?产?驱动的第?要素 以前没想过要整,现在?需求了,其实 TBtools 就可以很?便的绘制,不过还是?痒想?R实现?下。就? ggplot2撸出来了。国际惯例,上图 Gh_A08G039000.jpg ?法和原理 其实就是把gff?件可视化?下,看GFF?件的介绍:陈连福?佬的博客-GFF3格式介绍 我们发现GFF3包含了基因整体信息,所以就想**根据gff?件信息,提取UTR和cds信息? ggplot2 的 geom_segment ??段?段?段的画出来。其实很简单。注意以下?个信息: strand,?向性。 exon是否包含UTR。 所以鉴于这两点也是写了两个判断。直来直去的代码有点辣眼睛,不过没时间了,先解决问题,以后在慢慢美化 _ 。 Script 更新后, 之前的不删除了,看最后能优化成什么样 drawGeneStructure = function(gff,size,lcolor){ names(gff) = c(chr,source,type,start,end,score,strand,phase,attributes) chr = unique(gff$chr) strand = unique(gff$strand) a = filter(gff,type == gene)$attributes desc = strsplit(a,split = ;)%%unlist(.) tpm1 = filter(gff,type == exon) tpm3 = filter(gff,type == five_prime_UTR| type == three_prime_UTR) if (strand == -){ tpm2 = data.frame(type = paste(tpm1$type,seq(1:nrow(tpm1)),sep = ), end = tpm1$start, start = tpm1$end, y = 1) xend = tpm2$end[1]-100 } else { tpm2 = data.frame(type = paste(tpm1$type,seq(1:nrow(tpm1)),sep = ), start = tpm1$start, end = tpm1$end, y = 1) xend = tpm2$end[1]+100 } p = ggplot(tpm2,aes(x = start,y = y))+ geom_segment(aes(x = tpm2$start[1],y = 0, xend = tpm2$end[nrow(tpm2)], yend = 0), color = lcolor)+ geom_segment(data = tpm2, mapping = aes(x = start,xend = end,y = 0, yend = 0,color = type), size = size)+ geom_segment(aes(x = tpm2$end[1],y = 0, xend = xend, yend = 0), arrow = arrow(length = unit(0.2,cm)), color = red)+ xlab(chr)+ theme(axis.ticks.y.left = element_blank(), axis.ticks.y = element_blank(), axis.line.y = element_blank(), axis.line.x.top = element_blank(), panel.grid = element_blank(), axis.text.y = element_blank(), plot.background = element_blank(), panel.background = element_blank(), axis.title.y = element_blank(), axis.line = element_line(colour = black,size = 1), legend.position = none) if(nrow(tpm3) != 0){ p = p + geom_segment(data = tpm3, mapping = aes(x = start,xend = end,y = 0, yend = 0), size = size, color = grey) } else { p = p } return(p) } 原始辣眼睛代码 start = tpm1$end, y = 1) tpm3 = data.frame(

文档评论(0)

1亿VIP精品文档

相关文档