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

transPlotR是一个R包,用于绘制基因结构,包括编码和非编码基因的转录本。它支持多基因、跨染色体、折叠转录本等多种可视化,并提供了新样式箭头、极坐标展示等功能。用户可以自定义填充颜色、标签、箭头等,便于基因结构比较和分析。
摘要由CSDN通过智能技术生成

无能为力

56632cb09b5c0ebfc858678b471dcd44.gif

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

f0932557d4c8197b6f916ee1e0244672.png

参考手册链接:

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

4单个基因绘制

非编码基因:

# load test data
data(gtf)

# non-coding gene
trancriptVis(gtfFile = gtf,
             gene = 'Xist')
bb02768e1c13658619a25d81588dbcf8.png

编码基因:

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

# coding gene
trancriptVis(gtfFile = gtf,
             gene = 'Nanog')
e53e11f3c1b047774e1c9f0dad34f98b.png

修改填充颜色:

# change fill color
trancriptVis(gtfFile = gtf,
             gene = 'Nanog',
             exonFill = '#CCFF00')
ac5cf9b25c31f49958b501cb8fde8aa5.png

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

# change label size,color and position
trancriptVis(gtfFile = gtf,
             gene = 'Nanog',
             textLabelSize = 4,
             textLabelColor = 'red',
             relTextDist = 0)
393de0b52840ce54b64f1979dbd39e68.png

标注基因名:

# aes by gene name
trancriptVis(gtfFile = gtf,
             gene = 'Nanog',
             textLabel = 'gene_name')
07f207bbc78225a9bd55741b218b0b85.png

用转录本映射颜色:

# color aes by transcript
trancriptVis(gtfFile = gtf,
             gene = 'Tpx2',
             exonColorBy = 'transcript_id')
b61f31318e0d84859f1c95a19352f66f.png

修改箭头颜色及类型:

# change arrow color and type
trancriptVis(gtfFile = gtf,
             gene = 'Nanog',
             arrowCol = 'orange',
             arrowType = 'closed')
1a00f3b176e69923c54de786ef553276.png

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

# 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()
6a2151b029526b72c1522a251bba9699.png

添加箭头数量:

# add arrow breaks
trancriptVis(gtfFile = gtf,
             gene = 'Nanog',
             arrowCol = 'orange',
             arrowType = 'closed',
             arrowBreak = 0.1)
aa9f23097e710fd88734af4c8b1b0427.png

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

# 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')
adbaf199eda87ad66d745947400bafdb.png

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')
9b521281173c0289b8da2d7e85a4da45.png

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

# remove normal arrow
trancriptVis(gtfFile = gtf,
             gene = 'Fat1',
             newStyleArrow = T,
             addNormalArrow = F)
512f73d0e18f990af22f831a1c6185fc.png

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

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

# draw absolute specific arrow
trancriptVis(gtfFile = gtf,
             gene = 'Fat1',
             newStyleArrow = T,
             addNormalArrow = F,
             absSpecArrowLen = T)
3e705f9e1622dd126b0e35640f578010.png

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

# change position size color and height
trancriptVis(gtfFile = gtf,
             gene = 'Fat1',
             newStyleArrow = T,
             addNormalArrow = F,
             speArrowRelPos = 0.5,
             speArrowLineSize = 1,
             speArrowCol = 'red',
             speArrowRelHigh = 3)
485f9de2bf1814d9faf2af772261c4b3.png

绘制极坐标下的转录本:

# circle plot with specific arrow
trancriptVis(gtfFile = gtf,
             gene = 'F11',
             newStyleArrow = T,
             addNormalArrow = F,
             circle = T,
             ylimLow = -2)
08f5616ef9302db6e5bbc328b18b8757.png

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

# circle plot with absolute specific arrow
trancriptVis(gtfFile = gtf,
             gene = 'F11',
             newStyleArrow = T,
             addNormalArrow = F,
             circle = T,
             ylimLow = -2,
             absSpecArrowLen = T)
ad727ce9f7c44cbe2500a2611e212ce7.png

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')
7e238359f4ff008140f4c1ab3f3edd46.png

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

0e862e77fcca8d2778d66d35b5069101.png

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

# color by gene and change arrow length
trancriptVis(gtfFile = gtf,
             gene = c('Crls1','Fermt1'),
             textLabel = 'gene_name',
             exonColorBy = 'gene_name',
             newStyleArrow = T,
             speArrowRelLen = 1)
3e52a64cae0303cf52fe451983711784.png

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

# collapse gene
trancriptVis(gtfFile = gtf,
             gene = c('Trmt6','Mcm8','Crls1','Lrrn4','Fermt1'),
             textLabel = 'gene_name',
             collapse = T,
             relTextDist = 0.2)
d35565a2ff236f018069c5609ebe547a.png

7给定区域绘图

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

# support plot at a given region
trancriptVis(gtfFile = gtf,
             Chr = 11,
             posStart = 69609973,
             posEnd = 69624790)
ac61ea881aab6a58060b0f340f533b35.png

8环形图

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

# draw circle structure
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabelSize = 4,
             circle = T)
409e2458a078ba107fd0ca1ca8afbd7f.png

让圆圈变小点:

# change circle small
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabelSize = 4,
             circle = T,
             ylimLow = 0)
734933d4b0553c544130976520213102.png

改变圆圈的夹角:

# 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')
0a85b499e5e2b2b8c27d5d59f2c06051.png

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

# chenge aes fill
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabelSize = 4,
             circle = T,
             ylimLow = 0,
             exonColorByTrans = T)
5ab1bb6ec3dd731c0c45b46b0e8c744a.png

改变线颜色:

# change segment color
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabelSize = 4,
             circle = T,
             ylimLow = 0,
             exonColorByTrans = T,
             circSegCol = 'black')
908ebced9434762014056730e399b52c.png

添加基因名:

# add gene name
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabel = 'gene_name',
             textLabelSize = 5,
             circle = T,
             ylimLow = 0,
             exonColorByTrans = T)
ea0aa9aff41f6da866d1de6b6050fb8b.png

移除连线:

# remove line
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabel = 'gene_name',
             textLabelSize = 5,
             circle = T,
             ylimLow = 0,
             exonColorByTrans = T,
             text_only = T)
413721d5e73358acb907ae6b558c01d4.png

绘制多个基因:

# 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)
da6bcd28c42cddddb165292628695dcf.png

标记转录本名称:

# textlabel with transcript_name
trancriptVis(gtfFile = gtf,
             gene = 'Gucy2e',
             textLabelSize = 4,
             circle = T,
             ylimLow = 0,
             textLabel = 'transcript_name',
             addNormalArrow = F,
             newStyleArrow = T)
f39ece35b50775ddd6fc97c8117db24f.png

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')
b7b0faa4e3fbbaade5945223403430a6.png

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

# plot tegether
trancriptVis(gtfFile = gtf,
             gene = c('Camk1g','Daw1','Oprk1'),
             textLabel = 'gene_name')
672498174e391b46c3a93b195ccbd722.png

对基因进行分面展示:

# facet by gene
trancriptVis(gtfFile = gtf,
             gene = c('Camk1g','Daw1','Oprk1'),
             facetByGene = T)
b29b959cbaa76acbcbdbb54697750adf.png

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

# 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)
0c060f93a70e7d281a39ff3c13417013.png

绘制不同染色体的基因:

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

# for different chromosome genes
# chr1:Camk1g chr2:Duox2 chr3:Ttll7
trancriptVis(gtfFile = gtf,
             gene = c('Camk1g','Duox2','Ttll7'),
             facetByGene = T)
272480029399b3484e066918bb462313.png

老铁没毛病!

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)
4f5fc61077fd9d39427349ff8c3e31e6.png

我们可以看到都是以左边为 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)
2a90912674d4483504379f036766bf51.png

环形图展示:

# 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)
27020f0dace25a8b555eab3d75aab9c8.png

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)
1d950ab36cf6d77eecf7c5f9eb4c2679.png

可以看到 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')
bb925439fec815740b06ed5d811461ae.png

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

更多的参数见:

?trancriptVis

12结尾

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

往期精品(点击图片直达文字对应教程)

1c1c7911220bbe47e698b29bb993c57a.jpeg

b0886d9d66fa340d0a59c59849327ec1.jpeg

c8a9fef1aacae42b574a09698c2d9cd6.jpeg

babe9fce052679f3c8b0ae4a49285bd5.jpeg

3e2d0097edb2930d39a57f8a9c0edfae.jpeg

454918ce3d999733ea3dd7e4f8c18e4d.jpeg

302c020baf2883418f1b12b06ba93f93.jpeg

1fac6526aba1f76222f811e5448dedd8.jpeg

6533bb87ca3d53f145757f30b656d190.jpeg

cb13adec4b2083be8bee3e801840cffa.jpeg

4cb741a8c6bbd018ca22f9805effac0c.jpeg

f6b0a6ed0f32dff2b745f68671e9baf5.jpeg

acc3c81d47c861c9c07a1d974790ec58.png

e0ae0978e65645f82a754b73ab2b50e7.png

9815d2cb13f98d8fe2f54b28bed3aeae.png

39338cdc3798f2767c6661d7e997db9e.png

9b49f3e64ff670f8567aca52a8d8c43e.jpeg

a7030c42d00821d7732aa008c0077ff6.jpeg

555382931ab56158c1f331bdfc8dc152.jpeg

85bc16680c388a12bbcb616d921b9da2.jpeg

8e50e83e16d33506712c0c5e86b7b0f6.png

62e86a001da75b69f95333935914039a.png

f2975a1c2a5dc124c351ba413bad181b.jpeg

66dde06038c4cb51e9e901ceae8893fc.png

f22d8bd146ea80dd4ece0ed145ed8cb3.png

e10ee6e6347998cc77458bb0bbae0f29.jpeg

17726f583e9b753c2f39eed42a54bc15.png

7fb9734b8e70f61bd75ffa4813b0070c.png

机器学习

后台回复“生信宝典福利第一波”或点击阅读原文获取教程合集

202a93d29977ef1e43b4ae561a1b56c6.jpeg

d9ee46defaceeca01b137df037bb95f1.jpeg

0172c74c872bf5c15573c72a24998e58.png

绘制基因组变异圆圈图通常使用的工具是Circos。Circos是一个用于可视化科学数据的软件,特别适用于绘制基因组相关的图形。 以下是使用Circos绘制基因组变异圆圈图的一般步骤: 1. 准备数据:将基因组变异数据整理为适合Circos使用的格式,通常为文本文件或者表格。确保数据包含变异的位置、类型和其他相关信息。 2. 安装Circos:首先需要下载和安装Circos软件。你可以从Circos官方网站(http://circos.ca/software/download)下载并按照指南进行安装。 3. 配置Circos:在安装完成后,你需要配置Circos的参数文件。这个文件定义了绘图的样式、数据文件的路径和其他设置。你可以根据自己的需求进行配置。 4. 数据解析:在配置完成后,你需要编写一个脚本或程序来解析基因组变异数据文件,并将其转换为Circos所需的格式。这个格式通常为一个特定的文本格式,描述了每个变异的位置、类型和其他相关信息。 5. 绘制图形:使用解析后的数据,运行Circos程序来生成基因组变异圆圈图。Circos会根据你的配置文件和数据文件生成相应的图形。 6. 自定义样式:如果需要,你可以根据自己的需求对图形进行自定义。Circos提供了丰富的配置选项和样式设置,你可以根据自己的需求进行调整。 请注意,绘制基因组变异圆圈图是一个复杂的过程,需要一定的编程和数据处理能力。如果你不熟悉Circos或者编程,建议寻求相关领域专家的帮助或者使用一些基因可视化工具来简化这个过程。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值