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',
|
13
|
25 'cluster', 'b', 2, 'character',
|
|
26 'labels', 'a', 2, 'character',
|
3
|
27 'output', 'o', 2, 'character'
|
|
28 ), byrow=TRUE, ncol=4);
|
2
|
29
|
3
|
30 # Parse options
|
|
31 options = getopt(option_specification);
|
2
|
32
|
|
33
|
|
34
|
3
|
35 # Print options to see what is going on
|
|
36 cat("\n input: ",options$input)
|
|
37 cat("\n title: ",options$title)
|
|
38 cat("\n output: ",options$output)
|
2
|
39
|
3
|
40 input <- read.delim(options$input,sep='\t',header=TRUE)
|
2
|
41
|
3
|
42 mat_input <- data.matrix(input[,2:ncol(input)])
|
2
|
43
|
|
44
|
3
|
45 if(options$transform == "none"){
|
|
46 linput <- mat_input
|
|
47 }else if(options$transform == "log2"){
|
|
48 linput <- log2(mat_input)
|
|
49 }else if(options$transform == "log2plus1"){
|
|
50 linput <- log2(mat_input+1)
|
|
51 }else if(options$transform == "log10"){
|
|
52 linput <- log10(mat_input)
|
|
53 }else if(options$transform == "log10plus1"){
|
|
54 linput <- log10(mat_input+1)
|
|
55 }else{
|
|
56 }
|
2
|
57
|
13
|
58 if(options$colorscheme == "whrd"){
|
10
|
59 colorscale = colfunc <- colorRampPalette(c("white", "red"))
|
13
|
60 } else if(options$colorscheme == "whblu"){
|
|
61 colorscale = colfunc <- colorRampPalette(c("white", "blue"))
|
|
62 }else if(options$colorscheme == "blwhre"){
|
10
|
63 colorscale = colfunc <- colorRampPalette(c("blue","white", "red"))
|
13
|
64 }else{
|
10
|
65 }
|
2
|
66
|
|
67
|
13
|
68 if(options$cluster== "Default"){
|
|
69 hclust_fun = function(x) hclust(x, method="complete")
|
|
70 dist_fun = function(x) dist(x, method="maximum")
|
|
71 clust = distfun=dist_fun, hclustfun=hclust_fun
|
|
72 }else{
|
|
73 clust = NULL
|
|
74 }
|
|
75
|
|
76 if(options$labels== "both"){
|
|
77 labs = NULL
|
|
78 }else if(options$labels== "rows"){
|
|
79 labs = labCol=FALSE
|
|
80 }else if(options$labels== "columns"){
|
|
81 labs = labRow=FALSE
|
|
82 }else if(options$labels== "none"){
|
|
83 labs = labRow=FALSE, labCol=FALSE
|
|
84 } else{
|
|
85 }
|
|
86
|
|
87
|
|
88
|
2
|
89
|
3
|
90 pdf(file="Rplot.pdf")
|
10
|
91 colorscale
|
3
|
92 heatmap.2(linput,
|
13
|
93 clust, scale = options$scale,
|
|
94 col=colfunc(50), trace="none", density.info = "none", labs, margins=c(8,2),
|
8
|
95 main = options$title, key.xlab= options$key, keysize=1)
|
3
|
96 dev.off()
|