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