diff xcms_xcmsSet.r @ 32:b02d1992a43a draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
author workflow4metabolomics
date Wed, 07 Apr 2021 16:47:14 +0000
parents eb15a3841da4
children f5d51091cf84
line wrap: on
line diff
--- a/xcms_xcmsSet.r	Tue Apr 28 09:35:10 2020 -0400
+++ b/xcms_xcmsSet.r	Wed Apr 07 16:47:14 2021 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/env Rscript
 
 # ----- LOG FILE -----
-log_file <- file("log.txt", open="wt")
+log_file <- file("log.txt", open = "wt")
 sink(log_file)
 sink(log_file, type = "output")
 
@@ -10,10 +10,12 @@
 cat("\tSESSION INFO\n")
 
 #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="/")) }
+source_local <- function(fname) {
+  argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/"))
+}
 source_local("lib.r")
 
-pkgs <- c("xcms","batch")
+pkgs <- c("xcms", "batch")
 loadAndDisplayPackages(pkgs)
 cat("\n\n");
 
@@ -21,7 +23,7 @@
 # ----- ARGUMENTS -----
 cat("\tARGUMENTS INFO\n")
 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
-write.table(as.matrix(args), col.names=F, quote=F, sep='\t')
+write.table(as.matrix(args), col.names = F, quote = F, sep = "\t")
 
 cat("\n\n")
 
@@ -31,7 +33,7 @@
 
 #saving the commun parameters
 BPPARAM <- MulticoreParam(1)
-if (!is.null(args$BPPARAM)){
+if (!is.null(args$BPPARAM)) {
     BPPARAM <- MulticoreParam(args$BPPARAM)
 }
 register(BPPARAM)
@@ -44,7 +46,7 @@
 
 method <- args$method
 
-if (!is.null(args$roiList)){
+if (!is.null(args$roiList)) {
     cat("\t\troiList provided\n")
     args$roiList <- list(getDataFrameFromFile(args$roiList))
     print(args$roiList)
@@ -60,7 +62,7 @@
 if (!exists("raw_data")) stop("\n\nERROR: The RData doesn't contain any object called 'raw_data' which is provided by the tool: MSnbase readMSData")
 
 # Handle infiles
-rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args)
+rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)
 zipfile <- rawFilePath$zipfile
 singlefile <- rawFilePath$singlefile
 
@@ -79,34 +81,30 @@
 if (exists("filterRtParam")) raw_data <- filterRt(raw_data, filterRtParam)
 if (exists("filterMzParam")) raw_data <- filterMz(raw_data, filterMzParam)
 #Apply this filter only if file contain MS and MSn
-if(length(unique(msLevel(raw_data)))!= 1){
-	raw_data <- filterMsLevel(raw_data,msLevel=1)
+if (length(unique(msLevel(raw_data))) != 1) {
+  raw_data <- filterMsLevel(raw_data, msLevel = 1)
 }
 
 cat("\t\t\tChromatographic peak detection\n")
 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ...
-args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))]
+args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))]
 
-findChromPeaksParam <- do.call(paste0(method,"Param"), args)
+findChromPeaksParam <- do.call(paste0(method, "Param"), args)
 print(findChromPeaksParam)
-xdata <- findChromPeaks(raw_data, param=findChromPeaksParam)
+xdata <- findChromPeaks(raw_data, param = findChromPeaksParam)
 
 # Check if there are no peaks
 if (nrow(chromPeaks(xdata)) == 0) stop("No peaks were detected. You should review your settings")
 
 # Create a sampleMetada file
-sampleNamesList <- getSampleMetadata(xdata=xdata, sampleMetadataOutput="sampleMetadata.tsv")
-
-#cat("\t\t\tCompute and Store TIC and BPI\n")
-#chromTIC = chromatogram(xdata, aggregationFun = "sum")
-#chromBPI = chromatogram(xdata, aggregationFun = "max")
+sampleNamesList <- getSampleMetadata(xdata = xdata, sampleMetadataOutput = "sampleMetadata.tsv")
 
 # Create a chromPeaks table if required
 if (exists("peaklistParam")) {
-    if(peaklistParam){
-      cat("\nCreating the chromatographic peaks' table...\n")
-      write.table(chromPeaks(xdata), file="chromPeak_table.tsv",sep="\t",quote=F,row.names=F)
-	}
+  if (peaklistParam) {
+    cat("\nCreating the chromatographic peaks' table...\n")
+    write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = F, row.names = F)
+  }
 }
 
 cat("\n\n")
@@ -124,8 +122,8 @@
 cat("\n\n")
 
 #saving R data in .Rdata file to save the variables used in the present tool
-objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") #, "chromTIC", "chromBPI")
-save(list=objects2save[objects2save %in% ls()], file="xcmsSet.RData")
+objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList")
+save(list = objects2save[objects2save %in% ls()], file = "xcmsSet.RData")
 
 
 cat("\tDONE\n")