- 4
- 0
- 约7.18千字
- 约 5页
- 2023-07-21 发布于陕西
- 举报
『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(
您可能关注的文档
最近下载
- 船体结构第一节船用钢材及连接方法略第二节船体结构第三节船体.ppt VIP
- 电路(一)试题 - 上海大学.doc VIP
- ISO∕IEC 42001-2023人工智能管理体系之16:“8 运行-8.2∕8.3 人工智能风险评估∕人工智能风险应对”解读、实施流程和风险描述(雷泽佳编制-2024).pdf VIP
- 【高考真题】2025年普通高等学校招生全国统一考试上海数学试卷(含答案).docx VIP
- ISO∕IEC 42001-2023人工智能管理体系之18:“9 绩效评价-9.1 监视、测量、分析和评价”解读、实施流程和风险描述(雷泽佳编制-2024).pdf VIP
- 耐心资本的投资策略分析.docx VIP
- 船体装配工艺作业指导书.pdf VIP
- 《旅行社概述》PPT课件.ppt VIP
- 房地产审计流程与所需资料清单.docx VIP
- ISO∕IEC 42001-2023人工智能管理体系之13:“7支持-7.4沟通”解读、实施流程和风险描述(雷泽佳编制-2024).pdf VIP
原创力文档

文档评论(0)