changeset 36:e309e6af6744 draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 3922356e5edae763800a4311146e2fdeb52c296e
author lecorguille
date Fri, 31 Aug 2018 09:02:01 -0400
parents 2b0a4c7a4a48
children 35a20d7c9f33
files lib.r xcms_retcor.r
diffstat 2 files changed, 29 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/lib.r	Thu Apr 05 18:09:18 2018 -0400
+++ b/lib.r	Fri Aug 31 09:02:01 2018 -0400
@@ -391,38 +391,31 @@
 
 # This function get the raw file path from the arguments
 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr
-getRawfilePathFromArguments <- function(singlefile, zipfile, args) {
-    if (!is.null(args$zipfile))           zipfile <- args$zipfile
-    if (!is.null(args$zipfilePositive))   zipfile <- args$zipfilePositive
-    if (!is.null(args$zipfileNegative))   zipfile <- args$zipfileNegative
+getRawfilePathFromArguments <- function(singlefile, zipfile, args, prefix="") {
+  if (!(prefix %in% c("","Positive","Negative","MS1","MS2"))) stop("prefix must be either '', 'Positive', 'Negative', 'MS1' or 'MS2'")
+
+  if (!is.null(args[[paste0("zipfile",prefix)]])) zipfile <- args[[paste0("zipfile",prefix)]]
 
-    if (!is.null(args$singlefile_galaxyPath)) {
-        singlefile_galaxyPaths <- args$singlefile_galaxyPath;
-        singlefile_sampleNames <- args$singlefile_sampleName
-    }
-    if (!is.null(args$singlefile_galaxyPathPositive)) {
-        singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive;
-        singlefile_sampleNames <- args$singlefile_sampleNamePositive
+  if (!is.null(args[[paste0("singlefile_galaxyPath",prefix)]])) {
+    singlefile_galaxyPaths <- args[[paste0("singlefile_galaxyPath",prefix)]]
+    singlefile_sampleNames <- args[[paste0("singlefile_sampleName",prefix)]]
+  }
+  if (exists("singlefile_galaxyPaths")){
+    singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths,"\\|"))
+    singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames,"\\|"))
+
+    singlefile <- NULL
+    for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
+      singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i]
+      singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i]
+      # In case, an url is used to import data within Galaxy 
+      singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName,"/")), n=1)
+      singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath
     }
-    if (!is.null(args$singlefile_galaxyPathNegative)) {
-        singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative;
-        singlefile_sampleNames <- args$singlefile_sampleNameNegative
-    }
-    if (exists("singlefile_galaxyPaths")){
-        singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths,"\\|"))
-        singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames,"\\|"))
-
-        singlefile <- NULL
-        for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
-            singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i]
-            singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i]
-            singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath
-        }
-    }
-    return(list(zipfile=zipfile, singlefile=singlefile))
+  }
+  return(list(zipfile=zipfile, singlefile=singlefile))
 }
 
-
 # This function retrieve the raw file in the working directory
 #   - if zipfile: unzip the file with its directory tree
 #   - if singlefiles: set symlink with the good filename
@@ -480,7 +473,10 @@
     if (class(xobject) == "XCMSnExp") {
         # Get the legacy xcmsSet object
         suppressWarnings(xset <- as(xobject, 'xcmsSet'))
-        sampclass(xset) <- xset@phenoData$sample_group
+        if (!is.null(xset@phenoData$sample_group))
+            sampclass(xset) <- xset@phenoData$sample_group
+        else
+            sampclass(xset) <- "."
         return (xset)
     }
 }
--- a/xcms_retcor.r	Thu Apr 05 18:09:18 2018 -0400
+++ b/xcms_retcor.r	Fri Aug 31 09:02:01 2018 -0400
@@ -49,11 +49,6 @@
 singlefile <- rawFilePath$singlefile
 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
 
-cat("\t\t\tCompute and Store TIC and BPI\n")
-chromTIC_adjusted = chromatogram(xdata, aggregationFun = "sum")
-chromBPI_adjusted = chromatogram(xdata, aggregationFun = "max")
-
-
 cat("\n\n")
 
 
@@ -71,6 +66,10 @@
 print(adjustRtimeParam)
 xdata <- adjustRtime(xdata, param=adjustRtimeParam)
 
+cat("\t\t\tCompute and Store TIC and BPI\n")
+chromTIC_adjusted = chromatogram(xdata, aggregationFun = "sum")
+chromBPI_adjusted = chromatogram(xdata, aggregationFun = "max")
+
 cat("\n\n")