ggplot画gene structure和alternative splicing | ggbio | GenomicFeatures

见上篇:genome browser | ggplot | 基因组可视化 | R | transcript | isoform

 

新需求(画出Fig 4D上面的辅图, Science, 2021):

 

山寨版,分析解构:

  • 首先去method里找,完全没写是什么工具画的,那就猜吧;
  • 其次看配色和对齐方式,基本肯定是ggplot画的,但仍然查不到是什么工具;
  • 最后,能猜到这是卡通图,并不是真实的数据(exon的长度过于平均);
  • 优点:辅图一目了然的AS event可视化,这种barplot的可视化(颜色对应,PSI和为1)更加易读,可以看出作者在AS可视化上的功底;
  • 细节也很到位:箭头和UTR

 

做一个API,自动读取AS event格式,添加箭头和UTR,以后可以常用。

 

不难

举个栗子:

# prepare kartoon data
# SE, Cassettes
AS_1 <- data.frame(EXONSTART=c(0,2,4),
                   EXONEND=c(1,3,5),
                   EXONSTRAND="+")
seg_1 <- data.frame(x=c(0, 1.5, 3.5),
                   xend=c(1.5, 3.5, 4.5),
                   y=0, yend=0)
AS_2 <- data.frame(EXONSTART=c(0,4),
                   EXONEND=c(1,5),
                   EXONSTRAND="+")
seg_2 <- data.frame(x=c(0, 1.5, 2.5, 3.5),
                   xend=c(1.5, 2.5, 3.5, 4.5),
                   y=0, yend=0)

options(repr.plot.width=2.5, repr.plot.height=1)
p1 <- ggplot() + 
  # add line and arrow
  # geom_hline(yintercept=0)+
  # geom_segment(x = 0, xend = 5.5, y = 0, yend = 0) +
  geom_segment(data=seg_1, aes(x=x,y=y,xend=xend,yend=yend), arrow=arrow(length=unit(0.3,"cm")), size=1) +
  # add exons
  geom_rect(data=AS_1, aes(xmin=EXONSTART, xmax=EXONEND,ymin= -0.1,ymax=0.1),fill="#4DAF4A")+
  # add UTR
  # geom_rect(data=UTR, aes(xmin=EXONSTART, xmax=EXONEND,ymin= -0.05,ymax=0.05),fill="#282a73")+
  # details
  labs(title = NULL,subtitle = NULL)+
  theme_void() +
  theme(legend.position = "none") +
  scale_x_continuous(expand = c(0.1, 0.1), limits = c(0, 5)) +
  scale_y_continuous(expand = c(0.02, 0.02), limits = c(-0.1, 0.1))
p1

options(repr.plot.width=2.5, repr.plot.height=1)
p2 <- ggplot() + 
  # add line and arrow
  # geom_hline(yintercept=0)+
  # geom_segment(x = 0, xend = 5.5, y = 0, yend = 0) +
  geom_segment(data=seg_2, aes(x=x,y=y,xend=xend,yend=yend), arrow=arrow(length=unit(0.3,"cm")), size=1) +
  # add exons
  geom_rect(data=AS_2, aes(xmin=EXONSTART, xmax=EXONEND,ymin= -0.1,ymax=0.1),fill="#984EA3")+
  # add UTR
  # geom_rect(data=UTR, aes(xmin=EXONSTART, xmax=EXONEND,ymin= -0.05,ymax=0.05),fill="#282a73")+
  # details
  labs(title = NULL,subtitle = NULL)+
  theme_void() +
  theme(legend.position = "none") +
  scale_x_continuous(expand = c(0.1, 0.1), limits = c(0, 5))+
  scale_y_continuous(expand = c(0.02, 0.02), limits = c(-0.1, 0.1))
p2

options(repr.plot.width=2.5, repr.plot.height=2)
AS1 <- cowplot::plot_grid(p1,p2,ncol = 1)
AS1

options(repr.plot.width=9, repr.plot.height=1)
cowplot::plot_grid(AS2, AS2, AS3, AS1,ncol = 4)

  

最终的模仿图,颜值还行:

 

 

分析案例:project/scPipeline/AS/suppa_AS_stat.ipynb

 

参考:

 

posted @ 2021-07-21 16:55  Life·Intelligence  阅读(779)  评论(0编辑  收藏  举报
TOP