Mercurial > repos > ethevenot > heatmap
comparison heatmap_wrapper.R @ 0:ad06aeed02c9 draft
planemo upload for repository https://github.com/workflow4metabolomics/heatmap.git commit 7e599d006e53fefb7e1b923ba8894b4fb19f9cfa-dirty
author | ethevenot |
---|---|
date | Tue, 02 Aug 2016 06:26:41 -0400 |
parents | |
children | b1667c118127 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ad06aeed02c9 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 library(batch) ## parseCommandArgs | |
4 | |
5 source_local <- function(fname){ | |
6 argv <- commandArgs(trailingOnly = FALSE) | |
7 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | |
8 source(paste(base_dir, fname, sep="/")) | |
9 } | |
10 | |
11 source_local("heatmap_script.R") | |
12 | |
13 argVc <- unlist(parseCommandArgs(evaluate=FALSE)) | |
14 | |
15 | |
16 ##------------------------------ | |
17 ## Initializing | |
18 ##------------------------------ | |
19 | |
20 ## options | |
21 ##-------- | |
22 | |
23 strAsFacL <- options()[["stringsAsFactors"]] | |
24 options(stringsAsFactors=FALSE) | |
25 | |
26 ## constants | |
27 ##---------- | |
28 | |
29 modNamC <- "Heatmap" ## module name | |
30 | |
31 ## log file | |
32 ##--------- | |
33 | |
34 sink(argVc["information"]) | |
35 | |
36 cat("\nStart of the '", modNamC, "' module: ", | |
37 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
38 | |
39 ## loading | |
40 ##-------- | |
41 | |
42 proMN <- t(as.matrix(read.table(argVc["dataMatrix_in"], | |
43 check.names = FALSE, | |
44 header = TRUE, | |
45 row.names = 1, | |
46 sep = "\t"))) | |
47 | |
48 obsDF <- read.table(argVc["sampleMetadata_in"], | |
49 check.names = FALSE, | |
50 header = TRUE, | |
51 row.names = 1, | |
52 sep = "\t") | |
53 | |
54 feaDF <- read.table(argVc["variableMetadata_in"], | |
55 check.names = FALSE, | |
56 header = TRUE, | |
57 row.names = 1, | |
58 sep = "\t") | |
59 | |
60 ## adding default parameter values | |
61 ##-------------------------------- | |
62 | |
63 | |
64 if(!("corMetC" %in% names(argVc))) | |
65 argVc["corMetC"] <- "pearson" | |
66 if(!("aggMetC" %in% names(argVc))) | |
67 argVc["aggMetC"] <- "ward" | |
68 if(!("colC" %in% names(argVc))) | |
69 argVc["colC"] <- "blueOrangeRed" | |
70 if(!("scaL" %in% names(argVc))) | |
71 argVc["scaL"] <- "TRUE" | |
72 if(!("cexN" %in% names(argVc))) | |
73 argVc["cexN"] <- "0.8" | |
74 | |
75 ## checking | |
76 ##--------- | |
77 | |
78 if(as.numeric(argVc["cutSamN"]) > nrow(proMN)) | |
79 stop("Number of sample clusters must be inferior to the number of samples") | |
80 if(as.numeric(argVc["cutVarN"]) > ncol(proMN)) | |
81 stop("Number of variable clusters must be inferior to the number of variables") | |
82 | |
83 ## printing arguments | |
84 ##------------------- | |
85 | |
86 cat("\nArguments used:\n\n") | |
87 argMC <- as.matrix(argVc) | |
88 colnames(argMC) <- "value" | |
89 argDatVl <- grepl("\\.dat$", argVc) ## discarding dataset file names | |
90 if(sum(argDatVl)) | |
91 argMC <- argMC[!argDatVl, , drop = FALSE] | |
92 print(argMC) | |
93 | |
94 | |
95 ##------------------------------ | |
96 ## Computation | |
97 ##------------------------------ | |
98 | |
99 | |
100 heaLs <- heatmapF(proMN = proMN, | |
101 obsDF = obsDF, | |
102 feaDF = feaDF, | |
103 disC = argVc["disC"], | |
104 cutSamN = as.numeric(argVc["cutSamN"]), | |
105 cutVarN = as.numeric(argVc["cutVarN"]), | |
106 fig.pdfC = argVc["figure"], | |
107 corMetC = argVc["corMetC"], | |
108 aggMetC = argVc["aggMetC"], | |
109 colC = argVc["colC"], | |
110 scaL = as.logical(argVc["scaL"]), | |
111 cexN = as.numeric(argVc["cexN"])) | |
112 | |
113 | |
114 ##------------------------------ | |
115 ## Ending | |
116 ##------------------------------ | |
117 | |
118 | |
119 ## saving | |
120 ##------- | |
121 | |
122 proDF <- cbind.data.frame(dataMatrix = colnames(heaLs[["proMN"]]), | |
123 as.data.frame(t(heaLs[["proMN"]]))) | |
124 write.table(proDF, | |
125 file = argVc["dataMatrix_out"], | |
126 quote = FALSE, | |
127 row.names = FALSE, | |
128 sep = "\t") | |
129 | |
130 obsDF <- cbind.data.frame(sampleMetadata = rownames(heaLs[["obsDF"]]), | |
131 heaLs[["obsDF"]]) | |
132 write.table(obsDF, | |
133 file = argVc["sampleMetadata_out"], | |
134 quote = FALSE, | |
135 row.names = FALSE, | |
136 sep = "\t") | |
137 | |
138 feaDF <- cbind.data.frame(variableMetadata = rownames(heaLs[["feaDF"]]), | |
139 heaLs[["feaDF"]]) | |
140 write.table(feaDF, | |
141 file = argVc["variableMetadata_out"], | |
142 quote = FALSE, | |
143 row.names = FALSE, | |
144 sep = "\t") | |
145 | |
146 ## Ending | |
147 ##------- | |
148 | |
149 cat("\nEnd of the '", modNamC, "' Galaxy module call: ", | |
150 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep = "") | |
151 | |
152 sink() | |
153 | |
154 options(stringsAsFactors = strAsFacL) | |
155 | |
156 rm(list = ls()) |