View Single Post
Old 08-24-2013, 12:20 PM   #10
crazyhottommy
Senior Member
 
Location: Gainesville

Join Date: Apr 2012
Posts: 140
Smile

Quote:
Originally Posted by jmw86069 View Post
No bother at all, sorry I didn't get back to this earlier in the day. The "lazy-load database 'P' is corrupt" sounds like a symptom of memory limits, or session corruption, or both. Occasionally I'll have an R session go stale -- either the tempdir() cannot be found or the X-windows lost its authentication. In either case the most time-effective fix is to save the R session (and the history), close and re-open R. So did these errors all come from one R session, or are they reproducible each time you open a new R session? I'd check that you're indeed running 64-bit R on whatever platform. See if it works fine with only half the rows of data.

Now for my heatmap power tip of the day, if you will: use the "useRaster=TRUE" parameter in your heatmap.2() call. Excellent extension by R developers since 2.13. But for some reason the R developers explicitly turn it off for interactive session windows, so you'll only see it in an exported file. (Unless you have a custom image() function which doesn't disable it, I did this.) It also makes the exported file hugely smaller, especially for PDFs.

What it does is darn-near essential for nextgen coverage heatmaps -- it actually properly resamples the image as it down-sizes the image during export. Without useRaster=TRUE, image() creates a zillion tiny rectangles to represent the heatmap, all pieced together right next to each other. When the display is fewer pixels/points high than the number of rows of data, it discretizes the data -- that is, it uses integer values for the rectangles. In many cases, especially onscreen, many rectangles fully overlap others, randomly obscuring the real patterns, and often blunting your otherwise cool-looking signal.

Best way to test is export to PDF with useRaster=FALSE, then do it again with useRaster=TRUE. For me, night and day.
Code:
library(gplots);
## Prep some random noise sample data
testHeatdata <- matrix(rnorm(90000), nrow=10000, ncol=9);
testHeatdata <- testHeatdata[order(testHeatdata[,5]),];
testHeatdata2 <- testHeatdata;
g1 <- seq(from=10, to=10000, by=1000);
## Make some tiny horizontal stripes
testHeatdata2[g1+rep(1:3, each=length(g1)),] <- 9;

## Try to hide a little happy face
testHeatdata3 <- testHeatdata;
for (i in seq(from=125, to=235, by=3)) {
   ix <- round(sin(deg2rad(i))*5+5);
   iy <- round(-cos(deg2rad(i))*5500 + 3500);
   testHeatdata3[iy:(iy+4), ix] <- 10;
}
g2 <- 3011+c(1:12*90);
testHeatdata3[g2+rep(1:3, each=length(g2)), 4] <- 10;
testHeatdata3[g2+rep(1:3, each=length(g2)), 7] <- 10;

cairo_pdf("testHeatmapRaster.pdf", onefile=TRUE);
heatmap.2(testHeatdata2, Rowv=FALSE, Colv=FALSE, useRaster=FALSE, labRow=NA, symbreaks=TRUE, breaks=51,
   main="useRaster=FALSE", col="redblue", trace="none", key=FALSE);
heatmap.2(testHeatdata2, Rowv=FALSE, Colv=FALSE, useRaster=TRUE, labRow=NA, symbreaks=TRUE, breaks=51,
   main="useRaster=TRUE", col="redblue", trace="none", key=FALSE);
heatmap.2(testHeatdata3, Rowv=FALSE, Colv=FALSE, useRaster=FALSE, labRow=NA, symbreaks=TRUE, breaks=51,
   main="useRaster=FALSE", col="redblue", trace="none", key=FALSE);
heatmap.2(testHeatdata3, Rowv=FALSE, Colv=FALSE, useRaster=TRUE, labRow=NA, symbreaks=TRUE, breaks=51,
   main="useRaster=TRUE", col="redblue", trace="none", key=FALSE);
dev.off();

Thank you so much for your insight! I am running 64-bit R in ubuntu 12.04 through Emacs.
I restarted emacs and run the code, it worked fine!

Also, I am so happy to know the useRaster argument. I learned a lot from you.
crazyhottommy is offline   Reply With Quote