Repository 'xcms_plot_chromatogram'
hg clone https://toolshed.g2.bx.psu.edu/repos/lecorguille/xcms_plot_chromatogram

Changeset 16:9291271ec4d9 (2025-02-03)
Previous changeset 15:c8bef8f6a1cb (2024-07-15)
Commit message:
planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics/ commit 95721ced8347c09e79340e6d67ecb41c5cc64163
modified:
lib.r
macros_xcms.xml
xcms_plot_chromatogram.r
xcms_plot_chromatogram.xml
b
diff -r c8bef8f6a1cb -r 9291271ec4d9 lib.r
--- a/lib.r Mon Jul 15 16:00:15 2024 +0000
+++ b/lib.r Mon Feb 03 14:46:19 2025 +0000
[
b'@@ -1,461 +1,470 @@\n-#@authors ABiMS TEAM, Y. Guitton\n+# @authors ABiMS TEAM, Y. Guitton\n # lib.r for Galaxy Workflow4Metabolomics xcms tools\n \n-#@author G. Le Corguille\n+# @author G. Le Corguille\n # solve an issue with batch if arguments are logical TRUE/FALSE\n parseCommandArgs <- function(...) {\n-  args <- batch::parseCommandArgs(...)\n-  for (key in names(args)) {\n-    if (args[key] %in% c("TRUE", "FALSE"))\n-      args[key] <- as.logical(args[key])\n-  }\n-  return(args)\n+    args <- batch::parseCommandArgs(...)\n+    for (key in names(args)) {\n+        if (args[key] %in% c("TRUE", "FALSE")) {\n+            args[key] <- as.logical(args[key])\n+        }\n+    }\n+    return(args)\n }\n \n-#@author G. Le Corguille\n+# @author G. Le Corguille\n # This function will\n # - load the packages\n # - display the sessionInfo\n loadAndDisplayPackages <- function(pkgs) {\n-  for (pkg in pkgs) suppressPackageStartupMessages(stopifnot(library(pkg, quietly = TRUE, logical.return = TRUE, character.only = TRUE)))\n+    for (pkg in pkgs) suppressPackageStartupMessages(stopifnot(library(pkg, quietly = TRUE, logical.return = TRUE, character.only = TRUE)))\n \n-  sessioninfo <- sessionInfo()\n-  cat(sessioninfo$R.version$version.string, "\\n")\n-  cat("Main packages:\\n")\n-  for (pkg in names(sessioninfo$otherPkgs)) {\n-    cat(paste(pkg, packageVersion(pkg)), "\\t")\n-  }\n-  cat("\\n")\n-  cat("Other loaded packages:\\n")\n-  for (pkg in names(sessioninfo$loadedOnly)) {\n-    cat(paste(pkg, packageVersion(pkg)), "\\t")\n-  }\n-  cat("\\n")\n+    sessioninfo <- sessionInfo()\n+    cat(sessioninfo$R.version$version.string, "\\n")\n+    cat("Main packages:\\n")\n+    for (pkg in names(sessioninfo$otherPkgs)) {\n+        cat(paste(pkg, packageVersion(pkg)), "\\t")\n+    }\n+    cat("\\n")\n+    cat("Other loaded packages:\\n")\n+    for (pkg in names(sessioninfo$loadedOnly)) {\n+        cat(paste(pkg, packageVersion(pkg)), "\\t")\n+    }\n+    cat("\\n")\n }\n \n-#@author G. Le Corguille\n+# @author G. Le Corguille\n # This function merge several chromBPI or chromTIC into one.\n mergeChrom <- function(chrom_merged, chrom) {\n-  if (is.null(chrom_merged)) return(NULL)\n-  chrom_merged@.Data <- cbind(chrom_merged@.Data, chrom@.Data)\n-  return(chrom_merged)\n+    if (is.null(chrom_merged)) {\n+        return(NULL)\n+    }\n+    chrom_merged@.Data <- cbind(chrom_merged@.Data, chrom@.Data)\n+    return(chrom_merged)\n }\n \n-#@author G. Le Corguille\n+# @author G. Le Corguille\n # This function merge several xdata into one.\n mergeXData <- function(args) {\n-  chromTIC <- NULL\n-  chromBPI <- NULL\n-  chromTIC_adjusted <- NULL\n-  chromBPI_adjusted <- NULL\n-  md5sumList <- NULL\n-  for (image in args$images) {\n+    chromTIC <- NULL\n+    chromBPI <- NULL\n+    chromTIC_adjusted <- NULL\n+    chromBPI_adjusted <- NULL\n+    md5sumList <- NULL\n+    for (image in args$images) {\n+        load(image)\n+        # Handle infiles\n+        if (!exists("singlefile")) singlefile <- NULL\n+        if (!exists("zipfile")) zipfile <- NULL\n+        rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)\n+        zipfile <- rawFilePath$zipfile\n+        singlefile <- rawFilePath$singlefile\n \n-    load(image)\n-    # Handle infiles\n-    if (!exists("singlefile")) singlefile <- NULL\n-    if (!exists("zipfile")) zipfile <- NULL\n-    rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)\n-    zipfile <- rawFilePath$zipfile\n-    singlefile <- rawFilePath$singlefile\n+        if (exists("raw_data")) xdata <- raw_data\n+        if (!exists("xdata")) stop("\\n\\nERROR: The RData doesn\'t contain any object called \'xdata\'. This RData should have been created by an old version of XMCS 2.*")\n \n-    if (exists("raw_data")) xdata <- raw_data\n-    if (!exists("xdata")) stop("\\n\\nERROR: The RData doesn\'t contain any object called \'xdata\'. This RData should have been created by an old version of XMCS 2.*")\n-\n-    cat(sampleNamesList$sampleNamesOrigin, "\\n")\n+        cat(sampleNamesList$sampleNamesOrigin, "\\n")\n \n-    if (!exists("xdata_m'..b'ngs(try(file.link(singlefile_galaxyPath, singlefile_sampleName), silent = TRUE))) {\n+                file.copy(singlefile_galaxyPath, singlefile_sampleName)\n+            }\n+            files <- c(files, singlefile_sampleName)\n+        }\n     }\n-  }\n-  # zipfile\n-  if (!is.null(zipfile) && (zipfile != "")) {\n-    if (!file.exists(zipfile)) {\n-      error_message <- paste("Cannot access the Zip file:", zipfile, ". Please, contact your administrator ... if you have one!")\n-      print(error_message)\n-      stop(error_message)\n-    }\n-    suppressWarnings(unzip(zipfile, unzip = "unzip"))\n+    # zipfile\n+    if (!is.null(zipfile) && (zipfile != "")) {\n+        if (!file.exists(zipfile)) {\n+            error_message <- paste("Cannot access the Zip file:", zipfile, ". Please, contact your administrator ... if you have one!")\n+            print(error_message)\n+            stop(error_message)\n+        }\n+        suppressWarnings(unzip(zipfile, unzip = "unzip"))\n \n-    #get the directory name\n-    suppressWarnings(filesInZip <- unzip(zipfile, list = TRUE))\n-    directories <- unique(unlist(lapply(strsplit(filesInZip$Name, "/"), function(x) x[1])))\n-    directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]\n-    directory <- "."\n-    if (length(directories) == 1) directory <- directories\n+        # get the directory name\n+        suppressWarnings(filesInZip <- unzip(zipfile, list = TRUE))\n+        directories <- unique(unlist(lapply(strsplit(filesInZip$Name, "/"), function(x) x[1])))\n+        directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]\n+        directory <- "."\n+        if (length(directories) == 1) directory <- directories\n \n-    cat("files_root_directory\\t", directory, "\\n")\n+        cat("files_root_directory\\t", directory, "\\n")\n \n-    filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]", "[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]")\n-    filepattern <- paste(paste("\\\\.", filepattern, "$", sep = ""), collapse = "|")\n-    info <- file.info(directory)\n-    listed <- list.files(directory[info$isdir], pattern = filepattern, recursive = TRUE, full.names = TRUE)\n-    files <- c(directory[!info$isdir], listed)\n-    exists <- file.exists(files)\n-    files <- files[exists]\n-\n-  }\n-  return(list(zipfile = zipfile, singlefile = singlefile, files = files))\n+        filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]", "[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]")\n+        filepattern <- paste(paste("\\\\.", filepattern, "$", sep = ""), collapse = "|")\n+        info <- file.info(directory)\n+        listed <- list.files(directory[info$isdir], pattern = filepattern, recursive = TRUE, full.names = TRUE)\n+        files <- c(directory[!info$isdir], listed)\n+        exists <- file.exists(files)\n+        files <- files[exists]\n+    }\n+    return(list(zipfile = zipfile, singlefile = singlefile, files = files))\n }\n \n \n # This function retrieve a xset like object\n-#@author Gildas Le Corguille lecorguille@sb-roscoff.fr\n+# @author Gildas Le Corguille lecorguille@sb-roscoff.fr\n getxcmsSetObject <- function(xobject) {\n-  # XCMS 1.x\n-  if (class(xobject) == "xcmsSet")\n-    return(xobject)\n-  # XCMS 3.x\n-  if (class(xobject) == "XCMSnExp") {\n-    # Get the legacy xcmsSet object\n-    suppressWarnings(xset <- as(xobject, "xcmsSet"))\n-    if (!is.null(xset@phenoData$sample_group))\n-      sampclass(xset) <- xset@phenoData$sample_group\n-    else\n-      sampclass(xset) <- "."\n-    return(xset)\n-  }\n+    # XCMS 1.x\n+    if (class(xobject) == "xcmsSet") {\n+        return(xobject)\n+    }\n+    # XCMS 3.x\n+    if (class(xobject) == "XCMSnExp") {\n+        # Get the legacy xcmsSet object\n+        suppressWarnings(xset <- as(xobject, "xcmsSet"))\n+        if (!is.null(xset@phenoData$sample_group)) {\n+            sampclass(xset) <- xset@phenoData$sample_group\n+        } else {\n+            sampclass(xset) <- "."\n+        }\n+        return(xset)\n+    }\n }\n'
b
diff -r c8bef8f6a1cb -r 9291271ec4d9 macros_xcms.xml
--- a/macros_xcms.xml Mon Jul 15 16:00:15 2024 +0000
+++ b/macros_xcms.xml Mon Feb 03 14:46:19 2025 +0000
b
@@ -2,7 +2,7 @@
 <macros>
 
     <token name="@TOOL_VERSION@">3.12.0</token>
-    <token name="@VERSION_SUFFIX@">1</token>
+    <token name="@VERSION_SUFFIX@">3</token>
     <token name="@PROFILE@">21.09</token>
     <xml name="requirements">
         <requirements>
b
diff -r c8bef8f6a1cb -r 9291271ec4d9 xcms_plot_chromatogram.r
--- a/xcms_plot_chromatogram.r Mon Jul 15 16:00:15 2024 +0000
+++ b/xcms_plot_chromatogram.r Mon Feb 03 14:46:19 2025 +0000
[
@@ -4,11 +4,11 @@
 # ----- PACKAGE -----
 cat("\tSESSION INFO\n")
 
-#Import the different functions
+# Import the different functions
 source_local <- function(fname) {
-  argv <- commandArgs(trailingOnly = FALSE)
-  base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
-  source(paste(base_dir, fname, sep = "/"))
+    argv <- commandArgs(trailingOnly = FALSE)
+    base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
+    source(paste(base_dir, fname, sep = "/"))
 }
 source_local("lib.r")
 
@@ -19,7 +19,7 @@
 
 # ----- ARGUMENTS -----
 cat("\tARGUMENTS INFO\n")
-args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
+args <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects
 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t")
 
 cat("\n\n")
@@ -54,12 +54,12 @@
 
 register(SerialParam())
 if (!exists("chromTIC") || is.null(chromTIC)) {
-  cat("\t\t\tCompute TIC\n")
-  chromTIC <- chromatogram(xdata, aggregationFun = "sum")
+    cat("\t\t\tCompute TIC\n")
+    chromTIC <- chromatogram(xdata, aggregationFun = "sum")
 }
 if (!exists("chromBPI") || is.null(chromBPI)) {
-  cat("\t\t\tCompute BPI\n")
-  chromBPI <- chromatogram(xdata, aggregationFun = "max")
+    cat("\t\t\tCompute BPI\n")
+    chromBPI <- chromatogram(xdata, aggregationFun = "max")
 }
 
 if (!is.null(chromTIC_adjusted)) chromTIC <- chromTIC_adjusted
b
diff -r c8bef8f6a1cb -r 9291271ec4d9 xcms_plot_chromatogram.xml
--- a/xcms_plot_chromatogram.xml Mon Jul 15 16:00:15 2024 +0000
+++ b/xcms_plot_chromatogram.xml Mon Feb 03 14:46:19 2025 +0000
[
@@ -6,10 +6,14 @@
         <import>macros_xcms.xml</import>
     </macros>
     <expand macro="requirements"/>
+    <required_files>
+        <include path="xcms_plot_chromatogram.r" />
+        <include path="lib.r" />
+    </required_files>
     <expand macro="stdio"/>
 
     <command><![CDATA[
-        @COMMAND_RSCRIPT@//xcms_plot_chromatogram.r
+        @COMMAND_RSCRIPT@xcms_plot_chromatogram.r
 
         images 'c("${"\",\"".join(map(str, $images))}")'