diff metaMS_runGC.r @ 6:286ebb9f6e84 draft

planemo upload for repository https://github.com/workflow4metabolomics/metaMS commit eb45457830f9d220bcb845acf71bffb50038a4c7-dirty
author workflow4metabolomics
date Thu, 07 May 2020 03:10:33 -0400
parents b8d4129dd2a6
children 89af36e05548
line wrap: on
line diff
--- a/metaMS_runGC.r	Fri Sep 06 06:09:10 2019 -0400
+++ b/metaMS_runGC.r	Thu May 07 03:10:33 2020 -0400
@@ -20,17 +20,16 @@
     base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
     source(paste(base_dir, fname, sep="/"))
 }
-source_local("lib_metams.r")
 
 pkgs <- c("metaMS","stringr","batch","CAMERA") #"batch" necessary for parseCommandArgs function
 loadAndDisplayPackages(pkgs)
 
+
 cat("\n\n")
 
 modNamC <- "metaMS:runGC" ## module name
 cat("\nStart of the '", modNamC, "' Galaxy module call: ", format(Sys.time(), "%a %d %b %Y %X"), "\n", sep="")
 
-
 # ----- PROCESSING INFILE -----
 cat("\n\n\tARGUMENTS PROCESSING INFO\n\n")
 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
@@ -194,7 +193,7 @@
 #runGC accept either a list of files a zip folder or an xset object from xcms.xcmsSet tool
 #From xset is an .RData file necessary to use the xcmsSet object generated by xcms.xcmsSet given by previous tools
 if (!is.null(args$singlefile_galaxyPath)){
-    cat("Loading datas from XCMS files...\n")
+    cat("Loading datas from XCMS file(s)...\n")
     load(args$singlefile_galaxyPath)
     
     #Transform XCMS object if needed
@@ -207,12 +206,6 @@
             stop(error_message)
         }
     }
-    #Verify that there are more than 1 file (can't run metaMS on only 1 file)
-    if(length(rownames(xdata@phenoData)) < 2){
-        error_message="You need more than 1 file to be able to run metaMS"
-        print(error_message)
-        stop(error_message)
-    }
 
     #xset from xcms.xcmsSet is not well formatted for metaMS this function do the formatting
     if (class(xset)=="xcmsSet"){
@@ -259,7 +252,7 @@
         
         #default settings for GC from Wehrens et al
         cat("Process runGC with metaMS package...\n\n")
-        print(str(TSQXLS.GC))
+        print(str(TSQXLS.GC))  
         resGC<-runGC(xset=xsetCAM,settings=TSQXLS.GC, rtrange=rtrange, DB= DBgc, removeArtefacts = TRUE, 
                     findUnknowns = TRUE, returnXset = TRUE, RIstandards = RIarg, nSlaves = nSlaves)
     } else {
@@ -308,12 +301,14 @@
 cat("\nGenerating dataMatrix file")
 dataMatrix<-cbind(Name=peaktable[,"Name"],peaktable[,(colnames(peaktable) %in% sampleMetadata[,1])])
 rownames(dataMatrix)<-NULL
+print(dataMatrix)
 cat("\t.\t.")
 write.table(dataMatrix, file="dataMatrix.tsv", sep="\t", row.names=FALSE, quote=FALSE)
 cat("\t.\tOK")
 
 #variableMetadata
 cat("\nGenerating variableMetadata file")
+print(colnames(peaktable))
 variableMetadata<-peaktable[,!(colnames(peaktable) %in% sampleMetadata[,1])]
 rownames(variableMetadata)<-NULL
 cat("\t.")
@@ -328,18 +323,14 @@
 
 #peak spectrum as MSP for DB search
 cat("\nGenerating",length(resGC$PseudoSpectra),"peakspectra in peakspectra.msp file\n")
-write.msp(resGC$PseudoSpectra, file="peakspectra.msp", newFile = TRUE)
+if(is.null(resGC$PseudoSpectra)){
+    write("No results", file="peakspectra.msp")
+}else{
+    write.msp(resGC$PseudoSpectra, file="peakspectra.msp", newFile = TRUE)
+}
 
 #saving R data in .Rdata file to save the variables used in the present tool
 objects2save <- c("resGC", "xset", "singlefile", "zipfile", "DBgc")
 save(list = objects2save[objects2save %in% ls()], file = "runGC.RData")
 
-cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "")
-
-#WARNING if user has CDF files (not yet good for plotting)
-files <- paste("./",names(singlefile),sep="")
-if(MSnbase:::isCdfFile(files)){
-    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"
-    warning(warning_message)
-    cat(paste("\n","/!\\Warning/!\\",warning_message,sep="\n"))
-}
\ No newline at end of file
+cat("\nEnd of '", modNamC, "' Galaxy module call: ", as.character(Sys.time()), "\n", sep = "")
\ No newline at end of file