[BioC] Gviz output extra empty page on pdf device

Dan Du tooyoung at gmail.com
Wed Feb 19 17:04:13 CET 2014


Hi Florian and others,

I have been testing some functions and parameters, and noticed something
odd when plotting tracks on a pdf device (postscript turns out fine),
this only happens to some recent R-devel versions (tested on three
r-devel builds Feb.3, Feb.14 and Feb.18), apparently the build machine
in Seattle is not yet affected, which has a devel build on Jan.15. This
happens to the most recent devel version of Gviz 1.7.7.

Here is an example, can't really figure it why,
#########################################
# say using the 1st example of plotTracks, I will get one empty page
before the real deal.
#########################################
pdf('test.Gviz.pdf')
#postscript('test.Gviz.eps', fonts='sans') # this is ok...
st <- c(2000000, 2070000, 2100000, 2160000)
ed <- c(2050000, 2130000, 2150000, 2170000)
str <- c("-", "+", "-", "-")
gr <- c("Group1","Group2","Group1", "Group3")
annTrack <- AnnotationTrack(start=st, end=ed, strand=str, chromosome=7,
                            genome="hg19", feature="test", group=gr,
                            id=paste("annTrack item", 1:4),
                            name="annotation track foo",
                            stacking="squish")
ax <- GenomeAxisTrack()
dt <- DataTrack(start=seq(min(st), max(ed), len=10), width=18000,
data=matrix(runif(40), nrow=4), genome="hg19", chromosome=7,
type="histogram", name="data track bar")
## Now plot the tracks
res <- plotTracks(list(ax, annTrack, dt))
dev.off()
#########################################

#########################################
# while it turns out fine for a normal multipage grid viewport, say the
viewport clipping example of viewport()
#########################################
pdf('test.viewport.pdf')
clip.demo <- function(i, j, clip1, clip2) {
  pushViewport(viewport(layout.pos.col=i,
                         layout.pos.row=j))
  pushViewport(viewport(width=0.6, height=0.6, clip=clip1))
  grid.rect(gp=gpar(fill="white"))
  grid.circle(r=0.55, gp=gpar(col="red", fill="pink"))
  popViewport()
  pushViewport(viewport(width=0.6, height=0.6, clip=clip2))
  grid.polygon(x=c(0.5, 1.1, 0.6, 1.1, 0.5, -0.1, 0.4, -0.1),
               y=c(0.6, 1.1, 0.5, -0.1, 0.4, -0.1, 0.5, 1.1),
               gp=gpar(col="blue", fill="light blue"))
  popViewport(2)
}

grid.newpage()
grid.rect(gp=gpar(fill="grey"))
pushViewport(viewport(layout=grid.layout(2, 2)))
clip.demo(1, 1, FALSE, FALSE)
clip.demo(1, 2, TRUE, FALSE)
clip.demo(2, 1, FALSE, TRUE)
clip.demo(2, 2, TRUE, TRUE)
popViewport()
# Demonstrate turning clipping off
grid.newpage()
pushViewport(viewport(w=.5, h=.5, clip="on"))
grid.rect()
grid.circle(r=.6, gp=gpar(lwd=10))
pushViewport(viewport(clip="inherit"))
grid.circle(r=.6, gp=gpar(lwd=5, col="grey"))
pushViewport(viewport(clip="off"))
grid.circle(r=.6)
popViewport(3)
# Demonstrate vpList, vpStack, and vpTree
grid.newpage()
tree <- vpTree(viewport(w=0.8, h=0.8, name="A"),
               vpList(vpStack(viewport(x=0.1, y=0.1, w=0.5, h=0.5,
                                       just=c("left", "bottom"), name="B"),
                              viewport(x=0.1, y=0.1, w=0.5, h=0.5,
                                       just=c("left", "bottom"), name="C"),
                              viewport(x=0.1, y=0.1, w=0.5, h=0.5,
                                       just=c("left", "bottom"), name="D")),
                      viewport(x=0.5, w=0.4, h=0.9,
                               just="left", name="E")))
pushViewport(tree)
for (i in LETTERS[1:5]) {
  seekViewport(i)
  grid.rect()
  grid.text(current.vpTree(FALSE),
            x=unit(1, "mm"), y=unit(1, "npc") - unit(1, "mm"),
            just=c("left", "top"),
            gp=gpar(fontsize=8))
}
dev.off()
#########################################

I found that there has been a bug fix introduced in R-devel on Feb 2, not sure if this is the cause. Also noticed some very recent commit (r65013) to r-devel, will see if this changes anything.

# R-devel news
"Bug fix for pushing viewports in ‘grid’ (reported by JJ Allaire and Kevin Ushey).
NOTE for anyone poking around within the graphics engine display list (despite the warnings not to) that this changes what is recorded by ‘grid’ on the graphics engine display list."

# R-devel svn log
r64901 | murrell | 2014-01-31 00:45:44 +0100 (Fri, 31 Jan 2014) | 1 line
Changed paths:
   M /trunk/doc/NEWS.Rd
   M /trunk/src/library/grid/R/grid.R
   M /trunk/src/library/grid/R/util.R
   M /trunk/src/library/grid/R/viewport.R
   M /trunk/src/library/grid/inst/doc/changes.txt
   M /trunk/src/library/grid/src/grid.c
   M /trunk/src/library/grid/src/grid.h

bug fix for pushing grid viewports (only record viewport, NOT pushedvp, on graphics engine display list)

Best regards,
Dan



More information about the Bioconductor mailing list