gviz: controlling track labels
5
0
Entering edit mode
Janet Young ▴ 740
@janet-young-2360
Last seen 5.1 years ago
Fred Hutchinson Cancer Research Center,…

Hi there,

I've just started using gviz - it looks really useful. Thanks for the package!

I'm plotting annotations and coverage (from a bam file) and am having trouble to get the labels to show up properly for the coverage tracks. Here's a very simple example that should show what I mean: in this example, I'd love to see the full label for the alignments track, and to have the labels for the two tracks left-aligned with each other.

Is there a way to control those things? I've been looking at the parameters for the track objects, but can't see anything that looks like what I need

thanks very much, 

Janet Young

library(Gviz)

afrom <- 2960000
ato <- 3160000
gtrack2 <- GenomeAxisTrack()

fakeRegions <- GRanges(seqnames=rep("chr12",3), ranges=IRanges(start=c( 2970000, 3000000, 3050000), width=2000))

atrack <- AnnotationTrack(fakeRegions, name = "temp", rotation.title=0)

alTrack <- AlignmentsTrack(system.file(package = "Gviz", "extdata", "gapped.bam"), isPaired = TRUE, rotation.title=0, type="coverage")

plotTracks(c(gtrack2,atrack, alTrack), from = afrom, to = ato, chromosome = "chr12", title.width=6, sizes=c(1,1,1) )

sessionInfo()

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] grid      parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Gviz_1.16.1          GenomicRanges_1.24.2 GenomeInfoDb_1.8.3   IRanges_2.6.1        S4Vectors_0.10.2    
[6] BiocGenerics_0.18.0 

loaded via a namespace (and not attached):
 [1] SummarizedExperiment_1.2.3    VariantAnnotation_1.18.6      splines_3.3.1                 lattice_0.20-33              
 [5] colorspace_1.2-6              htmltools_0.3.5               rtracklayer_1.32.2            GenomicFeatures_1.24.5       
 [9] chron_2.3-47                  interactiveDisplayBase_1.10.3 survival_2.39-5               XML_3.98-1.4                 
[13] foreign_0.8-66                DBI_0.4-1                     ensembldb_1.4.7               BiocParallel_1.6.3           
[17] RColorBrewer_1.1-2            matrixStats_0.50.2            plyr_1.8.4                    zlibbioc_1.18.0              
[21] Biostrings_2.40.2             munsell_0.4.3                 gtable_0.2.0                  latticeExtra_0.6-28          
[25] Biobase_2.32.0                biomaRt_2.28.0                BiocInstaller_1.22.3          httpuv_1.3.3                 
[29] AnnotationDbi_1.34.4          Rcpp_0.12.6                   acepack_1.3-3.3               xtable_1.8-2                 
[33] BSgenome_1.40.1               scales_0.4.0                  Hmisc_3.17-4                  XVector_0.12.1               
[37] mime_0.5                      Rsamtools_1.24.0              gridExtra_2.2.1               AnnotationHub_2.4.2          
[41] ggplot2_2.1.0                 digest_0.6.9                  biovizBase_1.20.0             shiny_0.13.2                 
[45] tools_3.3.1                   bitops_1.0-6                  RCurl_1.95-4.8                RSQLite_1.0.0                
[49] dichromat_2.0-0               Formula_1.2-1                 cluster_2.0.4                 Matrix_1.2-6                 
[53] data.table_1.9.6              httr_1.2.1                    R6_2.1.2                      rpart_4.1-10                 
[57] GenomicAlignments_1.8.4       nnet_7.3-12                  
gviz • 4.9k views
ADD COMMENT
0
Entering edit mode

having trouble embedding the image: http://imgur.com/1xHYFWh

ADD REPLY
0
Entering edit mode

Hi Janet, 

form the docs:

'rotation.title=1': Numeric scalar. The rotation angle for the text in the

          title panel. Even though this can be adjusted, the automatic

          resizing of the title panel will currently not work, so use

          at own risk.

So if you insist on using the vertical titles you will have to play with blank spaces to buffer. There is no way to set horizontal alignments. The idea was always to have rotated titles here.

names(alTrack) <- "                                 AlignmentsTrack"
plotTracks(c(gtrack2,atrack, alTrack), from = afrom, to = ato, chromosome = "chr12", title.width=6, sizes=c(1,1,1) )

 

 

ADD REPLY
0
Entering edit mode
Janet Young ▴ 740
@janet-young-2360
Last seen 5.1 years ago
Fred Hutchinson Cancer Research Center,…

Thanks, Florian - that should let me fix it as needed.  Sorry I missed it in the docs.

Unfortunately vertical titles are challenging in my actual use case -  I have rather a lot of tracks I want to show, so some of them are very narrow (8 DNA-seq coverage tracks, 2 or more RNA-seq tracks with coverage and sashimi, gene annotations, and a couple of other regional annotation tracks). The data show up just fine on the narrow tracks, and making them taller would not be a good use of plot space, but many of the titles are too long to work vertically with these narrow tracks. 

I might be missing a simpler way to do this:  you show a really nice example in the vignette using DataTrack for a simpler data type :

> data(dtHoriz)
> dtHoriz <- dtHoriz[1:6, ]
> plotTracks(dtHoriz, type = "horiz", groups = rownames(values(dtHoriz)),
+ showSampleNames = TRUE, cex.sampleNames = 0.6,
+ separator = 1)

I'd love to be able to do create something that looks superficially like that example in the way that several quite narrow tracks are grouped for display.  I would love to specify a group of bam files (DNA-seq, 8 samples, each in a separate bam file), and use the AlignmentsTrack coverage display (rather than horizon plots) to produce grouped tracks (like for that dtHoriz example) rather than showing each track individually.  I've been trying to find that in the docs, but can't see it - is that sort of approach implemented in Gviz?  

thanks again,

Janet

ADD COMMENT
0
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.3 years ago
Switzerland

Hi Janet,

The DataTrack class is much more flexible for these sorts of visualizations, but you would have to take care of preprocessing the data into the right format, first. DataTracks take a set of GenomicRanges, and associated data values in the form of a matrix. What you could do is extract the coverage vectors from your BAM file as Rles, and from that define the union of all positions where the coverage changes. With that information you can transform the coverage Rles into a rectangular matrix (simple sub-setting should work, and use that as the input for the DataTrack. 

Here is some (untested) pseudo code that should get you going:

library(Rsamtools)
library(GenomicAlignments)
alignments <- readGAlignments(system.file("extdata", "ex1.bam", package="Rsamtools"))
cov1 <- coverage(sample(alignments, length(alignments)/2))[["seq1"]]
cov2 <- coverage(sample(alignments, length(alignments)/2))[["seq2"]]
x <- disjoin(c(ranges(cov1), ranges(cov2)))
data <- rbind(as.integer(cov1)[start(x)], as.integer(cov2)[start(x)])
plotTracks(DataTrack(x, data=data, chromosome=1, groups=1:2), type="l")
ADD COMMENT
0
Entering edit mode
Janet Young ▴ 740
@janet-young-2360
Last seen 5.1 years ago
Fred Hutchinson Cancer Research Center,…

Thanks again, Florian - that's helpful.  

Here's a suggestion for a future enhancement: would it be easy for you to implement a plot type for DataTrack that mimics the coverage track for AlignmentTrack plots?  I love the look of the filled gray polygon, rather than the simple line-only plot that type="l" gives:  the fill really makes it visually obvious what's going on with our data. We're looking at a genomic region where half of our 8 samples have a deletion and the other half don't: the line-only plots get a bit visually confusing as there's so many of them.

thanks for considering it,

Janet

ADD COMMENT
0
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.3 years ago
Switzerland

Have you tried this one?

plotTracks(DataTrack(x, data=data, chromosome=1, groups=1:2), type="histogram")

Not 100% the same, but quite close. If there was a plotting type that looks exactly like the coverage plots, how would you like to treat different groups? Would you want to overplot with different colors as it is done for the histogram type? Or rather distribute the groups over multiple sub-panels, as done for the horizon type?

 

ADD COMMENT
0
Entering edit mode
Janet Young ▴ 740
@janet-young-2360
Last seen 5.1 years ago
Fred Hutchinson Cancer Research Center,…

Thanks again - that is fairly close.   I have enough samples (2 groups, 4 samples each) that it'd look better to mimic the horizon type multipanel grouped plot rather than than the overlaid histograms.  I can get something pretty close to what I want just by plotting coverage as separate individual tracks, it's just that (as I mentioned) I'm having trouble getting the labels to show up, and the way the horizon plot labels the tracks is just what I'd love to see. 

ADD COMMENT

Login before adding your answer.

Traffic: 578 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6