Mercurial > repos > ethevenot > profia
comparison profia_wrapper.R @ 0:39ccace77270 draft
planemo upload for repository https://github.com/workflow4metabolomics/profia.git commit 2757590af8c7ba9833ba3bebd7da7f96b20d1128-dirty
author | ethevenot |
---|---|
date | Sun, 26 Mar 2017 17:37:12 -0400 |
parents | |
children | 4753e64cf694 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:39ccace77270 |
---|---|
1 #!/usr/bin/env Rscript | |
2 | |
3 library(batch) ## parseCommandArgs | |
4 | |
5 argVc <- unlist(parseCommandArgs(evaluate=FALSE)) | |
6 | |
7 ##------------------------------ | |
8 ## Initializing | |
9 ##------------------------------ | |
10 | |
11 | |
12 ## libraries | |
13 ##---------- | |
14 | |
15 suppressMessages(library(proFIA)) | |
16 | |
17 | |
18 ## constants | |
19 ##---------- | |
20 | |
21 modNamC <- "proFIA" ## module name | |
22 | |
23 | |
24 ## log file | |
25 ##--------- | |
26 | |
27 sink(argVc["information"]) | |
28 | |
29 cat("\nStart of the '", modNamC, "' Galaxy module call: ", | |
30 format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") | |
31 | |
32 | |
33 ## arguments | |
34 ##---------- | |
35 | |
36 | |
37 if("zipfile" %in% names(argVc)) { | |
38 | |
39 zipfile <- argVc["zipfile"] | |
40 | |
41 ## We unzip automatically the raw files from the zip file | |
42 | |
43 if(exists("zipfile") && (zipfile!="")) { | |
44 if(!file.exists(zipfile)){ | |
45 error_message=paste("Cannot access the Zip file:", zipfile) | |
46 print(error_message) | |
47 stop(error_message) | |
48 } | |
49 | |
50 ## unzip | |
51 | |
52 suppressWarnings(unzip(zipfile, unzip="unzip")) | |
53 | |
54 ## get the directory name | |
55 | |
56 filesInZip=unzip(zipfile, list=T); | |
57 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))); | |
58 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] | |
59 directory = "." | |
60 if (length(directories) == 1) directory = directories | |
61 | |
62 cat("files_root_directory\t",directory,"\n") | |
63 | |
64 } | |
65 | |
66 } else if ("library" %in% names(argVc)) { | |
67 | |
68 directory <- argVc["library"] | |
69 | |
70 if(!file.exists(directory)) { | |
71 | |
72 error_message=paste("Cannot access the directory:", directory,". Please check that the directory really exists.") | |
73 print(error_message) | |
74 stop(error_message) | |
75 | |
76 } | |
77 | |
78 } else { | |
79 | |
80 error_message <- "No zipfile nor input library available" | |
81 print(error_message) | |
82 stop(error_message) | |
83 | |
84 } | |
85 | |
86 ##------------------------------ | |
87 ## Computations | |
88 ##------------------------------ | |
89 | |
90 | |
91 optWrnN <- options()$warn | |
92 options(warn = -1) | |
93 | |
94 stpI <- 1 | |
95 | |
96 cat("\n", stpI, ") Peak detection step ('proFIAset'):\n", sep = "") | |
97 | |
98 fiaset <- proFIAset(directory, | |
99 ppm = as.numeric(argVc["ppmN"]), | |
100 parallel = FALSE) | |
101 | |
102 stpI <- stpI + 1 | |
103 | |
104 cat("\n", stpI, ") Peak alignment ('group.FIA'):\n", sep = "") | |
105 | |
106 fiaset <- group.FIA(fiaset, | |
107 ppmGroup = as.numeric(argVc["ppmGroupN"]), | |
108 fracGroup = as.numeric(argVc["fracGroupN"])) | |
109 | |
110 stpI <- stpI + 1 | |
111 | |
112 cat("\n", stpI, ") Creating the peak table ('makeDataMatrix'):\n", sep = "") | |
113 | |
114 fiaset <- makeDataMatrix(fiaset, | |
115 maxo = FALSE) | |
116 | |
117 stpI <- stpI + 1 | |
118 | |
119 kI <- as.integer(argVc["kI"]) | |
120 | |
121 if(kI > 0) { | |
122 | |
123 cat("\n", stpI, ") Imputing missing values ('imputeMissingValues.WKNN_TN'):\n", sep = "") | |
124 | |
125 fiaset <- imputeMissingValues.WKNN_TN(fiaset, | |
126 k = kI) | |
127 | |
128 stpI <- stpI + 1 | |
129 } | |
130 | |
131 options(warn = optWrnN) | |
132 | |
133 | |
134 ##------------------------------ | |
135 ## Ending | |
136 ##------------------------------ | |
137 | |
138 | |
139 ## Plotting | |
140 ##--------- | |
141 | |
142 cat("\n", stpI, ") Plotting ('plot'):\n", sep = "") | |
143 | |
144 pdf(argVc["figure"]) | |
145 | |
146 plot(fiaset) | |
147 | |
148 dev.off() | |
149 | |
150 stpI <- stpI + 1 | |
151 | |
152 ## Printing | |
153 ##--------- | |
154 | |
155 cat("\n", stpI, ") Printing ('show'):\n", sep = "") | |
156 | |
157 fiaset | |
158 | |
159 stpI <- stpI + 1 | |
160 | |
161 ## Exporting | |
162 ##---------- | |
163 | |
164 cat("\n", stpI, ") Exporting ('exportDataMatrix', 'exportSampleMetadata', 'exportVariableMetadata'):\n", sep = "") | |
165 | |
166 datMN <- exportDataMatrix(fiaset) | |
167 samDF <- exportSampleMetadata(fiaset) | |
168 varDF <- exportVariableMetadata(fiaset) | |
169 | |
170 if(nrow(datMN) == nrow(samDF) && ncol(datMN) == nrow(varDF)) { | |
171 datDF <- as.data.frame(t(datMN)) | |
172 } else { | |
173 datDF <- as.data.frame(datMN) | |
174 } | |
175 rownames(varDF) <- rownames(datDF) | |
176 | |
177 datDF <- cbind.data.frame(dataMatrix = rownames(datDF), | |
178 datDF) | |
179 write.table(datDF, | |
180 file = argVc["dataMatrix_out"], | |
181 quote = FALSE, | |
182 row.names = FALSE, | |
183 sep = "\t") | |
184 | |
185 samDF <- cbind.data.frame(sampleMetadata = rownames(samDF), | |
186 samDF) | |
187 write.table(samDF, | |
188 file = argVc["sampleMetadata_out"], | |
189 quote = FALSE, | |
190 row.names = FALSE, | |
191 sep = "\t") | |
192 | |
193 varDF <- cbind.data.frame(variableMetadata = rownames(varDF), | |
194 varDF) | |
195 write.table(varDF, | |
196 file = argVc["variableMetadata_out"], | |
197 quote = FALSE, | |
198 row.names = FALSE, | |
199 sep = "\t") | |
200 | |
201 | |
202 ## Closing | |
203 ##-------- | |
204 | |
205 cat("\nEnd of '", modNamC, "' Galaxy module call: ", | |
206 as.character(Sys.time()), "\n", sep = "") | |
207 | |
208 sink() | |
209 | |
210 rm(list = ls()) |