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