Mercurial > repos > eschen42 > xcms_refine
comparison xcms_refine.r @ 0:ae9ef9219aae draft default tip
"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
author | eschen42 |
---|---|
date | Fri, 12 Feb 2021 18:05:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ae9ef9219aae |
---|---|
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 | |
16 pkgs <- c("xcms","batch","RColorBrewer") | |
17 loadAndDisplayPackages(pkgs) | |
18 cat("\n\n"); | |
19 | |
20 # ----- EXPLORE NAMESPACE ----- | |
21 # cat("\tXCMS NAMESPACE INFO\n") | |
22 # ls(asNamespace("xcms")) | |
23 | |
24 # ----- ARGUMENTS ----- | |
25 cat("\tARGUMENTS INFO\n") | |
26 args <- parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
27 write.table(as.matrix(args), col.names=F, quote=F, sep='\t') | |
28 | |
29 cat("\n\n") | |
30 | |
31 # ----- PROCESSING INFILE ----- | |
32 cat("\tARGUMENTS PROCESSING INFO\n") | |
33 | |
34 #saving the specific parameters | |
35 args_method <- args$method | |
36 args_image <- args$image | |
37 args_msLevel <- args$msLevel | |
38 #args[c('method','image','msLevel')] <- NULL | |
39 param_args <- list() | |
40 | |
41 if ( args_method == "CleanPeaks" ) { | |
42 param_args$maxPeakwidth <- as.numeric(args$maxPeakwidth) | |
43 if (is.na(as.numeric(param_args$maxPeakwidth))) stop("\n\nERROR: The maxPeakwidth argument cannot be coerced to a numeric value.") | |
44 } else if ( args_method == "FilterIntensity" ) { | |
45 param_args$threshold <- as.numeric(args$threshold) | |
46 if (is.na(as.numeric(param_args$threshold))) stop("\n\nERROR: The threshold argument cannot be coerced to a numeric value.") | |
47 param_args$nValues <- as.numeric(args$nValues) | |
48 if (is.na(as.numeric(param_args$nValues))) stop("\n\nERROR: The nValues argument cannot be coerced to a numeric value.") | |
49 if (as.integer(param_args$nValues) != param_args$nValues) stop("\n\nERROR: The nValues argument is not an integer value.") | |
50 param_args$value <- args$value | |
51 } else if ( args_method == "MergeNeighboringPeaks" ) { | |
52 if (is.na(as.numeric(args$expandRt))) stop("\n\nERROR: The expandRt argument cannot be coerced to a numeric value.") | |
53 if (is.na(as.numeric(args$expandMz))) stop("\n\nERROR: The expandMz argument cannot be coerced to a numeric value.") | |
54 if (is.na(as.numeric(args$ppm))) stop("\n\nERROR: The ppm argument cannot be coerced to a numeric value.") | |
55 if (is.na(as.numeric(args$minProp))) stop("\n\nERROR: The minProp argument cannot be coerced to a numeric value.") | |
56 param_args$expandRt <- args$expandRt | |
57 param_args$expandMz <- args$expandMz | |
58 param_args$ppm <- args$ppm | |
59 param_args$minProp <- args$minProp | |
60 } | |
61 | |
62 cat("\n\n") | |
63 | |
64 | |
65 # ----- ARGUMENTS PROCESSING ----- | |
66 cat("\tINFILE PROCESSING INFO\n") | |
67 | |
68 #image is an .RData file necessary to use xset variable given by previous tools | |
69 load(args_image) | |
70 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.*") | |
71 | |
72 # Handle infiles | |
73 if (!exists("singlefile")) singlefile <- NULL | |
74 if (!exists("zipfile")) zipfile <- NULL | |
75 rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args) | |
76 zipfile <- rawFilePath$zipfile | |
77 singlefile <- rawFilePath$singlefile | |
78 | |
79 cat("\n\n") | |
80 | |
81 | |
82 # ----- MAIN PROCESSING INFO ----- | |
83 cat("\tMAIN PROCESSING INFO\n") | |
84 | |
85 | |
86 cat("\t\tPREPARE PARAMETERS\n\n") | |
87 | |
88 if ( args_method == "CleanPeaks" ) { | |
89 refineChromPeaksParam <- CleanPeaksParam(maxPeakwidth = param_args$maxPeakwidth) | |
90 } else if ( args_method == "FilterIntensity" ) { | |
91 refineChromPeaksParam <- FilterIntensityParam( | |
92 threshold = param_args$threshold, | |
93 nValues = param_args$nValues, | |
94 value = param_args$value | |
95 ) | |
96 } else if ( args_method == "MergeNeighboringPeaks" ) { | |
97 refineChromPeaksParam <- MergeNeighboringPeaksParam( | |
98 expandRt = param_args$expandRt, | |
99 expandMz = param_args$expandMz, | |
100 ppm = param_args$ppm, | |
101 minProp = param_args$minProp | |
102 ) | |
103 } | |
104 | |
105 cat(str(refineChromPeaksParam)) | |
106 | |
107 cat("\n\n\t\tCOMPUTE\n") | |
108 | |
109 # cat("\t\t\tACE DEBUG show the xdata\n") | |
110 # cat(str(xdata)) | |
111 # cat("\n\t\t\tACE DEBUG (end show the xdata)\n") | |
112 | |
113 # cat("\t\t\tACE DEBUG show updateObject(xdata)\n") | |
114 xdata <- updateObject(xdata) | |
115 # cat(str(xdata)) | |
116 # cat("\n\t\t\tACE DEBUG (end show updateObject(xdata))\n") | |
117 # | |
118 # cat("\t\t\tACE DEBUG show the param_args\n") | |
119 # cat(str(param_args)) | |
120 # cat("\n\t\t\tACE DEBUG (end show the param_args)\n") | |
121 # | |
122 # cat("\t\t\tACE DEBUG show the refineChromPeaksParam\n") | |
123 # cat(str(refineChromPeaksParam)) | |
124 # cat("\n\t\t\tACE DEBUG (end show the refineChromPeaksParam)\n") | |
125 # | |
126 # cat("\t\t\tACE DEBUG show the slotNames\n") | |
127 # cat(str(slotNames(refineChromPeaksParam))) | |
128 # cat("\n\t\t\tACE DEBUG (end show the slotNames)\n") | |
129 | |
130 # # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or args_method ... | |
131 # param_args <- param_args[names(param_args) %in% slotNames(do.call(paste0(args_method,"Param"), param_args))] | |
132 # | |
133 # refineChromPeaksParam <- do.call(paste0(args_method,"Param"), param_args) | |
134 # print(refineChromPeaksParam) | |
135 | |
136 # cat("\t\t\tACE DEBUG invoke refineChromPeaks\n") | |
137 xdata <- refineChromPeaks(xdata, param = refineChromPeaksParam) | |
138 # cat("\t\t\tACE DEBUG returned from refineChromPeaks\n") | |
139 # | |
140 # | |
141 # cat("\t\tDRAW GRAPHICS\n") | |
142 # getPlotChromPeakDensity(xdata, param = groupChromPeaksParam) | |
143 # | |
144 # if (exists("intval")) { | |
145 # getPeaklistW4M(xdata, intval, convertRTMinute, numDigitsMZ, numDigitsRT, naTOzero, "variableMetadata.tsv", "dataMatrix.tsv") | |
146 # } | |
147 # | |
148 cat("\n\n") | |
149 | |
150 # ----- EXPORT ----- | |
151 | |
152 cat("\tXCMSnExp OBJECT INFO\n") | |
153 print(xdata) | |
154 cat("\n\n") | |
155 | |
156 cat("\txcmsSet OBJECT INFO\n") | |
157 # Get the legacy xcmsSet object | |
158 xset <- getxcmsSetObject(xdata) | |
159 print(xset) | |
160 cat("\n\n") | |
161 | |
162 #saving R data in .Rdata file to save the variables used in the present tool | |
163 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") | |
164 save(list=objects2save[objects2save %in% ls()], file="xcmsSet.RData") | |
165 | |
166 cat("\n\n") | |
167 | |
168 | |
169 cat("\tDONE\n") |