[Bioc-devel] Error: invalid graphics state in creating vignettes

Shin, Sunyoung Sunyoung@Sh|n @end|ng |rom utd@||@@@edu
Fri May 3 00:30:06 CEST 2019


Hi JIanhong, that did work. Thank you very much!

Best,
Sunyoung

On Apr 29, 2019, at 10:47 AM, Jianhong Ou, Ph.D. <jianhong.ou using duke.edu<mailto:jianhong.ou using duke.edu>> wrote:

Hi Sunyoung,

Sorry for the change of motifStack which makes you struggling. Please have a try following codes for plotting:

pushViewport(viewport(y =unit(.5, "npc") - unit(2, "lines"), height = unit(1, "npc") - unit(3, "lines")))
  pushViewport(viewport(y=.875, height=.25))
  plotMotifLogo(pcm2pfm(ref_aug_pwm), "Best match to the reference genome", yaxis=FALSE,
                xaxis=FALSE, xlab="", ylab="PWM", newpage=FALSE, margins = c(1.5, 3, 2, 2))
if(motif.match$ref_strand=='+') {
  grid.lines(x=c(convertUnit(unit(3, "lines"), "npc", valueOnly = TRUE), 1 - convertUnit(unit(2, "lines"), "npc", valueOnly = TRUE)),
             y=unit(1, "lines"),
           gp=gpar(col = "blue", lwd = 1.5, xpd=NA), arrow=arrow(length = unit(0.1, "inches"), angle = 15, ends = "last"))
  grid.text("3'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
  grid.text("5'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
} else {
  grid.lines(x=c(convertUnit(unit(3, "lines"), "npc", valueOnly = TRUE), 1 - convertUnit(unit(2, "lines"), "npc", valueOnly = TRUE)),
            y=unit(1, "lines"), gp=gpar(col = "blue", lwd = 1.5, xpd=NA),
             arrow=arrow(length = unit(0.1, "inches"), angle = 15, ends = "first"))
  grid.text("5'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
  grid.text("3'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
}
  popViewport()
  pushViewport(viewport(y=.625, height=.25))
  #par(mar = c(4, 3, 1.5, 2))
  plotMotifLogo(pcm2pfm(ref_aug_match_pwm), font="mono,Courier", yaxis=FALSE, xlab="",
                ylab=paste("(", motif.match$ref_strand, ")", sep=""),  newpage=FALSE, margins = c(2, 3, 1.5, 2))
  pushViewport(plotViewport(margins = c(2, 3, 1.5, 2)))
  grid.rect(x=(snp_loc+.5)/motif.match$snp_ref_length, width = 1/motif.match$snp_ref_length, gp=gpar(col="blue", lty=3, lwd=2, fill=NA))
  popViewport()
  if(motif.match$ref_strand=="+")   {
    grid.text("3'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(2.5, "lines"))
    grid.text("5'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(2.5, "lines"))
} else {
  grid.text("5'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(2.5, "lines"))
  grid.text("3'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(2.5, "lines"))
}
popViewport()
pushViewport(viewport(y=.375, height=.25))
#par(mar=c(1.5, 3, 4, 2))
plotMotifLogo(pcm2pfm(snp_aug_match_pwm), "Best match to the SNP genome", font="mono,Courier",
              yaxis=FALSE, xlab="", ylab=paste("(", motif.match$snp_strand, ")", sep=""), newpage=FALSE, margins = c(1.5, 3, 2, 2))
pushViewport(plotViewport(margins = c(1.5, 3, 2, 2)))
grid.rect(x=(snp_loc+.5)/motif.match$snp_ref_length, width = 1/motif.match$snp_ref_length, gp=gpar(col="blue", lty=3, lwd=2, fill=NA))
popViewport()
  if(motif.match$snp_strand=="+")   {
    grid.text("3'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
    grid.text("5'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
} else {
  grid.text("5'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
  grid.text("3'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(.5, "lines"))
}
popViewport()
pushViewport(viewport(y=.125, height=.25))
#par(mar=c(4, 3, 1.5, 2))
plotMotifLogo(pcm2pfm(snp_aug_pwm), yaxis=FALSE, xaxis=FALSE, xlab="", ylab="PWM", newpage=FALSE, margins = c(2, 3, 1.5, 2))
if(motif.match$snp_strand=='+') {
  grid.lines(x=c(convertUnit(unit(3, "lines"), "npc", valueOnly = TRUE), 1 - convertUnit(unit(1, "lines"), "npc", valueOnly = TRUE)),
             y=unit(1.5, "lines"), gp=gpar(col = "blue", lwd = 1.5, xpd=NA),
             arrow=arrow(length = unit(0.1, "inches"), angle = 15, ends = "last"))
  grid.text("3'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(1, "lines"))
  grid.text("5'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(1, "lines"))
} else {
  grid.lines(x=c(convertUnit(unit(3, "lines"), "npc", valueOnly = TRUE), 1 - convertUnit(unit(1, "lines"), "npc", valueOnly = TRUE)),
             y=unit(1.5, "lines"), gp=gpar(col = "blue", lwd = 1.5, xpd=NA),
             arrow=arrow(length = unit(0.1, "inches"), angle = 15, ends = "first"))
  grid.text("5'", x=unit(1, "npc") - unit(1, "lines"), gp=gpar(col="blue", cex=1), y=unit(1, "lines"))
  grid.text("3'", x=unit(2, "lines"), gp=gpar(col="blue", cex=1), y=unit(1, "lines"))
}
popViewport()
popViewport()
  grid.text(label = paste(motif.match$motif, " Motif Scan for ", motif.match$snpid, sep=""),
            y=unit(1, "npc") - unit(1.5, "lines"),
            gp=gpar(cex.main=cex.main, fontface="bold"))

You may want to double check if I understand your parameters correctly. And add grid as a Import package.

Jianhong.

From: "Shin, Sunyoung" <Sunyoung.Shin using utdallas.edu<mailto:Sunyoung.Shin using utdallas.edu>>
Date: Sunday, April 28, 2019 at 3:55 PM
To: "Jianhong Ou, Ph.D." <jianhong.ou using duke.edu<mailto:jianhong.ou using duke.edu>>, "bioc-devel using r-project.org<mailto:bioc-devel using r-project.org>" <bioc-devel using r-project.org<mailto:bioc-devel using r-project.org>>
Subject: Re: [Bioc-devel] Error: invalid graphics state in creating vignettes

Hello Jianhong,

Thank you very much for the quick response. I dropped all par commands, and used layout() instead of par(mfrow=c(4,1)). But, I still get the same error message. I put the updated code below. Do you have some suggestions on debugging?

* creating vignettes ... ERROR

--- re-building ‘atsnp-vignette.rmd’ using rmarkdown

Quitting from lines 292-294 (atsnp-vignette.rmd)

Error: processing vignette 'atsnp-vignette.rmd' failed with diagnostics:

invalid graphics state

--- failed re-building ‘atsnp-vignette.rmd’

plot.new()
  layout(matrix(c(1,2,3,4), 4, 1, byrow = TRUE))
  plotMotifLogo(pcm2pfm(ref_aug_pwm), "Best match to the reference genome", yaxis=FALSE, xaxis=FALSE, xlab="", ylab="PWM", ...)
if(motif.match$ref_strand=='+') {
arrows((min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), -0.17, max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
  mtext("5'", 1, adj=(min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
  mtext("3'", 1, adj=max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
} else {
arrows(max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), -0.17, (min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
  mtext("5'", 1, adj=max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
  mtext("3'", 1, adj=(min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
}
plotMotifLogo(pcm2pfm(ref_aug_match_pwm), font="mono,Courier", yaxis=FALSE, xlab="", ylab=paste("(", motif.match$ref_strand, ")", sep=""), ...)
segments(snp_loc/motif.match$snp_ref_length, 0, snp_loc/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments(snp_loc/motif.match$snp_ref_length, 1, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments((snp_loc+1)/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments(snp_loc/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 0, col="blue", lty=3, lwd=2)
  if(motif.match$ref_strand=="+")   {
  mtext("5'", 1,  adj=0, padj=1, col="blue", cex=1)
  mtext("3'", 1,  adj=1, padj=1, col="blue", cex=1)
} else {
  mtext("3'", 1, adj=0, padj=1, col="blue", cex=1)
  mtext("5'", 1, adj=1, padj=1, col="blue", cex=1)
  }
plotMotifLogo(pcm2pfm(snp_aug_match_pwm), "Best match to the SNP genome", font="mono,Courier", yaxis=FALSE, xlab="", ylab=paste("(", motif.match$snp_strand, ")", sep=""), ...)
segments(snp_loc/motif.match$snp_ref_length, 0, snp_loc/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments(snp_loc/motif.match$snp_ref_length, 1, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments((snp_loc+1)/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
segments(snp_loc/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 0, col="blue", lty=3, lwd=2)
  if(motif.match$snp_strand=="+")   {
  mtext("5'", 1,  adj=0, padj=1, col="blue", cex=1)
  mtext("3'", 1,  adj=1, padj=1, col="blue", cex=1)
} else {
  mtext("3'", 1, adj=0, padj=1, col="blue", cex=1)
  mtext("5'", 1, adj=1, padj=1, col="blue", cex=1)
  }
plotMotifLogo(pcm2pfm(snp_aug_pwm), yaxis=FALSE, xaxis=FALSE, xlab="", ylab="PWM", ...)
if(motif.match$snp_strand=='+') {
arrows((min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), -0.17, max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
  mtext("5'", 1, adj=(min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
  mtext("3'", 1, adj=max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
} else {
arrows(max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), -0.17, (min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
  mtext("5'", 1, adj=max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
  mtext("3'", 1, adj=(min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
}
title(main=paste(motif.match$motif, " Motif Scan for ", motif.match$snpid, sep=""), outer=TRUE, line=-2, cex.main=cex.main)
}


Best,
Sunyoung


On Apr 23, 2019, at 7:57 AM, Jianhong Ou, Ph.D. <jianhong.ou using duke.edu<mailto:jianhong.ou using duke.edu>> wrote:

Hi Sunyong,

plotMotifLogo does not compatible with par now. Please use grid to plot the multiple panels in one canvas. I am working on this but it takes time.

Jianhong.

On 4/23/19, 12:47 AM, "Bioc-devel on behalf of Shin, Sunyoung" <bioc-devel-bounces using r-project.org<mailto:bioc-devel-bounces using r-project.org> on behalf ofSunyoung.Shin using utdallas.edu<mailto:Sunyoung.Shin using utdallas.edu>> wrote:

   Dear all,

   I got an error message: invalid graphics state as below from BUILD report for atSNP 0.99.23 (https://urldefense.proofpoint.com/v2/url?u=https-3A__master.bioconductor.org_packages_3.9_bioc_html_atSNP.html&d=DwIGaQ&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=PXg851DHXyo-Gs3eMIfeo49gUXVh-JSZu_MZDDxGun8&m=PbqNdXfVMLxlePSjrHOEN8-tkQLva8Pg6UAfB4VOTUw&s=lESpOegy3zU7jKZUfxiUhG5mSg7qotzhof_KHZmVEB8&e=). This occurs on every platform: malbec2, tokay2, and celaya2. Running  devtools::check()  on my local computer does not produce the error. I would appreciate it if anyone can help debugging.

   * creating vignettes ... ERROR

   --- re-building ‘atsnp-vignette.rmd’ using rmarkdown
   Quitting from lines 292-294 (atsnp-vignette.rmd)
   Error: processing vignette 'atsnp-vignette.rmd' failed with diagnostics:
   invalid graphics state
   --- failed re-building ‘atsnp-vignette.rmd’

   SUMMARY: processing the following file failed:
     ‘atsnp-vignette.rmd’

   Error: Vignette re-building failed.
   Execution halted

   The graphing function which makes the error is plotMotifMatch(match.seq,  motif.lib = motif_library). Below is the part of the code that is needed  to be fixed, I think.

   {
     par(mfrow=c(4,1), oma=c(1,1,4,1))
     plot.new()
     par(mar=c(1.5, 3, 4, 2))
     plotMotifLogo(pcm2pfm(ref_aug_pwm), "Best match to the reference genome", yaxis=FALSE, xaxis=FALSE, xlab="", ylab="PWM", ...)
   if(motif.match$ref_strand=='+') {
   arrows((min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), -0.17, max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
     mtext("5'", 1, adj=(min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
     mtext("3'", 1, adj=max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
   } else {
   arrows(max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), -0.17, (min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
     mtext("5'", 1, adj=max(which(colSums(ref_aug_pwm)!=0))/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
     mtext("3'", 1, adj=(min(which(colSums(ref_aug_pwm)!=0))-1)/ncol(ref_aug_pwm), padj=1, col="blue", cex=1)
   }
     par(mar = c(4, 3, 1.5, 2))
   plotMotifLogo(pcm2pfm(ref_aug_match_pwm), font="mono,Courier", yaxis=FALSE, xlab="", ylab=paste("(", motif.match$ref_strand, ")", sep=""), ...)
   segments(snp_loc/motif.match$snp_ref_length, 0, snp_loc/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments(snp_loc/motif.match$snp_ref_length, 1, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments((snp_loc+1)/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments(snp_loc/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 0, col="blue", lty=3, lwd=2)
     if(motif.match$ref_strand=="+")   {
     mtext("5'", 1,  adj=0, padj=1, col="blue", cex=1)
     mtext("3'", 1,  adj=1, padj=1, col="blue", cex=1)
   } else {
     mtext("3'", 1, adj=0, padj=1, col="blue", cex=1)
     mtext("5'", 1, adj=1, padj=1, col="blue", cex=1)
     }
   par(mar=c(1.5, 3, 4, 2))
   plotMotifLogo(pcm2pfm(snp_aug_match_pwm), "Best match to the SNP genome", font="mono,Courier", yaxis=FALSE, xlab="", ylab=paste("(", motif.match$snp_strand, ")", sep=""), ...)
   segments(snp_loc/motif.match$snp_ref_length, 0, snp_loc/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments(snp_loc/motif.match$snp_ref_length, 1, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments((snp_loc+1)/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 1, col="blue", lty=3, lwd=2)
   segments(snp_loc/motif.match$snp_ref_length, 0, (snp_loc+1)/motif.match$snp_ref_length, 0, col="blue", lty=3, lwd=2)
     if(motif.match$snp_strand=="+")   {
     mtext("5'", 1,  adj=0, padj=1, col="blue", cex=1)
     mtext("3'", 1,  adj=1, padj=1, col="blue", cex=1)
   } else {
     mtext("3'", 1, adj=0, padj=1, col="blue", cex=1)
     mtext("5'", 1, adj=1, padj=1, col="blue", cex=1)
     }
   par(mar=c(4, 3, 1.5, 2))
   plotMotifLogo(pcm2pfm(snp_aug_pwm), yaxis=FALSE, xaxis=FALSE, xlab="", ylab="PWM", ...)
   if(motif.match$snp_strand=='+') {
   arrows((min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), -0.17, max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
     mtext("5'", 1, adj=(min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
     mtext("3'", 1, adj=max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
   } else {
   arrows(max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), -0.17, (min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), -0.17, length = 0.1, angle = 15, code = 2, col = "blue", lwd = 1.5, xpd=NA)
     mtext("5'", 1, adj=max(which(colSums(snp_aug_pwm)!=0))/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
     mtext("3'", 1, adj=(min(which(colSums(snp_aug_pwm)!=0))-1)/ncol(snp_aug_pwm), padj=1, col="blue", cex=1)
   }
   title(main=paste(motif.match$motif, " Motif Scan for ", motif.match$snpid, sep=""), outer=TRUE, cex.main=cex.main)
   }

   Just in case, I added the sessionInfo() of the local run.

   sessionInfo()

   R version 3.5.2 (2018-12-20)
   Platform: x86_64-apple-darwin15.6.0 (64-bit)
   Running under: macOS Mojave 10.14.3

   Matrix products: default
   BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
   LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

   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] stats     graphics  grDevices utils     datasets  methods   base

   other attached packages:
   [1] atSNP_0.99.23  usethis_1.4.0  devtools_2.0.1


   Best,

   Sunyoung



    [[alternative HTML version deleted]]

   _______________________________________________
   Bioc-devel using r-project.org<mailto:Bioc-devel using r-project.org> mailing list
   https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel&d=DwIGaQ&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=PXg851DHXyo-Gs3eMIfeo49gUXVh-JSZu_MZDDxGun8&m=PbqNdXfVMLxlePSjrHOEN8-tkQLva8Pg6UAfB4VOTUw&s=F94BcjXL4z7uzm48trzSORaQp9mAk3B6ZnZslsvLJEE&e=


	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list