comparison xcms_fillpeaks.r @ 13:91c71f3808f3 draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
author lecorguille
date Tue, 18 Sep 2018 16:13:36 -0400
parents
children 27fbe73c4279
comparison
equal deleted inserted replaced
12:dcb9041cb9ea 13:91c71f3808f3
1 #!/usr/bin/env Rscript
2
3 # ----- LOG FILE -----
4 log_file=file("log.txt", open = "wt")
5 sink(log_file)
6 sink(log_file, type = "output")
7
8
9 # ----- PACKAGE -----
10 cat("\tSESSION INFO\n")
11
12 #Import the different functions
13 source_local <- function(fname){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) }
14 source_local("lib.r")
15 source_local("lib-xcms3.x.x.r")
16
17 pkgs <- c("xcms","batch")
18 loadAndDisplayPackages(pkgs)
19 cat("\n\n");
20
21
22 # ----- ARGUMENTS -----
23 cat("\tARGUMENTS INFO\n")
24 args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
25 write.table(as.matrix(args), col.names=F, quote=F, sep='\t')
26
27 cat("\n\n")
28
29 # ----- PROCESSING INFILE -----
30 cat("\tARGUMENTS PROCESSING INFO\n")
31
32 #saving the specific parameters
33 method <- "FillChromPeaks"
34
35 if (!is.null(args$convertRTMinute)) convertRTMinute <- args$convertRTMinute
36 if (!is.null(args$numDigitsMZ)) numDigitsMZ <- args$numDigitsMZ
37 if (!is.null(args$numDigitsRT)) numDigitsRT <- args$numDigitsRT
38 if (!is.null(args$intval)) intval <- args$intval
39 if (!is.null(args$naTOzero)) naTOzero <- args$naTOzero
40
41 cat("\n\n")
42
43
44 # ----- ARGUMENTS PROCESSING -----
45 cat("\tINFILE PROCESSING INFO\n")
46
47 #image is an .RData file necessary to use xset variable given by previous tools
48 load(args$image)
49 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.*")
50
51 #Verification of a group step before doing the fillpeaks job.
52 if (!hasFeatures(xdata)) stop("You must always do a group step after a retcor. Otherwise it won't work for the fillpeaks step")
53
54 # Handle infiles
55 if (!exists("singlefile")) singlefile <- NULL
56 if (!exists("zipfile")) zipfile <- NULL
57 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args)
58 zipfile <- rawFilePath$zipfile
59 singlefile <- rawFilePath$singlefile
60 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
61
62 # Check some character issues
63 md5sumList <- list("origin" = getMd5sum(directory))
64 checkXmlStructure(directory)
65 checkFilesCompatibilityWithXcms(directory)
66
67
68 cat("\n\n")
69
70
71 # ----- MAIN PROCESSING INFO -----
72 cat("\tMAIN PROCESSING INFO\n")
73
74
75 cat("\t\tCOMPUTE\n")
76
77 cat("\t\t\tFilling missing peaks using default settings\n")
78 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ...
79 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))]
80
81 fillChromPeaksParam <- do.call(paste0(method,"Param"), args)
82 print(fillChromPeaksParam)
83 xdata <- fillChromPeaks(xdata, param=fillChromPeaksParam)
84
85 if (exists("intval")) {
86 getPeaklistW4M(xdata, intval, convertRTMinute, numDigitsMZ, numDigitsRT, naTOzero, "variableMetadata.tsv", "dataMatrix.tsv")
87 }
88
89 cat("\n\n")
90
91 # ----- EXPORT -----
92
93 cat("\tXCMSnExp OBJECT INFO\n")
94 print(xdata)
95 cat("\n\n")
96
97 cat("\txcmsSet OBJECT INFO\n")
98 # Get the legacy xcmsSet object
99 xset <- getxcmsSetObject(xdata)
100 print(xset)
101 cat("\n\n")
102
103 #saving R data in .Rdata file to save the variables used in the present tool
104 objects2save = c("xdata","zipfile","singlefile","md5sumList","sampleNamesList", "chromTIC", "chromBPI", "chromTIC_adjusted", "chromBPI_adjusted")
105 save(list=objects2save[objects2save %in% ls()], file="fillpeaks.RData")
106
107 cat("\n\n")
108
109
110 cat("\tDONE\n")