有没有办法缩短gggenes中长的基因间区域?

问题描述 投票:0回答:1

我正在用 gggenes 可视化一系列基因簇,并且想知道是否有内置功能或解决方法来缩短感兴趣基因之间长的、未注释的区域。这是一组让我悲伤的基因:

df<-data.frame(start=c(594198,596540,598457,600085,983488,984345),
stop=c(596450,598423,600070,601182,984336,986495),
species=rep("Ferriphaselus amnicola",6),
gene=c("gene1","gene2","gene3","gene4","gene5","gene6"))

当你使用 gggenes 来可视化这一点时,你会得到一些不太漂亮的东西:

ggplot(df, aes(xmin = start, xmax = stop, y = species, fill = gene)) +
    geom_gene_arrow() +
    facet_wrap(~ species, scales = "free", ncol = 1) +
    scale_fill_brewer(palette = "Set3") +
    theme_genes()

理想情况下,我能够告诉 gggenes,当 2 个基因之间的核苷酸数量超过 x 时,用两个斜杠替换该基因组范围(按照文献中的惯例)。我正在想象这样的编辑我在powerpoint中拼凑了一下:

有没有一种简单的方法可以在 gggenes 中甚至在另一个包中执行此操作?

谢谢!

r ggplot2 visualization genome gggenes
1个回答
0
投票

这个确实很hacky,并且有很多手工代码。但作为一个起点,它可能会有所帮助:

library(dplyr)
library(ggplot2)
library(gggenes)
library(ggpubr)
library(gridExtra)
library(grid)

# Define common components
arrow_geom <- list(
  geom_gene_arrow(
    arrowhead_height = unit(12, "mm"),
    arrowhead_width = unit(6, "mm"),
    arrow_body_height = unit(6, "mm")
  ),
  geom_gene_label(aes(label = gene), height = unit(6, "mm"), grow = TRUE)
)

common_theme <- theme_classic() +
  theme(
    text = element_text(size=20),
    plot.margin = margin(0, 0, 0, 0, "cm")
  )

# Plot with legend
p0 <- df %>%
  ggplot(aes(xmin = start, xmax = stop, y = species, fill = gene)) +
  arrow_geom +
  facet_wrap(~ species, scales = "free", ncol = 1) +
  scale_fill_brewer(palette = "Set3") +
  common_theme

# Extract the legend
legend <- get_legend(p0)

# Plot for gene1 to gene4
p1 <- df %>%
  mutate(median_stop = median(stop)) %>%
  filter(stop > (median_stop - 10000) & stop < (median_stop + 10000)) %>%
  ggplot(aes(xmin = start, xmax = stop, y = species, fill = gene)) +
  arrow_geom +
  facet_wrap(~ species, scales = "free", ncol = 1) +
  scale_fill_brewer(palette = "Set3") +
  labs(y="") +
  guides(fill = "none") +
  common_theme

# Plot for gene5 to gene6
p2 <- df %>%
  mutate(x = median(stop)) %>%
  filter(stop > x + 100000) %>%
  mutate(species = "") %>%
  ggplot(aes(xmin = start, xmax = stop, y = species, fill = gene)) +
  arrow_geom +
  facet_wrap(~ species, scales = "free", ncol = 1) +
  scale_fill_manual(values = c("lightblue", "orange")) +
  labs(y = "") +
  guides(fill = "none") +
  common_theme +
  theme(
    axis.line.y = element_blank(),
    axis.ticks.y = element_blank(),
    strip.background = element_blank()
  )


dev.off()

# set the margins and combine all
p1 <- p1 + theme(plot.margin = margin(0, 0, 0, 0, "cm")) 
p2 <- p2 + theme(plot.margin = margin(0, 0, 0, 0, "cm"))
g <- arrangeGrob(
  p1, p2, legend,
  nrow = 1,
  widths = c(4, 2, 1)  
)
grid.draw(g)

© www.soinside.com 2019 - 2024. All rights reserved.