comparison NmrPreprocessing_wrapper.R @ 7:122df1bf0a8c draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/nmr_preprocessing commit 3d328007dd7716848ec2eeb6c2a472f27eeb2995
author workflow4metabolomics
date Fri, 11 Jul 2025 08:33:38 +0000
parents 5b06800f3449
children
comparison
equal deleted inserted replaced
6:6e837e9352a2 7:122df1bf0a8c
1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
2
3 ## 170116_NmrPreprocessing.R
4 ## Manon Martin and Marie Tremblay-Franco
5
6 ##======================================================
7 ##======================================================
8 # Preamble
9 ##======================================================
10 ##======================================================
11
12 runExampleL <- FALSE
13
14
15 ##------------------------------
16 ## Options
17 ##------------------------------
18 strAsFacL <- options()$stringsAsFactors
19 options(stringsAsFactors = FALSE)
20
21 ##------------------------------
22 ## Libraries laoding 1 ## Libraries laoding
23 ##------------------------------ 2 ## ------------------------------
24 library(batch)
25 library(ptw) 3 library(ptw)
26 library(Matrix) 4 library(Matrix)
27 library(ggplot2) 5 library(ggplot2)
28 library(gridExtra) 6 library(gridExtra)
29 library(reshape2) 7 library(reshape2)
30 8
9 # In-house function for argument parsing
10 parse_args <- function() {
11 args <- commandArgs()
12 start <- which(args == "--args")[1] + 1
13 if (is.na(start)) {
14 return(list())
15 }
16 seq_by2 <- seq(start, length(args), by = 2)
17 result <- as.list(args[seq_by2 + 1])
18 names(result) <- args[seq_by2]
19 return(result)
20 }
31 21
32 # R script call 22 # R script call
33 source_local <- function(fname) 23 source_local <- function(fname) {
34 { 24 argv <- commandArgs(trailingOnly = FALSE)
35 argv <- commandArgs(trailingOnly = FALSE) 25 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
36 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) 26 source(paste(base_dir, fname, sep = "/"))
37 source(paste(base_dir, fname, sep="/")) 27 }
38 } 28 # Import the different functions
39 #Import the different functions
40 source_local("NmrPreprocessing_script.R") 29 source_local("NmrPreprocessing_script.R")
41 source_local("DrawFunctions.R") 30 source_local("DrawFunctions.R")
42 31
43 ##------------------------------ 32 ## ------------------------------
44 ## Script 33 ## Script
45 ##------------------------------ 34 ## ------------------------------
46 runExampleL <- FALSE 35 runExampleL <- FALSE
47 36
48 37 if (!runExampleL) {
49 if(!runExampleL) 38 argLs <- unlist(parse_args())
50 argLs <- parseCommandArgs(evaluate=FALSE) 39 }
51 40 # input arguments
52 sink(argLs$logOut) 41 cat("\n INPUT and OUTPUT ARGUMENTS :\n")
53 42 print(argLs)
54 43
55 ##------------------------------ 44 ## ------------------------------
56 ## Errors ?????????????????????
57 ##------------------------------
58
59
60 ##------------------------------
61 ## Constants 45 ## Constants
62 ##------------------------------ 46 ## ------------------------------
63 topEnvC <- environment() 47 topEnvC <- environment()
64 flagC <- "\n" 48 flagC <- "\n"
65 49
66
67
68
69 # log file
70 # print(argLs[["logOut"]])
71
72 ## Starting 50 ## Starting
73 cat("\nStart of 'Preprocessing' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "") 51 cat("\nStart of 'Preprocessing' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "")
74 52
75 53 ## ======================================================
76 ##====================================================== 54 ## ======================================================
77 ##======================================================
78 ## Parameters Loading 55 ## Parameters Loading
79 ##====================================================== 56 ## ======================================================
80 ##====================================================== 57 ## ======================================================
81 58
82 # graphical inputs 59 # graphical inputs
83 FirstOPCGraph <- argLs[["FirstOPCGraph"]] 60 FirstOPCGraph <- argLs[["FirstOPCGraph"]]
84 SSGraph <- argLs[["SSGraph"]] 61 SSGraph <- argLs[["SSGraph"]]
85 ApodGraph <- argLs[["ApodGraph"]] 62 ApodGraph <- argLs[["ApodGraph"]]
87 SRGraph <- argLs[["SRGraph"]] 64 SRGraph <- argLs[["SRGraph"]]
88 ZeroOPCGraph <- argLs[["ZeroOPCGraph"]] 65 ZeroOPCGraph <- argLs[["ZeroOPCGraph"]]
89 BCGraph <- argLs[["BCGraph"]] 66 BCGraph <- argLs[["BCGraph"]]
90 FinalGraph <- argLs[["FinalGraph"]] 67 FinalGraph <- argLs[["FinalGraph"]]
91 68
92
93 # 1rst order phase correction ------------------------ 69 # 1rst order phase correction ------------------------
94 # Inputs 70 # Inputs
95 ## Data matrix 71 ## Data matrix
96 Fid_data0 <- read.table(argLs[["dataMatrixFid"]],header=TRUE, check.names=FALSE, sep='\t') 72 Fid_data0 <- read.table(argLs[["dataMatrixFid"]], header = TRUE, check.names = FALSE, sep = "\t")
97 # Fid_data0 <- Fid_data0[,-1] 73 # Fid_data0 <- Fid_data0[,-1]
98 Fid_data0 <- as.matrix(Fid_data0) 74 Fid_data0 <- as.matrix(Fid_data0)
99 75
100 ## Samplemetadata 76 ## Samplemetadata
101 samplemetadataFid <- read.table(argLs[["sampleMetadataFid"]],check.names=FALSE,header=TRUE,sep="\t") 77 samplemetadataFid <- read.table(argLs[["sampleMetadataFid"]], check.names = FALSE, header = TRUE, sep = "\t")
102 samplemetadataFid <- as.matrix(samplemetadataFid) 78 samplemetadataFid <- as.matrix(samplemetadataFid)
103 79
104
105 # water and solvent(s) correction ------------------------ 80 # water and solvent(s) correction ------------------------
106 # Inputs 81 # Inputs
107 lambda <- argLs[["lambda"]] 82 lambda <- as.numeric(argLs[["lambda"]])
108
109
110 83
111 # apodization ----------------------------------------- 84 # apodization -----------------------------------------
112 # Inputs 85 # Inputs
113 phase=0 86 phase <- 0
114 rectRatio=1/2 87 rectRatio <- 1 / 2
115 gaussLB=1 88 gaussLB <- 1
116 expLB=1 89 expLB <- 1
117 apodization <- argLs[["apodizationMethod"]] 90 apodization <- argLs[["apodizationMethod"]]
118 91
119 if (apodization=='exp'){ 92 if (apodization == "exp") {
120 expLB <- argLs[["expLB"]] 93 expLB <- as.numeric(argLs[["expLB"]])
121 } else if (apodization=='cos2'){ 94 } else if (apodization == "cos2") {
122 phase <- argLs[["phase"]] 95 phase <- as.numeric(argLs[["phase"]])
123 } else if (apodization=='hanning'){ 96 } else if (apodization == "hanning") {
124 phase <- argLs[["phase"]] 97 phase <- as.numeric(argLs[["phase"]])
125 } else if (apodization=='hamming'){ 98 } else if (apodization == "hamming") {
126 phase <- argLs[["phase"]] 99 phase <- as.numeric(argLs[["phase"]])
127 } else if (apodization=='blockexp'){ 100 } else if (apodization == "blockexp") {
128 rectRatio <- argLs[["rectRatio"]] 101 rectRatio <- as.numeric(argLs[["rectRatio"]])
129 expLB <- argLs[["expLB"]] 102 expLB <- as.numeric(argLs[["expLB"]])
130 } else if (apodization=='blockcos2'){ 103 } else if (apodization == "blockcos2") {
131 rectRatio <- argLs[["rectRatio"]] 104 rectRatio <- as.numeric(argLs[["rectRatio"]])
132 } else if (apodization=='gauss'){ 105 } else if (apodization == "gauss") {
133 rectRatio <- argLs[["rectRatio"]] 106 rectRatio <- as.numeric(argLs[["rectRatio"]])
134 gaussLB <- argLs[["gaussLB"]] 107 gaussLB <- as.numeric(argLs[["gaussLB"]])
135 } 108 }
136
137 109
138 # Fourier transform ---------------------------------- 110 # Fourier transform ----------------------------------
139 # Inputs 111 # Inputs
140
141 112
142 # Zero Order Phase Correction ------------------------------- 113 # Zero Order Phase Correction -------------------------------
143 # Inputs 114 # Inputs
144 115 angle <- NULL
145 angle = NULL 116 excludeZOPC <- NULL
146 excludeZOPC = NULL
147
148 117
149 zeroOrderPhaseMethod <- argLs[["zeroOrderPhaseMethod"]] 118 zeroOrderPhaseMethod <- argLs[["zeroOrderPhaseMethod"]]
150 119
151 if (zeroOrderPhaseMethod=='manual'){ 120 if (zeroOrderPhaseMethod == "manual") {
152 angle <- argLs[["angle"]] 121 angle <- argLs[["angle"]]
153 } 122 }
154 123
155 excludeZoneZeroPhase <- argLs[["excludeZoneZeroPhase.choice"]] 124 excludeZoneZeroPhase <- argLs[["excludeZoneZeroPhase.choice"]]
156 if (excludeZoneZeroPhase == 'YES') { 125 if (excludeZoneZeroPhase == "YES") {
157 excludeZoneZeroPhaseList <- list() 126 excludeZoneZeroPhaseList <- list()
158 for(i in which(names(argLs)=="excludeZoneZeroPhase_left")) { 127 for (i in which(names(argLs) == "excludeZoneZeroPhase_left")) {
159 excludeZoneZeroPhaseLeft <- argLs[[i]] 128 excludeZoneZeroPhaseLeft <- as.numeric(argLs[[i]])
160 excludeZoneZeroPhaseRight <- argLs[[i+1]] 129 excludeZoneZeroPhaseRight <- as.numeric(argLs[[i + 1]])
161 excludeZoneZeroPhaseList <- c(excludeZoneZeroPhaseList,list(c(excludeZoneZeroPhaseLeft,excludeZoneZeroPhaseRight))) 130 excludeZoneZeroPhaseList <- c(excludeZoneZeroPhaseList, list(c(excludeZoneZeroPhaseLeft, excludeZoneZeroPhaseRight)))
162 } 131 }
163 excludeZOPC <- excludeZoneZeroPhaseList 132 excludeZOPC <- excludeZoneZeroPhaseList
164 } 133 }
165
166 134
167 # Internal referencering ---------------------------------- 135 # Internal referencering ----------------------------------
168 # Inputs 136 # Inputs
169 shiftTreshold = 2 # c 137 shiftTreshold <- 2
170 ppm = TRUE 138 ppm <- TRUE
171 shiftReferencingRangeList = NULL # fromto.RC 139 shiftReferencingRangeList <- NULL # fromto.RC
172 pctNearValue = 0.02 # pc 140 pctNearValue <- 0.02 # pc
173 rowindex_graph = NULL 141 rowindex_graph <- NULL
174 ppm_ref = 0 # ppm.ref 142 ppm_ref <- 0 # ppm.ref
175 143
176 #
177 # shiftReferencing <- argLs[["shiftReferencing"]] 144 # shiftReferencing <- argLs[["shiftReferencing"]]
178 # print(shiftReferencing) 145 # print(shiftReferencing)
179 # 146 #
180 # if (shiftReferencing=="YES") 147 # if (shiftReferencing=="YES") {
181 # { 148 #
182 #
183 # shiftReferencingMethod <- argLs[["shiftReferencingMethod"]] 149 # shiftReferencingMethod <- argLs[["shiftReferencingMethod"]]
184 # 150 #
185 # if (shiftReferencingMethod == "thres") { 151 # if (shiftReferencingMethod == "thres") {
186 # shiftTreshold <- argLs[["shiftTreshold"]] 152 # shiftTreshold <- argLs[["shiftTreshold"]]
187 # } 153 # }
188 154
189 shiftReferencingRange <- argLs[["shiftReferencingRange"]] 155 shiftReferencingRange <- argLs[["shiftReferencingRange"]]
190 156 if (shiftReferencingRange == "near0") {
191 if (shiftReferencingRange == "near0"){ 157 pctNearValue <- as.numeric(argLs[["pctNearValue"]])
192 pctNearValue <- argLs[["pctNearValue"]] 158 }
193 } 159
194 160 if (shiftReferencingRange == "window") {
195 if (shiftReferencingRange == "window"){ 161 shiftReferencingRangeList <- list()
196 shiftReferencingRangeList <- list() 162 for (i in which(names(argLs) == "shiftReferencingRangeLeft"))
197 for(i in which(names(argLs)=="shiftReferencingRangeLeft")) 163 {
198 { 164 shiftReferencingRangeLeft <- as.numeric(argLs[[i]])
199 shiftReferencingRangeLeft <- argLs[[i]] 165 shiftReferencingRangeRight <- as.numeric(argLs[[i + 1]])
200 shiftReferencingRangeRight <- argLs[[i+1]] 166 shiftReferencingRangeList <- c(shiftReferencingRangeList, list(c(shiftReferencingRangeLeft, shiftReferencingRangeRight)))
201 shiftReferencingRangeList <- c(shiftReferencingRangeList,list(c(shiftReferencingRangeLeft,shiftReferencingRangeRight))) 167 }
202 } 168 }
203 }
204
205 shiftHandling <- argLs[["shiftHandling"]] 169 shiftHandling <- argLs[["shiftHandling"]]
206 170
207 ppmvalue <- argLs[["ppmvalue"]] 171 ppmvalue <- as.numeric(argLs[["ppmvalue"]])
208 172 # }
209
210
211 # }
212
213 173
214 # Baseline Correction ------------------------------- 174 # Baseline Correction -------------------------------
215 # Inputs 175 # Inputs
216 lambdaBc <- argLs[["lambdaBc"]] 176 lambdaBc <- as.numeric(argLs[["lambdaBc"]])
217 pBc <- argLs[["pBc"]] 177 pBc <- as.numeric(argLs[["pBc"]])
218 epsilon <- argLs[["epsilon"]] 178 epsilon <- as.numeric(argLs[["epsilon"]])
219 179
220 excludeBC = NULL 180 excludeBC <- NULL
221 181
222 excludeZoneBC <- argLs[["excludeZoneBC.choice"]] 182 excludeZoneBC <- argLs[["excludeZoneBC.choice"]]
223 if (excludeZoneBC == 'YES') { 183 if (excludeZoneBC == "YES") {
224 excludeZoneBCList <- list() 184 excludeZoneBCList <- list()
225 for(i in which(names(argLs)=="excludeZoneBC_left")) { 185 for (i in which(names(argLs) == "excludeZoneBC_left")) {
226 excludeZoneBCLeft <- argLs[[i]] 186 excludeZoneBCLeft <- as.numeric(argLs[[i]])
227 excludeZoneBCRight <- argLs[[i+1]] 187 excludeZoneBCRight <- as.numeric(argLs[[i + 1]])
228 excludeZoneBCList <- c(excludeZoneBCList,list(c(excludeZoneBCLeft,excludeZoneBCRight))) 188 excludeZoneBCList <- c(excludeZoneBCList, list(c(excludeZoneBCLeft, excludeZoneBCRight)))
229 } 189 }
230 excludeBC <- excludeZoneBCList 190 excludeBC <- excludeZoneBCList
231 } 191 }
232 192
233 # transformation of negative values ------------------------------- 193 # transformation of negative values -------------------------------
234 # Inputs 194 # Inputs
235 NegativetoZero <- argLs[["NegativetoZero"]] 195 NegativetoZero <- argLs[["NegativetoZero"]]
236 196
237 197 # Outputs
238 # Outputs
239 nomGraphe <- argLs[["graphOut"]] 198 nomGraphe <- argLs[["graphOut"]]
240 # dataMatrixOut <- argLs[["dataMatrixOut"]]
241 log <- argLs[["logOut"]] 199 log <- argLs[["logOut"]]
242 200
243
244
245 ## Checking arguments 201 ## Checking arguments
246 ##------------------- 202 ## -------------------
247 error.stock <- "\n" 203 error.stock <- "\n"
248 204 if (length(error.stock) > 1) {
249 if(length(error.stock) > 1) 205 stop(error.stock)
250 stop(error.stock) 206 }
251 207
252 208 ## ======================================================
253 ##======================================================
254 ##======================================================
255 ## Computation 209 ## Computation
256 ##====================================================== 210 ## ======================================================
257 ##======================================================
258
259 pdf(nomGraphe, onefile = TRUE, width = 13, height = 13) 211 pdf(nomGraphe, onefile = TRUE, width = 13, height = 13)
260 212
261 # FirstOrderPhaseCorrection --------------------------------- 213 # FirstOrderPhaseCorrection ---------------------------------
262 Fid_data <- GroupDelayCorrection(Fid_data0, Fid_info = samplemetadataFid, group_delay = NULL) 214 Fid_data <- GroupDelayCorrection(Fid_data0, Fid_info = samplemetadataFid, group_delay = NULL)
263 215
264 if (FirstOPCGraph == "YES") { 216 if (FirstOPCGraph == "YES") {
265 title = "FIDs after Group Delay Correction" 217 title <- "FIDs after Group Delay Correction"
266 DrawSignal(Fid_data, subtype = "stacked", 218 DrawSignal(Fid_data,
267 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 219 subtype = "stacked",
268 xlab = "Frequency", num.stacked = 4, 220 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
269 main = title, createWindow=FALSE) 221 xlab = "Frequency", num.stacked = 4,
222 main = title, createWindow = FALSE
223 )
270 } 224 }
271 225
272 # SolventSuppression --------------------------------- 226 # SolventSuppression ---------------------------------
273 Fid_data <- SolventSuppression(Fid_data, lambda.ss = lambda, ptw.ss = TRUE, plotSolvent = F, returnSolvent = F) 227 Fid_data <- SolventSuppression(Fid_data, lambda.ss = lambda, ptw.ss = TRUE, plotSolvent = F, returnSolvent = F)
274 228
275 if (SSGraph == "YES") { 229 if (SSGraph == "YES") {
276 title = "FIDs after Solvent Suppression " 230 title <- "FIDs after Solvent Suppression "
277 DrawSignal(Fid_data, subtype = "stacked", 231 DrawSignal(Fid_data,
278 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 232 subtype = "stacked",
279 xlab = "Frequency", num.stacked = 4, 233 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
280 main = title, createWindow=FALSE) 234 xlab = "Frequency", num.stacked = 4,
281 } 235 main = title, createWindow = FALSE
282 236 )
283 237 }
284 # Apodization --------------------------------- 238
285 Fid_data <- Apodization(Fid_data, Fid_info = samplemetadataFid, DT = NULL, 239
286 type.apod = apodization, phase = phase, rectRatio = rectRatio, gaussLB = gaussLB, expLB = expLB, plotWindow = F, returnFactor = F) 240 # Apodization ---------------------------------
241 Fid_data <- Apodization(Fid_data,
242 Fid_info = samplemetadataFid, DT = NULL,
243 type.apod = apodization, phase = phase, rectRatio = rectRatio, gaussLB = gaussLB, expLB = expLB, plotWindow = F, returnFactor = F
244 )
287 245
288 if (ApodGraph == "YES") { 246 if (ApodGraph == "YES") {
289 title = "FIDs after Apodization" 247 title <- "FIDs after Apodization"
290 DrawSignal(Fid_data, subtype = "stacked", 248 DrawSignal(Fid_data,
291 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 249 subtype = "stacked",
292 xlab = "Frequency", num.stacked = 4, 250 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
293 main = title, createWindow=FALSE) 251 xlab = "Frequency", num.stacked = 4,
252 main = title, createWindow = FALSE
253 )
294 } 254 }
295 255
296 256
297 # FourierTransform --------------------------------- 257 # FourierTransform ---------------------------------
298 Spectrum_data <- FourierTransform(Fid_data, Fid_info = samplemetadataFid, reverse.axis = TRUE) 258 Spectrum_data <- FourierTransform(Fid_data, Fid_info = samplemetadataFid, reverse.axis = TRUE)
299 259
300 260
301 if (FTGraph == "YES") { 261 if (FTGraph == "YES") {
302 title = "Fourier transformed spectra" 262 title <- "Fourier transformed spectra"
303 DrawSignal(Spectrum_data, subtype = "stacked", 263 DrawSignal(Spectrum_data,
304 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 264 subtype = "stacked",
305 xlab = "Frequency", num.stacked = 4, 265 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
306 main = title, createWindow=FALSE) 266 xlab = "Frequency", num.stacked = 4,
307 } 267 main = title, createWindow = FALSE
308 268 )
309 269 }
270
271
272 # if (FTGraph == "YES") {
273 # title = "Fourier transformed spectra"
274 # DrawSignal(Spectrum_data, subtype = "stacked",
275 # ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
276 # xlab = "Frequency", num.stacked = 4,
277 # main = title, createWindow=FALSE)
278 # }
310 279
311 # ZeroOrderPhaseCorrection --------------------------------- 280 # ZeroOrderPhaseCorrection ---------------------------------
312 Spectrum_data <- ZeroOrderPhaseCorrection(Spectrum_data, type.zopc = zeroOrderPhaseMethod, 281 Spectrum_data <- ZeroOrderPhaseCorrection(Spectrum_data,
313 plot_rms = NULL, returnAngle = FALSE, 282 type.zopc = zeroOrderPhaseMethod,
314 createWindow = TRUE,angle = angle, 283 plot_rms = NULL, returnAngle = FALSE,
315 plot_spectra = FALSE, 284 createWindow = TRUE, angle = angle,
316 ppm.zopc = TRUE, exclude.zopc = excludeZOPC) 285 plot_spectra = FALSE,
286 ppm.zopc = TRUE, exclude.zopc = excludeZOPC
287 )
317 288
318 289
319 # InternalReferencing --------------------------------- 290 # InternalReferencing ---------------------------------
320 # if (shiftReferencing=="YES") { 291 # if (shiftReferencing=="YES") {
321 Spectrum_data <- InternalReferencing(Spectrum_data, samplemetadataFid, method = "max", range = shiftReferencingRange, 292 Spectrum_data <- InternalReferencing(Spectrum_data, samplemetadataFid,
322 ppm.value = ppmvalue, shiftHandling = shiftHandling, ppm.ir = TRUE, 293 method = "max", range = shiftReferencingRange,
323 fromto.RC = shiftReferencingRangeList, pc = pctNearValue) 294 ppm.value = ppmvalue, shiftHandling = shiftHandling, ppm.ir = TRUE,
295 fromto.RC = shiftReferencingRangeList, pc = pctNearValue
296 )
324 297
325 if (SRGraph == "YES") { 298 if (SRGraph == "YES") {
326 title = "Spectra after Shift Referencing" 299 title <- "Spectra after Shift Referencing"
327 DrawSignal(Spectrum_data, subtype = "stacked", 300 DrawSignal(Spectrum_data,
328 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 301 subtype = "stacked",
329 xlab = "Frequency", num.stacked = 4, 302 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
330 main = title, createWindow=FALSE) 303 xlab = "Frequency", num.stacked = 4,
304 main = title, createWindow = FALSE
305 )
331 } 306 }
332 307
333 # } 308 # }
334 309
335 if (ZeroOPCGraph == "YES") { 310 if (ZeroOPCGraph == "YES") {
336 title = "Spectra after Zero Order Phase Correction" 311 title <- "Spectra after Zero Order Phase Correction"
337 DrawSignal(Spectrum_data, subtype = "stacked", 312 DrawSignal(Spectrum_data,
338 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 313 subtype = "stacked",
339 xlab = "Frequency", num.stacked = 4, 314 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
340 main = title, createWindow=FALSE) 315 xlab = "Frequency", num.stacked = 4,
341 } 316 main = title, createWindow = FALSE
342 317 )
343 318 }
344 # BaselineCorrection --------------------------------- 319
345 Spectrum_data <- BaselineCorrection(Spectrum_data, ptw.bc = TRUE, lambda.bc = lambdaBc, 320
346 p.bc = pBc, eps = epsilon, ppm.bc = TRUE, 321 # BaselineCorrection ---------------------------------
347 exclude.bc = excludeBC, 322 Spectrum_data <- BaselineCorrection(Spectrum_data,
348 returnBaseline = F) 323 ptw.bc = TRUE, lambda.bc = lambdaBc,
324 p.bc = pBc, eps = epsilon, ppm.bc = TRUE,
325 exclude.bc = excludeBC,
326 returnBaseline = F
327 )
349 328
350 329
351 330
352 if (BCGraph == "YES") { 331 if (BCGraph == "YES") {
353 title = "Spectra after Baseline Correction" 332 title <- "Spectra after Baseline Correction"
354 DrawSignal(Spectrum_data, subtype = "stacked", 333 DrawSignal(Spectrum_data,
355 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 334 subtype = "stacked",
356 xlab = "Frequency", num.stacked = 4, 335 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
357 main = title, createWindow=FALSE) 336 xlab = "Frequency", num.stacked = 4,
358 } 337 main = title, createWindow = FALSE
359 338 )
339 }
340
341 # if (BCGraph == "YES") {
342 # title = "Spectra after Baseline Correction"
343 # DrawSignal(Spectrum_data, subtype = "stacked",
344 # ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
345 # xlab = "Frequency", num.stacked = 4,
346 # main = title, createWindow=FALSE)
347 # }
360 348
361 # NegativeValuesZeroing --------------------------------- 349 # NegativeValuesZeroing ---------------------------------
362 if (NegativetoZero=="YES") { 350 if (NegativetoZero == "YES") {
363 Spectrum_data <- NegativeValuesZeroing(Spectrum_data) 351 Spectrum_data <- NegativeValuesZeroing(Spectrum_data)
364 } 352 }
365 353 print(Spectrum_data[1:5, 1:5])
366 if (FinalGraph == "YES") { 354 if (FinalGraph == "YES") {
367 title = "Final preprocessed spectra" 355 title <- "Final preprocessed spectra"
368 DrawSignal(Spectrum_data, subtype = "stacked", 356 DrawSignal(Spectrum_data,
369 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, 357 subtype = "stacked",
370 xlab = "Frequency", num.stacked = 4, 358 ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
371 main = title, createWindow=FALSE) 359 xlab = "Frequency", num.stacked = 4,
372 } 360 main = title, createWindow = FALSE
373 361 )
362 }
374 invisible(dev.off()) 363 invisible(dev.off())
375 364
376 365 # data_variable <- matrix(NA, nrow = 1, ncol = dim(Spectrum_data)[2], dimnames = list("ID", NULL))
377 data_variable <- matrix(NA, nrow = 1, ncol = dim(Spectrum_data)[2], dimnames = list("ID", NULL)) 366 # colnames(data_variable) <- colnames(Spectrum_data)
367 # data_variable[1,] <- colnames(data_variable)
368
369 data_variable <- matrix(NA, nrow = 1, ncol = dim(Spectrum_data)[2], dimnames = list("ID", NULL))
378 colnames(data_variable) <- colnames(Spectrum_data) 370 colnames(data_variable) <- colnames(Spectrum_data)
379 data_variable[1,] <- colnames(data_variable) 371 data_variable[1, ] <- colnames(data_variable)
380 372
381 373
382 ##====================================================== 374 ## ======================================================
383 ##====================================================== 375 ## ======================================================
384 ## Saving 376 ## Saving
385 ##====================================================== 377 ## ======================================================
386 ##====================================================== 378 ## ======================================================
387 379
388 # Data Matrix 380 # Data Matrix
389 write.table(round(t(Re(Spectrum_data)),6), file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) 381 write.table(round(t(Re(Spectrum_data)), 6), file = argLs[["dataMatrix"]], quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE)
390 382
391 # Variable metadata 383 # Variable metadata
392 write.table(data_variable,file=argLs$variableMetadata, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE) 384 write.table(data_variable, file = argLs[["variableMetadata"]], quote = FALSE, row.names = TRUE, sep = "\t", col.names = TRUE)
393
394 # log file
395 # write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE)
396 385
397 # input arguments 386 # input arguments
398 cat("\n INPUT and OUTPUT ARGUMENTS :\n") 387 cat("\n INPUT and OUTPUT ARGUMENTS :\n")
399
400 argLs 388 argLs
401 389
402
403 ## Ending 390 ## Ending
404 391 cat("\nVersion of R librairies")
392 print(sessionInfo())
405 cat("\nEnd of 'Preprocessing' Galaxy module call: ", as.character(Sys.time()), sep = "") 393 cat("\nEnd of 'Preprocessing' Galaxy module call: ", as.character(Sys.time()), sep = "")
406 394
407 sink()
408
409 options(stringsAsFactors = strAsFacL)
410
411 rm(list = ls()) 395 rm(list = ls())