comparison metaMS_runGC.r @ 7:89af36e05548 draft

planemo upload for repository https://github.com/workflow4metabolomics/metaMS commit eb45457830f9d220bcb845acf71bffb50038a4c7
author workflow4metabolomics
date Thu, 07 May 2020 06:24:39 -0400
parents 286ebb9f6e84
children d1ce2634135f
comparison
equal deleted inserted replaced
6:286ebb9f6e84 7:89af36e05548
18 source_local <- function(fname) { 18 source_local <- function(fname) {
19 argv <- commandArgs(trailingOnly = FALSE) 19 argv <- commandArgs(trailingOnly = FALSE)
20 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) 20 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
21 source(paste(base_dir, fname, sep="/")) 21 source(paste(base_dir, fname, sep="/"))
22 } 22 }
23 source_local("lib_metams.r")
23 24
24 pkgs <- c("metaMS","stringr","batch","CAMERA") #"batch" necessary for parseCommandArgs function 25 pkgs <- c("metaMS","stringr","batch","CAMERA") #"batch" necessary for parseCommandArgs function
25 loadAndDisplayPackages(pkgs) 26 loadAndDisplayPackages(pkgs)
26 27
27
28 cat("\n\n") 28 cat("\n\n")
29 29
30 modNamC <- "metaMS:runGC" ## module name 30 modNamC <- "metaMS:runGC" ## module name
31 cat("\nStart of the '", modNamC, "' Galaxy module call: ", format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="") 31 cat("\nStart of the '", modNamC, "' Galaxy module call: ", format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="")
32
32 33
33 # ----- PROCESSING INFILE ----- 34 # ----- PROCESSING INFILE -----
34 cat("\n\n\tARGUMENTS PROCESSING INFO\n\n") 35 cat("\n\n\tARGUMENTS PROCESSING INFO\n\n")
35 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects 36 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
36 #write.table(as.matrix(args), col.names=F, quote=F, sep='\t\t') 37 #write.table(as.matrix(args), col.names=F, quote=F, sep='\t\t')
96 nSlaves=args$nSlaves 97 nSlaves=args$nSlaves
97 } 98 }
98 99
99 if (args$settings=="User_defined") { 100 if (args$settings=="User_defined") {
100 cat("Using user's parameters\n") 101 cat("Using user's parameters\n")
101 fwhmparam=args$fwhm
102 rtdiffparam=args$rtdiff 102 rtdiffparam=args$rtdiff
103 minfeatparam=args$minfeat 103 minfeatparam=args$minfeat
104 simthreshparam=args$simthreshold 104 simthreshparam=args$simthreshold
105 minclassfractionparam=args$minclassfraction 105 minclassfractionparam=args$minclassfraction
106 minclasssizeparam=args$minclasssize 106 minclasssizeparam=args$minclasssize
191 cat("\t\tCOMPUTE\n\n") 191 cat("\t\tCOMPUTE\n\n")
192 192
193 #runGC accept either a list of files a zip folder or an xset object from xcms.xcmsSet tool 193 #runGC accept either a list of files a zip folder or an xset object from xcms.xcmsSet tool
194 #From xset is an .RData file necessary to use the xcmsSet object generated by xcms.xcmsSet given by previous tools 194 #From xset is an .RData file necessary to use the xcmsSet object generated by xcms.xcmsSet given by previous tools
195 if (!is.null(args$singlefile_galaxyPath)){ 195 if (!is.null(args$singlefile_galaxyPath)){
196 cat("Loading datas from XCMS file(s)...\n") 196 cat("Loading datas from XCMS files...\n")
197 load(args$singlefile_galaxyPath) 197 load(args$singlefile_galaxyPath)
198 198
199 #Transform XCMS object if needed 199 #Transform XCMS object if needed
200 if(!exists("xset")) { 200 if(!exists("xset")) {
201 if(exists("xdata")) { 201 if(exists("xdata")) {
203 } else { 203 } else {
204 error_message="no xset and no xdata... Probably a problem" 204 error_message="no xset and no xdata... Probably a problem"
205 print(error_message) 205 print(error_message)
206 stop(error_message) 206 stop(error_message)
207 } 207 }
208 }
209 #Verify that there are more than 1 file (can't run metaMS on only 1 file)
210 if(length(rownames(xdata@phenoData)) < 2){
211 error_message="You need more than 1 file to be able to run metaMS"
212 print(error_message)
213 stop(error_message)
208 } 214 }
209 215
210 #xset from xcms.xcmsSet is not well formatted for metaMS this function do the formatting 216 #xset from xcms.xcmsSet is not well formatted for metaMS this function do the formatting
211 if (class(xset)=="xcmsSet"){ 217 if (class(xset)=="xcmsSet"){
212 if (length(xset@rt$raw)>1){ 218 if (length(xset@rt$raw)>1){
250 xsetCAM <- xset.l 256 xsetCAM <- xset.l
251 } 257 }
252 258
253 #default settings for GC from Wehrens et al 259 #default settings for GC from Wehrens et al
254 cat("Process runGC with metaMS package...\n\n") 260 cat("Process runGC with metaMS package...\n\n")
255 print(str(TSQXLS.GC)) 261 print(str(TSQXLS.GC))
256 resGC<-runGC(xset=xsetCAM,settings=TSQXLS.GC, rtrange=rtrange, DB= DBgc, removeArtefacts = TRUE, 262 resGC<-runGC(xset=xsetCAM,settings=TSQXLS.GC, rtrange=rtrange, DB= DBgc, removeArtefacts = TRUE,
257 findUnknowns = TRUE, returnXset = TRUE, RIstandards = RIarg, nSlaves = nSlaves) 263 findUnknowns = TRUE, returnXset = TRUE, RIstandards = RIarg, nSlaves = nSlaves)
258 } else { 264 } else {
259 if(args$settings == "User_defined") { 265 if(args$settings == "User_defined") {
260 settingslist=GALAXY.GC 266 settingslist=GALAXY.GC
299 #peakTable for PCA 305 #peakTable for PCA
300 #dataMatrix 306 #dataMatrix
301 cat("\nGenerating dataMatrix file") 307 cat("\nGenerating dataMatrix file")
302 dataMatrix<-cbind(Name=peaktable[,"Name"],peaktable[,(colnames(peaktable) %in% sampleMetadata[,1])]) 308 dataMatrix<-cbind(Name=peaktable[,"Name"],peaktable[,(colnames(peaktable) %in% sampleMetadata[,1])])
303 rownames(dataMatrix)<-NULL 309 rownames(dataMatrix)<-NULL
304 print(dataMatrix)
305 cat("\t.\t.") 310 cat("\t.\t.")
306 write.table(dataMatrix, file="dataMatrix.tsv", sep="\t", row.names=FALSE, quote=FALSE) 311 write.table(dataMatrix, file="dataMatrix.tsv", sep="\t", row.names=FALSE, quote=FALSE)
307 cat("\t.\tOK") 312 cat("\t.\tOK")
308 313
309 #variableMetadata 314 #variableMetadata
310 cat("\nGenerating variableMetadata file") 315 cat("\nGenerating variableMetadata file")
311 print(colnames(peaktable))
312 variableMetadata<-peaktable[,!(colnames(peaktable) %in% sampleMetadata[,1])] 316 variableMetadata<-peaktable[,!(colnames(peaktable) %in% sampleMetadata[,1])]
313 rownames(variableMetadata)<-NULL 317 rownames(variableMetadata)<-NULL
314 cat("\t.") 318 cat("\t.")
315 write.table(variableMetadata, file="variableMetadata.tsv", sep="\t", row.names=FALSE, quote=FALSE) 319 write.table(variableMetadata, file="variableMetadata.tsv", sep="\t", row.names=FALSE, quote=FALSE)
316 cat("\t.\tOK") 320 cat("\t.\tOK")
321 write.table(sampleMetadata, file="sampleMetadata.tsv", sep="\t", row.names=FALSE, quote=FALSE) 325 write.table(sampleMetadata, file="sampleMetadata.tsv", sep="\t", row.names=FALSE, quote=FALSE)
322 cat("\t.\tOK") 326 cat("\t.\tOK")
323 327
324 #peak spectrum as MSP for DB search 328 #peak spectrum as MSP for DB search
325 cat("\nGenerating",length(resGC$PseudoSpectra),"peakspectra in peakspectra.msp file\n") 329 cat("\nGenerating",length(resGC$PseudoSpectra),"peakspectra in peakspectra.msp file\n")
326 if(is.null(resGC$PseudoSpectra)){ 330 write.msp(resGC$PseudoSpectra, file="peakspectra.msp", newFile = TRUE)
327 write("No results", file="peakspectra.msp")
328 }else{
329 write.msp(resGC$PseudoSpectra, file="peakspectra.msp", newFile = TRUE)
330 }
331 331
332 #saving R data in .Rdata file to save the variables used in the present tool 332 #saving R data in .Rdata file to save the variables used in the present tool
333 objects2save <- c("resGC", "xset", "singlefile", "zipfile", "DBgc") 333 objects2save <- c("resGC", "xset", "singlefile", "zipfile", "DBgc")
334 save(list = objects2save[objects2save %in% ls()], file = "runGC.RData") 334 save(list = objects2save[objects2save %in% ls()], file = "runGC.RData")
335 335
336 cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "") 336 cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "")
337
338 #WARNING if user has CDF files (not yet good for plotting)
339 files <- paste("./",names(singlefile),sep="")
340 if(MSnbase:::isCdfFile(files)){
341 warning_message <- "You have CDF files, for the moment you can't obtain plot after runGC! A new update will follow with the good correction"
342 warning(warning_message)
343 cat(paste("\n","/!\\Warning/!\\",warning_message,sep="\n"))
344 }