view xcms_plot_chromatogram.r @ 6:0290cd6b3354 draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit d481a27556155e3587901d702d364b71f28e30b9
author lecorguille
date Thu, 07 Mar 2019 07:37:23 -0500
parents 7c0cc7a3c3db
children 271c9d5f0d10
line wrap: on
line source

#!/usr/bin/env Rscript


# ----- PACKAGE -----
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("lib.r")

pkgs <- c("xcms","batch","RColorBrewer")
loadAndDisplayPackages(pkgs)
cat("\n\n");


# ----- 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')

cat("\n\n")

# ----- PROCESSING INFILE -----
cat("\tARGUMENTS PROCESSING INFO\n")

cat("\n\n")


# ----- ARGUMENTS PROCESSING -----
cat("\tINFILE PROCESSING INFO\n")

mergeXDataReturn <- mergeXData(args)
xdata <- mergeXDataReturn$xdata
singlefile <- mergeXDataReturn$singlefile
md5sumList <- mergeXDataReturn$md5sumList
sampleNamesList <- mergeXDataReturn$sampleNamesList
chromTIC <- mergeXDataReturn$chromTIC
chromBPI <- mergeXDataReturn$chromBPI
chromTIC_adjusted <- mergeXDataReturn$chromTIC_adjusted
chromBPI_adjusted <- mergeXDataReturn$chromBPI_adjusted

cat("\n\n")


# ----- MAIN PROCESSING INFO -----
cat("\tMAIN PROCESSING INFO\n")


cat("\t\tDRAW GRAPHICS\n")

if (!is.null(chromTIC) || is.null(chromTIC)) { cat("\t\t\tCompute TIC\n"); chromTIC <- chromatogram(xdata, aggregationFun = "sum") }
if (!is.null(chromBPI) || is.null(chromBPI)) { cat("\t\t\tCompute BPI\n"); chromBPI <- chromatogram(xdata, aggregationFun = "max") }

if (!is.null(chromTIC_adjusted)) chromTIC <- chromTIC_adjusted
if (!is.null(chromBPI_adjusted)) chromBPI <- chromBPI_adjusted

getPlotChromatogram(chromTIC, xdata, pdfname="TICs.pdf", aggregationFun = "sum")
getPlotChromatogram(chromBPI, xdata, pdfname="BPIs.pdf", aggregationFun = "max")

cat("\n\n")

# ----- EXPORT -----

cat("\tXCMSnExp OBJECT INFO\n")
print(xdata)
cat("\n\n")

cat("\txcmsSet OBJECT INFO\n")
# Get the legacy xcmsSet object
xset <- getxcmsSetObject(xdata)
print(xset)
cat("\n\n")


cat("\tDONE\n")