comparison xcms_refine.r @ 26:36480435e92b draft

planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics/ commit 2cb157bd9a8701a3d6874e084032cbd050b8953e
author workflow4metabolomics
date Mon, 11 Sep 2023 09:21:15 +0000
parents
children
comparison
equal deleted inserted replaced
25:aa252eec9229 26:36480435e92b
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) {
14 argv <- commandArgs(trailingOnly = FALSE)
15 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
16 source(paste(base_dir, fname, sep = "/"))
17 }
18 source_local("lib.r")
19
20 pkgs <- c("xcms", "batch", "RColorBrewer")
21 loadAndDisplayPackages(pkgs)
22 cat("\n\n")
23
24 # ----- ARGUMENTS -----
25 cat("\tARGUMENTS INFO\n")
26 # interpretation of arguments given in command line as an R list of objects
27 args <- parseCommandArgs(evaluate = FALSE)
28 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t")
29
30 cat("\n\n")
31
32 # ----- PROCESSING INFILE -----
33 cat("\tARGUMENTS PROCESSING INFO\n")
34
35 #saving the specific parameters
36 args_method <- args$method
37 args_image <- args$image
38 args_msLevel <- args$msLevel
39 param_args <- list()
40
41 if (args_method == "CleanPeaks") {
42 param_args$maxPeakwidth <- args$maxPeakwidth
43 } else if (args_method == "FilterIntensity") {
44 param_args$threshold <- args$threshold
45 param_args$value <- args$value
46 param_args$nValues <- args$nValues
47 } else if (args_method == "MergeNeighboringPeaks") {
48 param_args$expandRt <- args$expandRt
49 param_args$expandMz <- args$expandMz
50 param_args$ppm <- args$ppm
51 param_args$minProp <- args$minProp
52 }
53
54 cat("\n\n")
55
56
57 # ----- ARGUMENTS PROCESSING -----
58 cat("\tINFILE PROCESSING INFO\n")
59
60 #image is an .RData file necessary to use xset variable given by previous tools
61 load(args_image)
62 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. Such RData as this might have been created by an old version of XMCS 2.*")
63
64 # Handle infiles
65 if (!exists("singlefile")) singlefile <- NULL
66 if (!exists("zipfile")) zipfile <- NULL
67 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args)
68 zipfile <- rawFilePath$zipfile
69 singlefile <- rawFilePath$singlefile
70
71 cat("\n\n")
72
73
74 # ----- MAIN PROCESSING INFO -----
75 cat("\tMAIN PROCESSING INFO\n")
76
77
78 cat("\t\tPREPARE PARAMETERS\n\n")
79
80 if (args_method == "CleanPeaks") {
81 refineChromPeaksParam <- CleanPeaksParam(maxPeakwidth = param_args$maxPeakwidth)
82 } else if (args_method == "FilterIntensity") {
83 refineChromPeaksParam <- FilterIntensityParam(
84 threshold = param_args$threshold,
85 nValues = param_args$nValues,
86 value = param_args$value
87 )
88 } else if (args_method == "MergeNeighboringPeaks") {
89 refineChromPeaksParam <- MergeNeighboringPeaksParam(
90 expandRt = param_args$expandRt,
91 expandMz = param_args$expandMz,
92 ppm = param_args$ppm,
93 minProp = param_args$minProp
94 )
95 }
96
97 cat(str(refineChromPeaksParam))
98
99 cat("\n\n\t\tCOMPUTE\n")
100
101 xdata <- updateObject(xdata)
102
103 xdata <- refineChromPeaks(xdata, param = refineChromPeaksParam)
104
105 cat("\n\n")
106
107 # ----- EXPORT -----
108
109 cat("\tXCMSnExp OBJECT INFO\n")
110 print(xdata)
111 cat("\n\n")
112
113 cat("\txcmsSet OBJECT INFO\n")
114 # Get the legacy xcmsSet object
115 xset <- getxcmsSetObject(xdata)
116 print(xset)
117 cat("\n\n")
118
119 #saving R data in .Rdata file to save the variables used in the present tool
120 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList")
121 save(list = objects2save[objects2save %in% ls()], file = "xcmsSet.RData")
122
123 cat("\n\n")
124
125
126 cat("\tDONE\n")