当前位置:   article > 正文

trancriptVis 的左膀右臂: bedVis 和 trackVis

igv collapse

我也曾经憧憬过

0d04ec103c6d60e24c2fcc1573ab1a0e.gif

introduction

here I introduced bedVis and trackVis functions to visualize peak files and bigwig files which work better with trancriptVis. You can use these functions to make a complex track plot with more ajustable parameters to control you graph produced.

Note:

all the test files can be downloaded from:

https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE211475

1installation

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

bedVis

bedVis function can be used to visualize peaks data (bed format).

2examples

bed files:

  1. file <- list.files(pattern = '.bed')
  2. file
  3. # [1"H524-NeuroD1_peaks.bed"  "H524-Promoter_peaks.bed" "H82-NeuroD1_peaks.bed"
  4. # [4"H82-Promoter_peaks.bed"

choose the region and chromesome to be plotted:

  1. # plot
  2. bedVis(bdFile = file,
  3.        chr = "chr19",
  4.        region.min = 39875973,
  5.        region.max = 39919857)
c3c30d0695b542a5eec0e87db59d20bb.png

collapse the tracks:

  1. # collapse tracks
  2. bedVis(bdFile = file,
  3.        chr = "chr19",
  4.        region.min = 39875973,
  5.        region.max = 39919857,
  6.        collapse = TRUE)
6859177f60e77b6f60562865daa60d8a.png

change color:

  1. # change colors
  2. bedVis(bdFile = file,
  3.        chr = "chr19",
  4.        region.min = 39875973,
  5.        region.max = 39919857,
  6.        fill = ggsci::pal_d3()(4))
5561b78044e117432fc49841a6fbdd45.png

remove legend:

  1. # change to grey50 and turn off legend
  2. bedVis(bdFile = file,
  3.        chr = "chr19",
  4.        region.min = 39875973,
  5.        region.max = 39919857,
  6.        fill = rep('grey50',4),
  7.        show.legend = FALSE)
8659ea49f1b3381ef1365c23611391da.png

add peak name:

  1. # add label
  2. bd <-
  3. bedVis(bdFile = file,
  4.        chr = "chr19",
  5.        region.min = 39875973,
  6.        region.max = 39919857,
  7.        add.label = TRUE,label.column = 'name')
  8. bd
6950fff1e8c0834d1d0b5a19a334e078.png

3cases

you can combine with trancriptVis function:

  1. # combine
  2. gtf <- import('hg19.ncbiRefSeq.gtf',format = "gtf") %>%
  3.   data.frame()
  4. p <-
  5.   trancriptVis(gtfFile = gtf,
  6.                Chr = "chr19",
  7.                posStart = 39875973,
  8.                posEnd = 39919857,
  9.                textLabel = "gene_name")
  10. # combine
  11. p %>% insert_bottom(bd)
5f753ab70465179055d60857f312db74.png

here we can show the results in IGV:

652b3164fcda344a764ec865a5547daf.png

loadBigWig

loadBigWig function will load bigwig files and transform them into data.frame format.

4examples

  1. # test
  2. file <- list.files(pattern = '.bw')
  3. # [1"H524-Input.bw"    "H524-NeuroD1.bw"  "H524-Promoter.bw" "H82-Input.bw"     "H82-NeuroD1.bw"
  4. # [6"H82-Promoter.bw"
  5. # read file
  6. mybw <- loadBigWig(file)
  7. # check
  8. head(mybw,3)
  9. #   seqnames start   end width strand score   fileName
  10. 1    chr19 74845 74945   101      *     1 H524-Input
  11. 2    chr19 75000 75100   101      *     1 H524-Input
  12. 3    chr19 80776 80876   101      *     1 H524-Input

trackVis

trackVis function can be used to visualize bigwig files in an elegant way. The trackVis will extend 3000bps upstream and downstream by defalut. You can set the extend.up/extend.dn to ajust a suitable value.

5examples

plot a region:

  1. # load data
  2. load('bWData.Rda')
  3. mybw <- bWData
  4. # plot with specific region
  5. trackVis(bWData = mybw,
  6.          chr = "chr19",
  7.          region.min = 36226490,
  8.          region.max = 36269673)
80667b6ade9987f653a9864cd5a4e0a4.png

plot a specific gene:

  1. # load gtf
  2. gtf <- import('hg19.ncbiRefSeq.gtf',format = "gtf") %>%
  3.   data.frame()
  4. # plot with specific gene
  5. trackVis(bWData = mybw,
  6.          gtf.file = gtf,
  7.          gene.name = "RAD23A")
579faf59392772865597d92de79186ac.png

here we show the same results in IGV:

b70c169be36796ae78c2db474388ee4d.png

show the color legend:

  1. # show legend
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          show.legend = TRUE)
244f5507946d115a08db6ffe8d7a8671.png

remove Y axis information:

  1. # remove axis info
  2. trackVis(bWData = mybw,
  3.          gtf.file = gtf,
  4.          gene.name = "RAD23A",
  5.          xAxis.info = FALSE,
  6.          yAxis.info = FALSE)
812cfb3239be0af3619dd28722c772a2.png

change a theme:

  1. # change theme
  2. trackVis(bWData = mybw,
  3.          gtf.file = gtf,
  4.          gene.name = "RAD23A",
  5.          yAxis.info = FALSE,
  6.          theme = "bw")
092940fdea4174ab1e35cf0097271031.png

change scales and layout:

  1. # free scales and draw two columns
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          scales = "free",
  7.          ncol = 2,
  8.          label.angle = 90)
a5c97e74b13a54b15617afb9052c3d1d.png

change track colors:

  1. # change color
  2. c1 <- trackVis(bWData = mybw,
  3.                gtf.file = gtf,
  4.                gene.name = "RAD23A",
  5.                color = ggsci::pal_npg()(6))
  6. c2 <- trackVis(bWData = mybw,
  7.                gtf.file = gtf,
  8.                gene.name = "RAD23A",
  9.                color = rep('grey20',6))
  10. c3 <- trackVis(bWData = mybw,
  11.                gtf.file = gtf,
  12.                gene.name = "RAD23A",
  13.                color = jjAnno::useMyCol(platte = "stallion",n = 6))
  14. # combine
  15. cowplot::plot_grid(plotlist = list(c1,c2,c3),
  16.                    align = 'hv',ncol = 3)
fa62ea95708568db59909b3447d54c13.png

6highlight regions

sometimes we want to highlight some regions like peak site or modification site et. trackVis can also achive this. You just need to supply a list object include start and end coordinates.

mark three regions:

  1. # mark some regions
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)))
a236bffe6bf604024c9a4f3b0a686d8a.png

ajust the color alpha:

  1. # change alpha
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)),
  8.          mark.alpha = 0.2)
d75062c91e2d578914dc994f77424eb6.png

changing the marked regions color also is acceptable:

  1. # change color
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)),
  8.          mark.alpha = 0.2,
  9.          mark.col = ggsci::pal_aaas()(4))
11f231a846b1cba534b40d460b9225c5.png

change a theme:

  1. # change theme
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)),
  8.          mark.alpha = 0.2,
  9.          theme = "bw",yAxis.info = FALSE)
10f6eaade7e441e2a47b1f51a68d5a94.png

giving a gene name to plot with marked regions:

  1. # define gene name with mark region
  2. trackVis(bWData = mybw,
  3.          gtf.file = gtf,
  4.          gene.name = "RAD23A",
  5.          mark.region = list(c(13056500,13064000),
  6.                             c(13058400,13065000)),
  7.          mark.alpha = 0.2,
  8.          label.face = 'plain')
ef18403fbf95e1db69278ab30a3bdddd.png

7new style y axis

here I provide a new style Y axis which often ocurrs in papers, you can try this style.

add a new style Y axis:

  1. # add new y range
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)),
  8.          mark.alpha = 0.2,
  9.          theme = "bw",yAxis.info = FALSE,
  10.          new.yaxis = TRUE)
301a50c5813246cc35262655e75a0245.png

you can ajust the pos.ration arg to palace the label:

  1. # ajust position
  2. trackVis(bWData = mybw,
  3.          chr = "chr19",
  4.          region.min = 36226490,
  5.          region.max = 36269673,
  6.          mark.region = list(c(36230500,36235000,36247500,36265000),
  7.                             c(36232800,36241000,36250000,36267000)),
  8.          mark.alpha = 0.2,
  9.          theme = "bw",yAxis.info = FALSE,
  10.          new.yaxis = TRUE,
  11.          pos.ratio = c(0.95,0.8))
26dcf12f4c91c7c53b0e49bfd439b2d6.png

8order

you can also change the plot orders through sample.order arg.

change the orders:

  1. # ajust order
  2. order <- c("H524-Input","H82-Input","H524-NeuroD1","H524-Promoter","H82-NeuroD1","H82-Promoter")
  3. trackVis(bWData = mybw,
  4.          gtf.file = gtf,
  5.          gene.name = "RAD23A",
  6.          mark.region = list(c(13056500,13064000),
  7.                             c(13058400,13065000)),
  8.          mark.alpha = 0.2,
  9.          label.face = 'plain',
  10.          sample.order = order)
29538e8a38f6ab1f809adc6ef3047d52.png

9cases

let's see some cases working with other functions.

  1. ptrack <- trackVis(bWData = mybw,
  2.                    chr = "chr19",
  3.                    region.min = 36226490,
  4.                    region.max = 36269673)
  5. trans <-
  6. trancriptVis(gtfFile = gtf,
  7.              Chr = "chr19",
  8.              posStart = 36226490 - 3000,
  9.              posEnd = 36269673 + 3000,
  10.              addNormalArrow = FALSE,
  11.              newStyleArrow = T,
  12.              absSpecArrowLen = T,
  13.              speArrowRelLen = 0.2,
  14.              textLabel = "gene_name",
  15.              textLabelSize = 3,
  16.              relTextDist = 0.5,
  17.              exonWidth = 0.9)
  18. # combine
  19. ptrack %>% insert_bottom(trans,height = 0.75)
ce8655d05ce22bb67d342560b5573ab2.png

IGV:

cc4b7f8d76cf09b9535e9d1e5c80eb57.png

collapse the gene structures:

  1. trans <-
  2. trancriptVis(gtfFile = gtf,
  3.              Chr = "chr19",
  4.              posStart = 36226490 - 3000,
  5.              posEnd = 36269673 + 3000,
  6.              absSpecArrowLen = T,
  7.              speArrowRelLen = 0.2,
  8.              textLabel = "gene_name",
  9.              textLabelSize = 4,
  10.              relTextDist = 0.2,
  11.              exonWidth = 0.5,
  12.              collapse = T)
  13. # combine
  14. ptrack %>% insert_bottom(trans,height = 0.1)
cac7bbd319333f2d03301de0dd55cbb1.png

supply with gene name:

  1. RAD23A <-
  2.   trackVis(bWData = mybw,
  3.            gtf.file = gtf,
  4.            gene.name = "RAD23A",
  5.            extend.up = 500,
  6.            extend.dn = 1000,
  7.            xAxis.info = F)
  8. p <-
  9.   trancriptVis(gtfFile = gtf,
  10.                gene = "RAD23A",
  11.                relTextDist = -0.5,
  12.                exonWidth = 0.5,
  13.                exonColorBy = 'transcript_id',
  14.                textLabelSize = 4,
  15.                addNormalArrow = FALSE,
  16.                newStyleArrow = TRUE) +
  17.   xlab('')
  18. # combine
  19. RAD23A %>% insert_bottom(p,height = 0.3)
1c6d405ba62902e2b486972c0d178efc.png

IGV shows:

8c1360602140b0ef68ee0a4a39864dd3.png

change transcript colors:

  1. # change transcript color
  2. p <-
  3.   trancriptVis(gtfFile = gtf,
  4.                gene = "RAD23A",
  5.                relTextDist = -0.5,
  6.                exonWidth = 0.5,
  7.                exonFill = 'black',
  8.                arrowCol = 'black',
  9.                textLabelSize = 3,
  10.                addNormalArrow = FALSE,
  11.                newStyleArrow = TRUE,
  12.                xAxis.info = FALSE,
  13.                textLabel = 'gene_name') +
  14.   xlab('')
  15. # combine
  16. RAD23A %>% insert_bottom(p,height = 0.3)
4eaaa1553a06b26eb84e78dc49c594b1.png

let's combine track, gene and peak:

  1. # track + gene + peak
  2. RAD23A <-
  3.   trackVis(bWData = mybw,
  4.            gtf.file = gtf,
  5.            gene.name = "RAD23A",
  6.            extend.up = 500,
  7.            extend.dn = 1000,
  8.            xAxis.info = F,
  9.            theme = "bw",
  10.            yAxis.info = F,new.yaxis = T,
  11.            pos.ratio = c(0.06,0.8),
  12.            color = jjAnno::useMyCol(platte = "stallion",n = 6))
  13. # peak
  14. bd <- bedVis(bdFile = file,
  15.              chr = "chr19",
  16.              track.width = 0.3,
  17.              show.legend = T)
  18. # combine
  19. RAD23A %>% insert_bottom(p,height = 0.3) %>%
  20.   insert_bottom(bd,height = 0.15)
36686fefd65bb6ebe42115249b0301d5.png

end

if you have any advice or douts please leave words on:

  • https://github.com/junjunlab/transPlotR/issues.

226fae3f82c5ea45f3783040c9fda142.png

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

5a8493afcc5ad430580dbadde948bf75.jpeg

b6d644ca41b6c604ca25f8b53b861f8c.jpeg

ce9d433bbdbd5f169d3ac17487c97215.jpeg

9acf0f25aa2f221862dd5c69eabd288a.jpeg

fc7b3d508cca6dadecf7587724763c75.jpeg

53089072b9fd3b452d81d281b2feb081.jpeg

2ac130b0382079254ffb0ae82971bf8d.jpeg

70c893279b14948decd8b5dc462980d8.jpeg

6be2933f8840d3979ce8ae3509ade4c8.jpeg

774a9efc4a48b098a8dad36f97a9764d.jpeg

a244e37bd3250a6146833b3e85d178d6.jpeg

641a4b73819a06c2c0e629fc3c9f5640.jpeg

27d1717536b22d58049c46d36e27a68b.png

7d20f9ce13c9de3d96447c50269d2f04.png

b0e45c31f9fa7ef58600f7d7a0f42134.png

7b90a21a64f6cf0fb721b88ce9382150.png

35490fd7ffec9ed5f9a00eee92f5c540.jpeg

86f4caa5117f81de2f92ceb0cf2ab036.jpeg

781e9013807dc58dd2c7fbd0bd94218a.jpeg

87e860a3c7c73134e6a2c44c9503593d.jpeg

d6c5dd254328d170c9fa1aad7984be9e.png

3146206e01877f9a572678157499dea3.png

9c29c729bee890eb9dc7974ba2f75558.jpeg

46fe755c2b827306efd973eaec582228.png

f1a31d7474b429c5437470d04bf8f720.png

cf1a7a71a84fd2337c3a50eb464d48b8.jpeg

cde9b93f35412fcf6d1e461529bb817b.png

62c4c245859a6c4952a20a195efa8567.png

机器学习

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

07eae75bee9fbaa44b3f96e0016c473f.jpeg

dea1f303671e48359fa0bb4316c6d198.jpeg

28be57ff04eb3fefe078b683d2e0aebc.png


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/98134
推荐阅读
相关标签
  

闽ICP备14008679号