diff msnbase_readmsdata.r @ 14:11ab2081bd4a draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dff3ac53c7c305ff263e6358308db48cf9ed4e27"
author workflow4metabolomics
date Mon, 12 Apr 2021 09:35:02 +0000
parents 226fb89cacc4
children 7faf9b2d83f6
line wrap: on
line diff
--- a/msnbase_readmsdata.r	Wed Feb 12 08:27:38 2020 -0500
+++ b/msnbase_readmsdata.r	Mon Apr 12 09:35:02 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("MSnbase","batch")
+pkgs <- c("MSnbase", "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")
 
@@ -38,7 +40,7 @@
 # Handle infiles
 if (!exists("singlefile")) singlefile <- NULL
 if (!exists("zipfile")) zipfile <- NULL
-rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args)
+rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)
 zipfile <- rawFilePath$zipfile
 singlefile <- rawFilePath$singlefile
 files <- rawFilePath$files
@@ -55,23 +57,19 @@
 cat("\t\tCOMPUTE\n")
 
 cat("\t\t\tCreate a phenodata data.frame\n")
-s_groups <- sapply(files, function(x) tail(unlist(strsplit(dirname(x),"/")), n=1))
+s_groups <- sapply(files, function(x) tail(unlist(strsplit(dirname(x), "/")), n = 1))
 s_name <- tools::file_path_sans_ext(basename(files))
-pd <- data.frame(sample_name=s_name, sample_group=s_groups, stringsAsFactors=FALSE)
+pd <- data.frame(sample_name = s_name, sample_group = s_groups, stringsAsFactors = FALSE)
 print(pd)
 
 cat("\t\t\tLoad Raw Data\n")
-raw_data <- readMSData(files=files, pdata = new("NAnnotatedDataFrame", pd), mode="onDisk")
+raw_data <- readMSData(files = files, pdata = new("NAnnotatedDataFrame", pd), mode = "onDisk")
 
 # Transform the files absolute pathways into relative pathways
-raw_data@processingData@files <- sub(paste(getwd(), "/", sep="") , "", raw_data@processingData@files)
+raw_data@processingData@files <- sub(paste(getwd(), "/", sep = ""), "", raw_data@processingData@files)
 
 # Create a sampleMetada file
-sampleNamesList <- getSampleMetadata(xdata=raw_data, sampleMetadataOutput="sampleMetadata.tsv")
-
-#cat("\t\t\tCompute and Store TIC and BPI\n")
-#chromTIC <- chromatogram(raw_data, aggregationFun = "sum")
-#chromBPI <- chromatogram(raw_data, aggregationFun = "max")
+sampleNamesList <- getSampleMetadata(xdata = raw_data, sampleMetadataOutput = "sampleMetadata.tsv")
 
 cat("\n\n")
 
@@ -85,7 +83,7 @@
 
 #saving R data in .Rdata file to save the variables used in the present tool
 objects2save <- c("raw_data", "zipfile", "singlefile", "md5sumList", "sampleNamesList") #, "chromTIC", "chromBPI")
-save(list=objects2save[objects2save %in% ls()], file="readmsdata.RData")
+save(list = objects2save[objects2save %in% ls()], file = "readmsdata.RData")
 
 
 cat("\tDONE\n")