打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
技术贴 | R语言:绘制基因组基因箭头图

本文由微科盟阿童木根据实践经验而整理,希望对大家有帮助。

原创微文,欢迎转发转载。

举例介绍如何用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




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
「ggplot2练习」画基因结构图
R语言画图——添加显著性检验标记
Draw Gene Arrow Maps in 'ggplot2' · gggenes
R绘图
TCGA数据分析系列之火山图
ggplot2|undefined绘制KEGG气泡图
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服