3
|
1 # Setup R error handling to go to stderr
|
|
2 options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
|
2
|
3
|
3
|
4 # We need to not crash galaxy with an UTF8 error on German LC settings.
|
|
5 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
|
2
|
6
|
|
7
|
3
|
8 # Import library
|
|
9 library("getopt")
|
|
10 library("RColorBrewer")
|
|
11 library("gplots")
|
|
12 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
|
|
13 # Take in trailing command line arguments
|
|
14 args <- commandArgs(trailingOnly = TRUE)
|
2
|
15
|
|
16
|
3
|
17 # get options, using the spec as defined by the enclosed list.
|
|
18 # we read the options from the default: commandArgs(TRUE).
|
|
19 option_specification = matrix(c(
|
|
20 'input', 'i', 2, 'character',
|
8
|
21 'title', 't', 2, 'character',
|
3
|
22 'transform', 'c', 2, 'character',
|
8
|
23 'key', 'k', 2, 'character',
|
10
|
24 'colorscheme', 'z', 2, 'character',
|
3
|
25 'output', 'o', 2, 'character'
|
|
26 ), byrow=TRUE, ncol=4);
|
2
|
27
|
3
|
28 # Parse options
|
|
29 options = getopt(option_specification);
|
2
|
30
|
|
31
|
|
32
|
3
|
33 # Print options to see what is going on
|
|
34 cat("\n input: ",options$input)
|
|
35 cat("\n title: ",options$title)
|
|
36 cat("\n output: ",options$output)
|
2
|
37
|
3
|
38 input <- read.delim(options$input,sep='\t',header=TRUE)
|
2
|
39
|
3
|
40 mat_input <- data.matrix(input[,2:ncol(input)])
|
2
|
41
|
|
42
|
3
|
43 if(options$transform == "none"){
|
|
44 linput <- mat_input
|
|
45 }else if(options$transform == "log2"){
|
|
46 linput <- log2(mat_input)
|
|
47 }else if(options$transform == "log2plus1"){
|
|
48 linput <- log2(mat_input+1)
|
|
49 }else if(options$transform == "log10"){
|
|
50 linput <- log10(mat_input)
|
|
51 }else if(options$transform == "log10plus1"){
|
|
52 linput <- log10(mat_input+1)
|
|
53 }else{
|
|
54 }
|
2
|
55
|
10
|
56 if(options$colorscheme == "Default"){
|
|
57 colorscale = colfunc <- colorRampPalette(c("white", "red"))
|
|
58 } else {
|
|
59 colorscale = colfunc <- colorRampPalette(c("blue","white", "red"))
|
|
60 }
|
2
|
61
|
|
62
|
3
|
63 hclust_fun = function(x) hclust(x, method="complete")
|
|
64 dist_fun = function(x) dist(x, method="maximum")
|
2
|
65
|
3
|
66 pdf(file="Rplot.pdf")
|
10
|
67 colorscale
|
3
|
68 heatmap.2(linput,
|
|
69 distfun=dist_fun, hclustfun=hclust_fun, scale = "none",
|
|
70 col=colfunc(50), trace="none", density.info = "none",labRow=FALSE, margins=c(8,2),
|
8
|
71 main = options$title, key.xlab= options$key, keysize=1)
|
3
|
72 dev.off()
|