From 37fa1bf0cc3a559eb9d4b6c1534c0bc4bd9475df Mon Sep 17 00:00:00 2001 From: chartl Date: Tue, 16 Feb 2010 15:12:54 +0000 Subject: [PATCH] Added heatmap function git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2843 348d0f76-0448-11de-a6fe-93d51630548a --- R/plotting_library.R | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/R/plotting_library.R b/R/plotting_library.R index e1ffc6d31..db42f75c1 100644 --- a/R/plotting_library.R +++ b/R/plotting_library.R @@ -45,10 +45,53 @@ PlotInterleavedRows <- function(inFile,args) { pdf(paste(outFileBase,"_rplot",".pdf",sep="")) matplot(evalPoints,funcVal,col=colors,lty=styles,"l",xlab=xlabel,ylab=ylabel) legend("topright",funcVal[1,],lty=styles,col=colors) + title(main=title,outer=TRUE) # save dev.off() } PlotInterleavedRows(fileToRead,functionSpecificArgs) +} + +if ( functionToRun == "PlotHeatmap" ) { +### PLOT HEATMAP FUNCTION ### +# +# Normally what is meant by "heatmap" is just an image() of the +# matrix; in accordance with that, THIS FUNCTION DOES NOT COMPUTE +# DENDROGRAMS THROUGH HEATMAP(), so no rows and columns are not +# re-ordered, and dendrograms are not displayed. +# +# - expects a file of the form +# +# rentry1 \t rentry2 \t rentry3 \t ... +# colentry1 \t 0.7 \t 0.9 \t 0.4 \t ... +# colentry2 \t 0.8 \t 0.7 \t 0.6 \t ... +# ... +# Note that the rows and columns don't line up. R understands this +# and deals with it. +# Also expects an argument string: +# row_label;column_label;data_rescale_factor;plot_title;base_name_for_pdf +# - end of info - +### PLOT HEATMAP FUNCTION ### +PlotHeatmap <- function(inFile,args) { + arglist = unlist(strsplit(args,split=";")) + row_label = arglist[1] + column_label = arglist[2] + data_rescale_factor <- as.numeric(arglist[3]) + plot_title = arglist[4] + base_name_for_pdf = arglist[5] + image_matrix <- data_rescale_factor*as.matrix(read.table(inFile)) + ## change default colors to include "cool" colors for lower end of spectrum + ## e.g. red ~ near 1, yellow ~ near .75, green ~ near .5, teal ~ near .25 + ## blue ~ near 0 + colors <- rev(rainbow(32,start=0,end=0.6,s=0.9,v=0.9,gamma=0.8)) + pdf(paste(base_name_for_pdf,"_rplot",".pdf",sep="")) + heatmap(image_matrix,Rowv=NA,Colv=NA,ylab=row_label,xlab=column_label,col=colors) + title(main=plot_title,outer=TRUE) + dev.off() +} + +PlotHeatmap(fileToRead,functionSpecificArgs) + } \ No newline at end of file