本文由微科盟阿童木根据实践经验而整理,希望对大家有帮助。
原创微文,欢迎转发转载。 举例介绍如何用R语言gggenes函数包把基因预测得到的gff或gtf文件(含基因位置信息)中的基因类型、位置可视化到图中。
注意: R version >= 3.6 gggenes依赖的ggfittext需要R 3.6以上,导致我用R 3.4.1安装gggenes失败。后来改用R 3.6.1成功安装。 Linux conda安装R 3.6 conda install -c r r=3.6 一, 输入数据 1. 基因组-基因-方向 library(ggplot2) library(gggenes) data(example_genes) head(example_genes) 图1
2 基因组-基因-亚基因 head(example_subgenes) 图2
一、画基因箭头图 1 基础绘图 ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + facet_wrap(~ molecule, scales = "free", ncol = 1) + scale_fill_brewer(palette = "Set3") 图3
2. 去掉背景 方法:theme_genes() ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + facet_wrap(~ molecule, scales = "free", ncol = 1) + scale_fill_brewer(palette = "Set3") + theme_genes() 图4
3. 按geneE对齐 方法:make_alignment_dummies() dummies <- make_alignment_dummies( example_genes, aes(xmin = start, xmax = end, y = molecule, id = gene), on = "genE" )
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) + geom_gene_arrow() + geom_blank(data = dummies) + facet_wrap(~ molecule, scales = "free", ncol = 1) + scale_fill_brewer(palette = "Set3") + theme_genes() 图5
4. 按设置箭头形状 方法:geom_gene_label() ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, label = gene)) + geom_gene_arrow(arrowhead_height = unit(3, "mm"), arrowhead_width = unit(1, "mm")) + geom_gene_label(align = "left") + geom_blank(data = dummies) + facet_wrap(~ molecule, scales = "free", ncol = 1) + scale_fill_brewer(palette = "Set3") + theme_genes() 图6
5. 控制箭头方向 example_genes$direction <- ifelse(example_genes$strand == "forward", 1, -1) ggplot( subset(example_genes, molecule == "Genome1"), aes(xmin = start, xmax = end, y = strand, fill = gene, forward = direction) ) + geom_gene_arrow() + theme_genes() 图7
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, forward = direction)) + geom_gene_arrow() + facet_wrap(~ molecule, scales = "free", ncol = 1) + scale_fill_brewer(palette = "Set3") + theme_genes()
图8
6. 标记亚基因位置 方法:geom_subgene_arrow() ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule)) + facet_wrap(~ molecule, scales = "free", ncol = 1) + geom_gene_arrow(fill = "white") + geom_subgene_arrow(data = example_subgenes, aes(xmin = start, xmax = end, y = molecule, fill = gene, xsubmin = from, xsubmax = to), color="black", alpha=.7) + theme_genes()
图9
7. 标记某基因组中某基因的亚基因位置 方法:geom_subgene_label() ggplot(subset(example_genes, molecule == "Genome4" & gene == "genA"), aes(xmin = start, xmax = end, y = strand) ) + geom_gene_arrow() + geom_gene_label(aes(label = gene)) + geom_subgene_arrow( data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"), aes(xsubmin = from, xsubmax = to, fill = subgene) ) + geom_subgene_label( data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"), aes(xsubmin = from, xsubmax = to, label = subgene), min.size = 0 )
图10
|