(Is there a bug tracker for bioconductor packages? I couldn't find one. I sent this post to the maintainer as well).
There is an insiduous bug in Gviz that probably has to do with getting the geometry wrong if group labels are used in densely populated plots. I managed to isolate the bug, you can reproduce it as follows:
library(Gviz)
pdf(file="crash.pdf", width=12, height=3)
tfbs <- GRanges(ranges=IRanges(start=c(100,300,200,400), width=10),
seqnames='chrX',strand='*', ID=LETTERS[c(1,1,2,2)])
tfbs <- AnnotationTrack(range=tfbs,group=mcols(tfbs)$ID,groupAnnotation="group", shape='box',just.group='above')
plotTracks(trackList=list(GenomeAxisTrack(), tfbs), sizes=c(15, 1))
This example on transcription factor binding sites is of course very contrived, but it happens very often if I use viewports to display many promoters on one page using the trick described in the Vignette (chapter 6, Composite plots for multiple chromosomes). The problem seems to be the placement of the group labels above or below the boxes, because specifying just.group="left"
(or right) makes the problem disappear. Usually, if Gviz can't fit things into the space you give it, you get the "Too many stacks to draw. Either increase the device size or limit the drawing to a smaller region
."-error, which is of course exactly what is needed. Instead, I get the following (I include the stack trace):
> options(error=browser)
> plotTracks(trackList=list(GenomeAxisTrack(), tfbs), sizes=c(15, 1))
Error in normalizeDoubleBracketSubscript(i, x, exact = exact, error.if.nomatch = FALSE) :
subscript is out of bounds
Called from: stop("subscript is out of bounds")
Browse[1]> where
where 1: stop("subscript is out of bounds")
where 2: normalizeDoubleBracketSubscript(i, x, exact = exact, error.if.nomatch = FALSE)
where 3: getListElement(x, i, ...)
where 4: getListElement(x, i, ...)
where 5: levels[[cur.level]]
where 6: levels[[cur.level]]
where 7: resize(levels[[cur.level]], width = width(levels[[cur.level]]) -
1)
where 8: setdiff(IRanges(start = b$x1, end = b$x2), resize(levels[[cur.level]],
width = width(levels[[cur.level]]) - 1))
where 9: .arrowBar(bar$sx1, bar$sx2, y = bar$y, bar$strand, box[, 1:4,
drop = FALSE], col = if (is.null(col.line)) bar$col else rep(col.line,
length(bar$col)), lwd = lwd, lty = lty, alpha = alpha, barOnly = (!"smallArrow" %in%
.dpOrDefault(GdObject, "shape", "box") || stacking(GdObject) ==
"dense"), diff = res, min.height = .dpOrDefault(GdObject,
"min.height", 3))
where 10: .local(GdObject, ...)
where 11: drawGD(expandedTrackList[[i]], minBase = ranges["from"], maxBase = ranges["to"],
subset = FALSE)
where 12: drawGD(expandedTrackList[[i]], minBase = ranges["from"], maxBase = ranges["to"],
subset = FALSE)
where 13: plotTracks(trackList = list(GenomeAxisTrack(), tfbs), sizes = c(15,
1))
The sessionInfo() is:
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid parallel stats4 stats datasets graphics grDevices
[8] utils methods base
other attached packages:
[1] Gviz_1.17.3 GenomicRanges_1.24.2 GenomeInfoDb_1.8.1
[4] IRanges_2.6.0 S4Vectors_0.10.1 BiocGenerics_0.18.0
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.2.3 VariantAnnotation_1.18.1
[3] splines_3.3.0 lattice_0.20-33
[5] colorspace_1.2-6 htmltools_0.3.5
[7] rtracklayer_1.32.1 GenomicFeatures_1.24.2
[9] chron_2.3-47 interactiveDisplayBase_1.10.3
[11] survival_2.39-4 XML_3.98-1.4
[13] foreign_0.8-66 DBI_0.4-1
[15] ensembldb_1.4.6 BiocParallel_1.6.2
[17] RColorBrewer_1.1-2 matrixStats_0.50.2
[19] plyr_1.8.4 zlibbioc_1.18.0
[21] Biostrings_2.40.2 munsell_0.4.3
[23] gtable_0.2.0 latticeExtra_0.6-28
[25] Biobase_2.32.0 biomaRt_2.28.0
[27] BiocInstaller_1.22.2 httpuv_1.3.3
[29] AnnotationDbi_1.34.3 Rcpp_0.12.5
[31] acepack_1.3-3.3 xtable_1.8-2
[33] BSgenome_1.40.1 scales_0.4.0
[35] Hmisc_3.17-4 XVector_0.12.0
[37] mime_0.4 Rsamtools_1.24.0
[39] gridExtra_2.2.1 AnnotationHub_2.4.2
[41] ggplot2_2.1.0 digest_0.6.9
[43] biovizBase_1.20.0 shiny_0.13.2
[45] tools_3.3.0 bitops_1.0-6
[47] RCurl_1.95-4.8 RSQLite_1.0.0
[49] dichromat_2.0-0 Formula_1.2-1
[51] cluster_2.0.4 Matrix_1.2-6
[53] data.table_1.9.6 httr_1.2.0
[55] R6_2.1.2 rpart_4.1-10
[57] GenomicAlignments_1.8.3 nnet_7.3-12
BTW, the same occurs with the stable version.
But this is not the same error?!?
Solution for this is in the error message: increase the device size! You are most likely trying to cram to much stuff on too little vertical space.
Florian
I do have 7 tracks - is that too many? It works fine if I leave off the knownGenes track.
I get the same error even if I increase the pdf size:
pdf(file='test_plot.pdf',onefile=T,width=14,length=14)
The gene track is for the region chr20:58887626-58892145
d'oh! My mistake!