Mercurial > repos > moheydarian > heatmap2
view heatmap2.R @ 14:b3eb35cfc36d draft
Uploaded
author | moheydarian |
---|---|
date | Thu, 27 Apr 2017 13:30:18 -0400 |
parents | e75734b84e61 |
children | e9b93b60de80 |
line wrap: on
line source
# Setup R error handling to go to stderr options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)}) # We need to not crash galaxy with an UTF8 error on German LC settings. loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") # Import library library("getopt") library("RColorBrewer") library("gplots") options(stringAsfactors = FALSE, useFancyQuotes = FALSE) # Take in trailing command line arguments args <- commandArgs(trailingOnly = TRUE) # get options, using the spec as defined by the enclosed list. # we read the options from the default: commandArgs(TRUE). option_specification = matrix(c( 'input', 'i', 2, 'character', 'title', 't', 2, 'character', 'transform', 'c', 2, 'character', 'key', 'k', 2, 'character', 'colorscheme', 'z', 2, 'character', 'cluster', 'b', 2, 'character', 'labels', 'a', 2, 'character', 'scale', 'd', 2, 'character', 'output', 'o', 2, 'character' ), byrow=TRUE, ncol=4); # Parse options options = getopt(option_specification); # Print options to see what is going on cat("\n input: ",options$input) cat("\n title: ",options$title) cat("\n output: ",options$output) input <- read.delim(options$input,sep='\t',header=TRUE) mat_input <- data.matrix(input[,2:ncol(input)]) if(options$transform == "none"){ linput <- mat_input }else if(options$transform == "log2"){ linput <- log2(mat_input) }else if(options$transform == "log2plus1"){ linput <- log2(mat_input+1) }else if(options$transform == "log10"){ linput <- log10(mat_input) }else if(options$transform == "log10plus1"){ linput <- log10(mat_input+1) }else{ } if(options$colorscheme == "whrd"){ colorscale = colfunc <- colorRampPalette(c("white", "red")) } else if(options$colorscheme == "whblu"){ colorscale = colfunc <- colorRampPalette(c("white", "blue")) }else if(options$colorscheme == "blwhre"){ colorscale = colfunc <- colorRampPalette(c("blue","white", "red")) }else{ } if(options$cluster== "Default"){ hclust_fun = function(x) hclust(x, method="complete") dist_fun = function(x) dist(x, method="maximum") clust = distfun=dist_fun, hclustfun=hclust_fun }else{ clust = NULL } if(options$labels== "both"){ labs = NULL }else if(options$labels== "rows"){ labs = labCol=FALSE }else if(options$labels== "columns"){ labs = labRow=FALSE }else if(options$labels== "none"){ labs = labRow=FALSE, labCol=FALSE } else{ } pdf(file="Rplot.pdf") colorscale heatmap.2(linput, clust, scale = options$scale, col=colfunc(50), trace="none", density.info = "none", labs, margins=c(8,2), main = options$title, key.xlab= options$key, keysize=1) dev.off()