• 主页
  • 课程

    关于课程

    • 课程归档
    • 成为一名讲师
    • 讲师信息
    同等学历教学

    同等学历教学

    免费
    阅读更多
  • 特色
    • 展示
    • 关于我们
    • 问答
  • 事件
  • 个性化
  • 博客
  • 联系
  • 站点资源
    有任何问题吗?
    (00) 123 456 789
    weinfoadmin@weinformatics.cn
    注册登录
    恒诺新知
    • 主页
    • 课程

      关于课程

      • 课程归档
      • 成为一名讲师
      • 讲师信息
      同等学历教学

      同等学历教学

      免费
      阅读更多
    • 特色
      • 展示
      • 关于我们
      • 问答
    • 事件
    • 个性化
    • 博客
    • 联系
    • 站点资源

      未分类

      • 首页
      • 博客
      • 未分类
      • transPlotR 优雅的绘制基因转录本结构

      transPlotR 优雅的绘制基因转录本结构

      • 发布者 jiangxingyu
      • 分类 未分类
      • 日期 2022年7月13日
      测试开头

      无能为力

      transPlotR 优雅的绘制基因转录本结构

      1引言

      这个工作大概陆陆续续花费了一周多的时间基本完善的差不多了。你会想不会有这么多轮子了吗?(R 包),比如 ggtranscript, gggenes, wiggleplotr, Gviz 等等, 有些包用起来太复杂,有些又或者达不到自己的可视化要求,功能太少等等的不足或者限制,说白了也许就是自己屁事多, 我觉得比较好看的是 IGV 里面的转录本结构比较漂亮,也符合生物学意义。

      有时候需要逼自己造个轮子出来方便自己使用,于是写了这个 transPlotR package, 非常简单,就只有一个函数,前前后后也增加了很多功能,硬扣细节,最终搞了个差不多的样子出来。也分享给大家使用。

      2介绍

      只有一个函数 trancriptVis 来可视化基因结构,需要输入你的 GTF 文件就行了(你可以使用 rtracklayer 进行读取),操作方便简洁。

      主要功能:

      • 绘制编码或者非编码基因的转录本结构。
      • 支持多个基因。
      • 折叠多个转录本。
      • 支持跨距离,跨染色体基因可视化。
      • 极坐标展示基因结构。
      • 添加新 style 的箭头表示转录方向。
      • 绘制相对距离的位置坐标(以转录起始位置/终止位置为起点)。
      • 反转负链基因的结构位置。
      • …

      觉得有用的小伙伴欢迎在我的 github 上面留下你们的小星星哦!

      3安装

      # install.packages("devtools")
      devtools::install_github("junjunlab/transPlotR")

      github 地址:

      https://github.com/junjunlab/transPlotR

      transPlotR 优雅的绘制基因转录本结构

      参考手册链接:

      https://github.com/junjunlab/transPlotR/wiki/TransPlot-documentation

      4单个基因绘制

      非编码基因:

      # load test data
      data(gtf)

      # non-coding gene
      trancriptVis(gtfFile = gtf,
                   gene = 'Xist')
      transPlotR 优雅的绘制基因转录本结构

      编码基因:

      粗的代表 CDS 区域,较粗的为 UTR,细线为内含子,箭头方向为基因转录方向。

      # coding gene
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog')
      transPlotR 优雅的绘制基因转录本结构

      修改填充颜色:

      # change fill color
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   exonFill = '#CCFF00')
      transPlotR 优雅的绘制基因转录本结构

      修改标签大小,颜色及位置:

      # change label size,color and position
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   textLabelSize = 4,
                   textLabelColor = 'red',
                   relTextDist = 0)
      transPlotR 优雅的绘制基因转录本结构

      标注基因名:

      # aes by gene name
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   textLabel = 'gene_name')
      transPlotR 优雅的绘制基因转录本结构

      用转录本映射颜色:

      # color aes by transcript
      trancriptVis(gtfFile = gtf,
                   gene = 'Tpx2',
                   exonColorBy = 'transcript_id')
      transPlotR 优雅的绘制基因转录本结构

      修改箭头颜色及类型:

      # change arrow color and type
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   arrowCol = 'orange',
                   arrowType = 'closed')
      transPlotR 优雅的绘制基因转录本结构

      如果没有内含子,可以改变箭头颜色,更加容易分辨:

      # no intron gene and add arrow color
      # change arrow color and type
      trancriptVis(gtfFile = gtf,
                   gene = 'Jun',
                   textLabel = 'gene_name',
                   arrowCol = 'white',
                   arrowType = 'closed') +
        theme_void()
      transPlotR 优雅的绘制基因转录本结构

      添加箭头数量:

      # add arrow breaks
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   arrowCol = 'orange',
                   arrowType = 'closed',
                   arrowBreak = 0.1)
      transPlotR 优雅的绘制基因转录本结构

      指定特定的转录本进行可视化:

      # draw specific transcript
      p1 <- trancriptVis(gtfFile = gtf,
                         gene = 'Commd7')

      p2 <- trancriptVis(gtfFile = gtf,
                         gene = 'Commd7',
                         myTranscript = c('ENSMUST00000071852','ENSMUST00000109782'))

      # combine
      cowplot::plot_grid(p1,p2,ncol = 2,align = 'hv')
      transPlotR 优雅的绘制基因转录本结构

      5新的箭头类型

      这种在一些文献里可以见到,标注出来代表基因的转录方向,我这里也添加了这个功能,可以实现这种效果。

      对比:

      # add specific arrow
      pneg <- trancriptVis(gtfFile = gtf,
                           gene = 'Gucy2e',
                           newStyleArrow = T)

      ppos <- trancriptVis(gtfFile = gtf,
                           gene = 'Tex15',
                           newStyleArrow = T)

      # combine
      cowplot::plot_grid(pneg,ppos,ncol = 2,align = 'hv')
      transPlotR 优雅的绘制基因转录本结构

      我们可以去除正常的箭头:

      # remove normal arrow
      trancriptVis(gtfFile = gtf,
                   gene = 'Fat1',
                   newStyleArrow = T,
                   addNormalArrow = F)
      transPlotR 优雅的绘制基因转录本结构

      如你所见,每个转录本的新箭头是 与其转录本的长度成比例 的,是一种相对长度, 对于较短的转录本来说, 同样的相对长度可能会带来不一样的效果,比如一些短的转录本结构箭头太短。

      这里我们可以设置为绝对长度,使每个转录本的箭头保持一样长:

      # draw absolute specific arrow
      trancriptVis(gtfFile = gtf,
                   gene = 'Fat1',
                   newStyleArrow = T,
                   addNormalArrow = F,
                   absSpecArrowLen = T)
      transPlotR 优雅的绘制基因转录本结构

      我们还可以控制箭头的颜色,大小及位置:

      # change position size color and height
      trancriptVis(gtfFile = gtf,
                   gene = 'Fat1',
                   newStyleArrow = T,
                   addNormalArrow = F,
                   speArrowRelPos = 0.5,
                   speArrowLineSize = 1,
                   speArrowCol = 'red',
                   speArrowRelHigh = 3)
      transPlotR 优雅的绘制基因转录本结构

      绘制极坐标下的转录本:

      # circle plot with specific arrow
      trancriptVis(gtfFile = gtf,
                   gene = 'F11',
                   newStyleArrow = T,
                   addNormalArrow = F,
                   circle = T,
                   ylimLow = -2)
      transPlotR 优雅的绘制基因转录本结构

      极坐标下的绝对箭头长度因为弧度不一样,所以长度也会相应改变,也是比较好理解的:

      # circle plot with absolute specific arrow
      trancriptVis(gtfFile = gtf,
                   gene = 'F11',
                   newStyleArrow = T,
                   addNormalArrow = F,
                   circle = T,
                   ylimLow = -2,
                   absSpecArrowLen = T)
      transPlotR 优雅的绘制基因转录本结构

      6多基因转录本结构绘制

      支持多个基因多个转录本结构的绘制,但是首先记住,我们是在基因组坐标里绘图的,要想绘制多基因呈现一个较好的效果图,首先确定你的基因们是 相互靠近的,且是 位于同一染色体上面的,这很合理。

      # support multiple gene
      # should on same chromosome and close to each other
      trancriptVis(gtfFile = gtf,
                   gene = c('Trmt6','Mcm8','Crls1','Lrrn4','Fermt1'),
                   textLabel = 'gene_name')
      transPlotR 优雅的绘制基因转录本结构

      下面展示的是 IGV 的结果,有一些差异,因为使用的注释文件不太一致:

      transPlotR 优雅的绘制基因转录本结构

      对基因进行映射,改变箭头长度:

      # color by gene and change arrow length
      trancriptVis(gtfFile = gtf,
                   gene = c('Crls1','Fermt1'),
                   textLabel = 'gene_name',
                   exonColorBy = 'gene_name',
                   newStyleArrow = T,
                   speArrowRelLen = 1)
      transPlotR 优雅的绘制基因转录本结构

      我们可以将多个转录本折叠为一个:

      # collapse gene
      trancriptVis(gtfFile = gtf,
                   gene = c('Trmt6','Mcm8','Crls1','Lrrn4','Fermt1'),
                   textLabel = 'gene_name',
                   collapse = T,
                   relTextDist = 0.2)
      transPlotR 优雅的绘制基因转录本结构

      7给定区域绘图

      你可以指定染色体,起始位置和终止位置来进行绘图:

      # support plot at a given region
      trancriptVis(gtfFile = gtf,
                   Chr = 11,
                   posStart = 69609973,
                   posEnd = 69624790)
      transPlotR 优雅的绘制基因转录本结构

      8环形图

      我们可以在极坐标系里对基因结构进行展示:

      # draw circle structure
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabelSize = 4,
                   circle = T)
      transPlotR 优雅的绘制基因转录本结构

      让圆圈变小点:

      # change circle small
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0)
      transPlotR 优雅的绘制基因转录本结构

      改变圆圈的夹角:

      # change circle angle
      c1 <- trancriptVis(gtfFile = gtf,
                   gene = 'F11',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   openAngle = 0)

      c2 <- trancriptVis(gtfFile = gtf,
                   gene = 'F11',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   openAngle = 0.2)

      # combine
      cowplot::plot_grid(c1,c2,ncol = 2,align = 'hv')
      transPlotR 优雅的绘制基因转录本结构

      对转录本进行映射填充颜色:

      # chenge aes fill
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   exonColorByTrans = T)
      transPlotR 优雅的绘制基因转录本结构

      改变线颜色:

      # change segment color
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   exonColorByTrans = T,
                   circSegCol = 'black')
      transPlotR 优雅的绘制基因转录本结构

      添加基因名:

      # add gene name
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabel = 'gene_name',
                   textLabelSize = 5,
                   circle = T,
                   ylimLow = 0,
                   exonColorByTrans = T)
      transPlotR 优雅的绘制基因转录本结构

      移除连线:

      # remove line
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabel = 'gene_name',
                   textLabelSize = 5,
                   circle = T,
                   ylimLow = 0,
                   exonColorByTrans = T,
                   text_only = T)
      transPlotR 优雅的绘制基因转录本结构

      绘制多个基因:

      # multiple gene
      trancriptVis(gtfFile = gtf,
                   gene = c('Pfn1','Eno3','Spag7'),
                   textLabel = 'gene_name',
                   textLabelSize = 2,
                   circle = T,
                   ylimLow = -5,
                   text_only = T,
                   circSegCol = 'grey80',
                   exonColorByTrans = T)
      transPlotR 优雅的绘制基因转录本结构

      标记转录本名称:

      # textlabel with transcript_name
      trancriptVis(gtfFile = gtf,
                   gene = 'Gucy2e',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   textLabel = 'transcript_name',
                   addNormalArrow = F,
                   newStyleArrow = T)
      transPlotR 优雅的绘制基因转录本结构

      9跨距离/染色体绘图

      想象你有多个基因,它们可能距离很远或者不在同一个染色体上面,你想绘制它们的转录本结构可以使用 单基因循环批量绘图, 这是一种解决方法。但是非常的不人性化,这里提供了解决这个问题的方案, 分面绘图 来实现。

      批量循环绘图:

      这里选了三个基因分别位于1号染色体的首/中间/末尾的位置,跨度很大来作为示范:

      # single plot
      lapply(c('Camk1g','Daw1','Oprk1'), function(x){
        trancriptVis(gtfFile = gtf,
                     gene = x,
                     textLabel = 'gene_name')
      }) -> plist

      # combine
      cowplot::plot_grid(plotlist = plist,ncol = 3,align = 'hv')
      transPlotR 优雅的绘制基因转录本结构

      按照前面一起绘图将会得到下面结果:

      # plot tegether
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   textLabel = 'gene_name')
      transPlotR 优雅的绘制基因转录本结构

      对基因进行分面展示:

      # facet by gene
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   facetByGene = T)
      transPlotR 优雅的绘制基因转录本结构

      去除正常箭头,添加新样式箭头,以绝对距离展示:

      # add new arrow and remove normal arrow
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   facetByGene = T,
                   newStyleArrow = T,
                   absSpecArrowLen = T,
                   speArrowRelLen = 0.1,
                   addNormalArrow = F)
      transPlotR 优雅的绘制基因转录本结构

      绘制不同染色体的基因:

      这里的三个基因分别位于染色体1/2/3上作为示范:

      # for different chromosome genes
      # chr1:Camk1g chr2:Duox2 chr3:Ttll7
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Duox2','Ttll7'),
                   facetByGene = T)
      transPlotR 优雅的绘制基因转录本结构

      老铁没毛病!

      10相对距离

      如你所见,上面的绘图我们都是基因 基因组坐标系统下 进行绘制的,如果我们想在同一坐标下比较不同基因不同转录本将会变得困难。这里提供了可以 将坐标转换为相对坐标 来进行展示比较。

      只需要设置 forcePosRel = T:

      # transform relative position
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   facetByGene = T,
                   newStyleArrow = T,
                   absSpecArrowLen = T,
                   speArrowRelLen = 0.1,
                   addNormalArrow = F,
                   forcePosRel = T)
      transPlotR 优雅的绘制基因转录本结构

      我们可以看到都是以左边为 0 起始位点来绘图的,横坐标的长度代表了整个转录本的长度。

      美化一下:

      # ajusted with facet parameters
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   facetByGene = T,
                   newStyleArrow = T,
                   absSpecArrowLen = T,
                   speArrowRelLen = 0.1,
                   addNormalArrow = F,
                   forcePosRel = T,
                   ncolGene = 1,
                   scales = 'free_y',
                   strip.position = 'left',
                   textLabelSize = 2,
                   exonColorBy = 'gene_name',
                   textLabel = 'transcript_name',
                   panel.spacing = 0)
      transPlotR 优雅的绘制基因转录本结构

      环形图展示:

      # cicular plot with relative position
      trancriptVis(gtfFile = gtf,
                   gene = 'Nanog',
                   textLabelSize = 4,
                   circle = T,
                   ylimLow = 0,
                   textLabel = 'transcript_name',
                   addNormalArrow = F,
                   newStyleArrow = T,
                   exonColorBy = 'transcript_name',
                   forcePosRel = T)
      transPlotR 优雅的绘制基因转录本结构

      11反转负链

      在上面的图中可以看到,将坐标系转为相对以后, 负链上的基因还是以从右往左进行的,要 比较似乎还需要反转一下负链基因的位置。这里提供了反转负链的revNegStrand = T 参数来让比较更加方便和易于理解。

      # reverse negtive strand
      trancriptVis(gtfFile = gtf,
                   gene = c('Camk1g','Daw1','Oprk1'),
                   facetByGene = T,
                   newStyleArrow = T,
                   absSpecArrowLen = T,
                   speArrowRelLen = 0.1,
                   addNormalArrow = F,
                   forcePosRel = T,
                   revNegStrand = T)
      transPlotR 优雅的绘制基因转录本结构

      可以看到 Camk1g 这个位于负链的基因所有位置都被反转了,此外,对应的新样式的箭头也一起改变了。注意这里的箭头方向不再有意义了。

      美化调整一下:

      # ajusted with facet parameters
      p1 <- trancriptVis(gtfFile = gtf,
                         gene = c('Camk1g','Daw1','Oprk1'),
                         facetByGene = T,
                         newStyleArrow = T,
                         absSpecArrowLen = T,
                         speArrowRelLen = 0.1,
                         addNormalArrow = F,
                         forcePosRel = T,
                         ncolGene = 1,
                         scales = 'free_y',
                         strip.position = 'left',
                         textLabelSize = 2,
                         exonColorBy = 'gene_name',
                         textLabel = 'transcript_name',
                         panel.spacing = 0)

      # reverse negtive strand
      p2 <- trancriptVis(gtfFile = gtf,
                         gene = c('Camk1g','Daw1','Oprk1'),
                         facetByGene = T,
                         newStyleArrow = T,
                         absSpecArrowLen = T,
                         speArrowRelLen = 0.1,
                         addNormalArrow = F,
                         forcePosRel = T,
                         ncolGene = 1,
                         scales = 'free_y',
                         strip.position = 'left',
                         textLabelSize = 2,
                         exonColorBy = 'gene_name',
                         textLabel = 'transcript_name',
                         panel.spacing = 0,
                         revNegStrand = T)

      # combine
      cowplot::plot_grid(plotlist = list(p1,p2),ncol = 2,align = 'hv')
      transPlotR 优雅的绘制基因转录本结构

      左边是没有反转的,右边是反转的,对比一下,看起来更加好比较了。

      更多的参数见:

      ?trancriptVis

      12结尾

      有其它建议或者疑问请在 github 提问。

      transPlotR 优雅的绘制基因转录本结构



      欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群 (微信交流群需收取20元入群费用(防止骗子和便于管理))。



      老俊俊微信:


      transPlotR 优雅的绘制基因转录本结构

      知识星球:


      transPlotR 优雅的绘制基因转录本结构


      所以今天你学习了吗?

      今天的分享就到这里了,敬请期待下一篇!

      最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!

      如果觉得对您帮助很大,赏杯快乐水喝喝吧!




       往期回顾 





      ◀ggarchery 添加个性化箭头

      ◀scRNAtoolVis 0.0.3 版本更新

      ◀customize 你的 GSEA 图

      ◀GseaVis 优雅的可视化 GSEA 富集结果

      ◀GSEA 图是如何画出来的? (源码解析)

      ◀clusterProfiler 的可视化大全

      ◀clusterProfiler 做 GSEA 富集分析

      ◀深度神经网络学习对单细胞数据进行清洗去噪

      ◀ggpie 解决你的所有饼图绘制

      ◀Bigwig 可视化用 tackPlotR 试试看?

      ◀…

      测试结尾

      请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!

      • 分享:
      作者头像
      jiangxingyu

      上一篇文章

      单细胞多样本整合之harmony
      2022年7月13日

      下一篇文章

      介绍一个新的基线特征表绘制R包
      2022年7月16日

      你可能也喜欢

      2-1675088548
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      30 1月, 2023
      9-1675131201
      如何快速批量修改 Git 提交记录中的用户信息
      26 1月, 2023
      8-1678501786
      肿瘤细胞通过改变CD8+ T细胞中的丙酮酸利用和琥珀酸信号来调控抗肿瘤免疫应答。
      7 12月, 2022

      搜索

      分类

      • R语言
      • TCGA数据挖掘
      • 单细胞RNA-seq测序
      • 在线会议直播预告与回放
      • 数据分析那些事儿分类
      • 未分类
      • 生信星球
      • 老俊俊的生信笔记

      投稿培训

      免费

      alphafold2培训

      免费

      群晖配置培训

      免费

      最新博文

      Nature | 单细胞技术揭示衰老细胞与肌肉再生
      301月2023
      lncRNA和miRNA生信分析系列讲座免费视频课和课件资源包,干货满满
      301月2023
      如何快速批量修改 Git 提交记录中的用户信息
      261月2023
      logo-eduma-the-best-lms-wordpress-theme

      (00) 123 456 789

      weinfoadmin@weinformatics.cn

      恒诺新知

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      链接

      • 课程
      • 事件
      • 展示
      • 问答

      支持

      • 文档
      • 论坛
      • 语言包
      • 发行状态

      推荐

      • iHub汉语代码托管
      • iLAB耗材管理
      • WooCommerce
      • 丁香园论坛

      weinformatics 即 恒诺新知。ICP备案号:粤ICP备19129767号

      • 关于我们
      • 博客
      • 联系
      • 成为一名讲师

      要成为一名讲师吗?

      加入数以千计的演讲者获得100%课时费!

      现在开始

      用你的站点账户登录

      忘记密码?

      还不是会员? 现在注册

      注册新帐户

      已经拥有注册账户? 现在登录

      close
      会员购买 你还没有登录,请先登录
      • ¥99 VIP-1个月
      • ¥199 VIP-半年
      • ¥299 VIP-1年
      在线支付 激活码

      立即支付
      支付宝
      微信支付
      请使用 支付宝 或 微信 扫码支付
      登录
      注册|忘记密码?