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',
|
|
21 'title', 't',2, 'character',
|
|
22 'transform', 'c', 2, 'character',
|
|
23 'keylabel', 'k',2, 'character',
|
|
24 'output', 'o', 2, 'character'
|
|
25 ), byrow=TRUE, ncol=4);
|
2
|
26
|
3
|
27 # Parse options
|
|
28 options = getopt(option_specification);
|
2
|
29
|
|
30
|
|
31
|
3
|
32 # Print options to see what is going on
|
|
33 cat("\n input: ",options$input)
|
|
34 cat("\n title: ",options$title)
|
|
35 cat("\n output: ",options$output)
|
2
|
36
|
3
|
37 input <- read.delim(options$input,sep='\t',header=TRUE)
|
2
|
38
|
3
|
39 mat_input <- data.matrix(input[,2:ncol(input)])
|
2
|
40
|
|
41
|
3
|
42 if(options$transform == "none"){
|
|
43 linput <- mat_input
|
|
44 }else if(options$transform == "log2"){
|
|
45 linput <- log2(mat_input)
|
|
46 }else if(options$transform == "log2plus1"){
|
|
47 linput <- log2(mat_input+1)
|
|
48 }else if(options$transform == "log10"){
|
|
49 linput <- log10(mat_input)
|
|
50 }else if(options$transform == "log10plus1"){
|
|
51 linput <- log10(mat_input+1)
|
|
52 }else{
|
|
53 }
|
2
|
54
|
|
55
|
|
56
|
3
|
57 hclust_fun = function(x) hclust(x, method="complete")
|
|
58 dist_fun = function(x) dist(x, method="maximum")
|
2
|
59
|
3
|
60 pdf(file="Rplot.pdf")
|
|
61 colfunc <- colorRampPalette(c("white", "red"))
|
|
62 heatmap.2(linput,
|
|
63 distfun=dist_fun, hclustfun=hclust_fun, scale = "none",
|
|
64 col=colfunc(50), trace="none", density.info = "none",labRow=FALSE, margins=c(8,2),
|
|
65 main = options$title, key.xlab= options$keylabel, keysize=1)
|
|
66 dev.off()
|