changeset 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
files metaMS_runGC.r
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/metaMS_runGC.r	Thu May 07 03:10:33 2020 -0400
+++ b/metaMS_runGC.r	Thu May 07 06:24:39 2020 -0400
@@ -20,16 +20,17 @@
     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
@@ -98,7 +99,6 @@
 
 if (args$settings=="User_defined") {
     cat("Using user's parameters\n")
-    fwhmparam=args$fwhm
     rtdiffparam=args$rtdiff
     minfeatparam=args$minfeat
     simthreshparam=args$simthreshold
@@ -193,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 file(s)...\n")
+    cat("Loading datas from XCMS files...\n")
     load(args$singlefile_galaxyPath)
     
     #Transform XCMS object if needed
@@ -206,6 +206,12 @@
             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"){
@@ -252,7 +258,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 {
@@ -301,14 +307,12 @@
 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.")
@@ -323,14 +327,18 @@
 
 #peak spectrum as MSP for DB search
 cat("\nGenerating",length(resGC$PseudoSpectra),"peakspectra in peakspectra.msp file\n")
-if(is.null(resGC$PseudoSpectra)){
-    write("No results", file="peakspectra.msp")
-}else{
-    write.msp(resGC$PseudoSpectra, file="peakspectra.msp", newFile = TRUE)
-}
+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 = "")
\ No newline at end of file
+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"))
+}