annotate MS2snoop.R @ 6:77abacd33c31 draft

planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
author workflow4metabolomics
date Fri, 30 Sep 2022 16:18:56 +0000
parents 78d5a12406c2
children 2a1f120a6874
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1 #' read and process mspurity W4M files
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
2 #' create a summary of fragment for each precursor and a graphics of peseudo
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
3 #' spectra + correlation on which checking of fragment is based on
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
4 #' V3 try to identify and process multiple files for 1 precursor which may
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
5 #' occur if different collision energy are used
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
6 #' V4 elimination of correlation = NA. Correlation is done with precursor, if
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
7 #' precursor is not present correlation with most intense peak
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
8 #' author: Jean-Francois Martin
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
9 #' V5 is versionned, lintR-compliant, packaged, unit-tested, documented and
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
10 #' tested against data from other labs.
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
11 #' new maintainer: Lain Pavot - lain.pavot@inrae.fr
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
12 #'
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
13 #' @import optparse
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
14 #'
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
15
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
16
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
17 get_version <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
18 cmd <- commandArgs(trailingOnly = FALSE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
19 root <- dirname(gsub("--file=", "", cmd[grep("--file=", cmd)]))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
20 readme <- readLines(file.path(root, "README.md"))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
21 version_line <- readme[grepl(" * **@version**: ", readme, fixed = TRUE)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
22 return(gsub(".*: ", "", version_line))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
23 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
24
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
25 defaults <- list(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
26 MS2SNOOP_VERSION = get_version(),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
27 MISSING_PARAMETER_ERROR = 1,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
28 BAD_PARAMETER_VALUE_ERROR = 2,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
29 MISSING_INPUT_FILE_ERROR = 3,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
30 NO_ANY_RESULT_ERROR = 255,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
31 DEFAULT_PRECURSOR_PATH = NULL,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
32 DEFAULT_FRAGMENTS_PATH = NULL,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
33 DEFAULT_COMPOUNDS_PATH = NULL,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
34 DEFAULT_OUTPUT_PATH = "compound_fragments_result.txt",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
35 DEFAULT_TOLMZ = 0.01,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
36 DEFAULT_TOLRT = 20,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
37 DEFAULT_MZDECIMAL = 3,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
38 DEFAULT_R_THRESHOLD = 0.85,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
39 DEFAULT_MINNUMBERSCAN = 8,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
40 DEFAULT_SEUIL_RA = 0.05,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
41 DEFAULT_FRAGMENTS_MATCH_DELTA = 10,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
42 DEFAULT_FRAGMENTS_MATCH_DELTA_UNIT = "ppm",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
43 DEFAULT_PDF_PATH = ""
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
44 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
45 env <- globalenv()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
46 for (default in names(defaults)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
47 assign(default, defaults[[default]], envir = env)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
48 lockBinding(default, env)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
49 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
50
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
51 ########################################################################
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
52
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
53 get_formulas <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
54 mzref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
55 spectra,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
56 processing_parameters,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
57 background = !TRUE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
58 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
59 if (is.vector(mzref) && length(mzref) > 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
60 return(lapply(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
61 mzref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
62 function(mz) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
63 return(get_formulas(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
64 mzref = mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
65 spectra = spectra,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
66 processing_parameters = processing_parameters,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
67 background = background
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
68 ))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
69 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
70 ))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
71 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
72 input <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
73 "%s-%s.ms",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
74 gsub("[[:space:]]", "_", processing_parameters$c_name),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
75 mzref
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
76 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
77 create_ms_file(input, mzref, spectra, processing_parameters)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
78 output <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
79 "out/%s-%s.out",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
80 gsub("[[:space:]]", "_", processing_parameters$c_name),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
81 mzref
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
82 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
83 command <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
84 paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
85 "sirius",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
86 "--noCite",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
87 "--noSummaries",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
88 "--loglevel=WARNING",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
89 "-i='%s'",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
90 "-o='%s'",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
91 "tree",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
92 ## loglevel is not working taken into account during
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
93 ## sirius startup, so we filter outputs...
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
94 "2>&1 | grep '^(WARNING|SEVERE)'"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
95 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
96 input,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
97 output
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
98 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
99 verbose_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
100 ">> Sirius is running %swith the command: %s\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
101 if (background) "in the background " else "",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
102 command
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
103 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
104 system(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
105 command,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
106 wait = !background,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
107 ignore.stdout = background,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
108 ignore.stderr = background
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
109 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
110 return(extract_sirius_results(output, spectra$mz, processing_parameters))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
111 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
112
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
113 create_ms_file <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
114 path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
115 mzref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
116 spectra,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
117 processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
118 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
119 file_content <- paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
120 sprintf(">compound %s", processing_parameters$c_name),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
121 sprintf(">ionization %s", processing_parameters$ionization),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
122 sprintf(">parentmass %s", mzref),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
123 sprintf(">formula %s", processing_parameters$elemcomposition),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
124 sep = "\n"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
125 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
126 displayed_file_content <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
127 "%s\n>collision\n%s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
128 file_content,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
129 paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
130 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
131 "%s %s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
132 spectra[1:3, "mz"],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
133 spectra[1:3, "intensities"]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
134 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
135 collapse = "\n"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
136 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
137 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
138 if (nrow(spectra) > 3) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
139 displayed_file_content <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
140 "%s\n[... %s more rows of mz and intensities ...]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
141 displayed_file_content,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
142 nrow(spectra) - 3
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
143 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
144 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
145 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
146 ">> MS file created for %s with content:\n%s\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
147 processing_parameters$c_name,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
148 displayed_file_content
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
149 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
150 file_content <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
151 "%s\n\n>collision\n%s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
152 file_content,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
153 paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
154 paste(spectra$mz, spectra$intensities),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
155 collapse = "\n"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
156 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
157 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
158 cat(file_content, file = path, append = FALSE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
159 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
160
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
161 extract_sirius_results <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
162 output,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
163 mz_list,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
164 processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
165 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
166
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
167 delta <- processing_parameters$fragment_match_delta
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
168 delta_unit <- tolower(processing_parameters$fragment_match_delta_unit)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
169
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
170 output <- list.dirs(output, recursive = FALSE)[[1]]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
171
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
172 spectra_out_dir <- sprintf("%s/spectra", output)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
173 spectra_filename <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
174 "%s/%s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
175 spectra_out_dir,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
176 list.files(spectra_out_dir)[[1]]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
177 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
178
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
179 trees_out_dir <- sprintf("%s/trees", output)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
180 trees_filename <- sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
181 "%s/%s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
182 trees_out_dir,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
183 list.files(trees_out_dir)[[1]]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
184 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
185
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
186 if (!is.null(spectra_filename)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
187 sirius_results <- get_csv_or_tsv(spectra_filename)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
188 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
189 return(rep(NA, length(mz_list)))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
190 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
191 if (!is.null(trees_filename)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
192 sirius_results <- cbind(sirius_results, extract_sirius_ppm(trees_filename))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
193 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
194 return(rep(NA, length(mz_list)))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
195 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
196
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
197 fragment_matchings <- data.frame(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
198 formula = NA,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
199 ppm = NA,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
200 mz = mz_list,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
201 error = NA
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
202 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
203
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
204 sirius_results <- filter_sirius_with_delta(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
205 sirius_results = sirius_results,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
206 original_mz = fragment_matchings$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
207 delta = delta,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
208 delta_unit = delta_unit
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
209 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
210
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
211 for (index in seq_len(nrow(sirius_results))) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
212 result <- sirius_results[index, ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
213 filter <- which(order(abs(fragment_matchings$mz - result$mz)) == 1)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
214 fragment_matchings[filter, "formula"] <- result$formula
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
215 fragment_matchings[filter, "ppm"] <- result$ppm
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
216 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
217 "[OK] Fragment with m/z=%s matches %s with a difference of %s ppm\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
218 fragment_matchings[filter, "mz"], result$formula, result$ppm
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
219 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
220 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
221 return(fragment_matchings)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
222 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
223
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
224 filter_sirius_with_delta <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
225 sirius_results,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
226 original_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
227 delta,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
228 delta_unit
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
229 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
230 if (is.numeric(delta) && !is.na(delta) && delta > 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
231 if (delta_unit == "ppm") {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
232 filter <- abs(sirius_results$ppm) <= delta
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
233 fine <- which(filter)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
234 not_fine <- which(!filter)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
235 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
236 paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
237 "[KO] fragment %s (m/z=%s) eleminated because ppm=%s is greater",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
238 "than delta=%s\n"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
239 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
240 sirius_results[not_fine, ]$formula,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
241 sirius_results[not_fine, ]$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
242 sirius_results[not_fine, ]$ppm,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
243 delta
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
244 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
245 sirius_results <- sirius_results[fine, ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
246 } else if (delta_unit == "mz") {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
247 differences <- sapply(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
248 sirius_results$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
249 function(mz) min(abs(original_mz - mz))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
250 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
251 fine <- which(sapply(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
252 sirius_results$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
253 function(mz) any(abs(original_mz - mz) <= delta)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
254 ))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
255 not_fine <- which(sapply(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
256 sirius_results$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
257 function(mz) all(abs(original_mz - mz) > delta)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
258 ))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
259 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
260 paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
261 "[KO] fragment %s eleminated because mz difference=%s is",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
262 "greater than delta=%s\n"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
263 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
264 sirius_results[not_fine, ]$formula,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
265 differences[not_fine],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
266 delta
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
267 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
268 sirius_results <- sirius_results[fine, ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
269 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
270 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
271 return(sirius_results)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
272 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
273
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
274 extract_sirius_ppm <- function(path) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
275 json <- file(path, "r")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
276 suppressWarnings(json_lines <- readLines(json))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
277 close(json)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
278 json_lines <- json_lines[
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
279 grepl("\\s+\"(massDeviation|recalibratedMass)\" :", json_lines)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
280 ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
281 json_lines <- gsub("^\\s+\"[^\"]+\" : \"?", "", json_lines)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
282 ppms <- json_lines[seq(1, length(json_lines), 2)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
283 mz <- json_lines[seq(2, length(json_lines), 2)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
284 ppms <- as.numeric(gsub(" ppm .*", "", ppms))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
285 mz <- as.numeric(gsub(",$", "", mz))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
286 ordered <- order(mz)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
287 return(list(ppm = ppms[ordered], recalibrated_mz = mz[ordered]))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
288 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
289
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
290 #' @title plot_pseudo_spectra
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
291 #' @param x
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
292 #' @param fid
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
293 #' @param sum_int
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
294 #' @param vmz
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
295 #' @param cor_abs_int
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
296 #' @param refcol
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
297 #' @param c_name
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
298 #' @description plot_pseudo_spectra
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
299 #' function to compute sum of intensities among scans for all
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
300 #' m/z kept (cor > r_threshold & minimum number of scans)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
301 #' and plot pseudo spectra
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
302 #' x dataframe scan X fragments with scans number in the 1st column and
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
303 #' ions in next with intensities
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
304 #' fid file id when several a precursor has been detected in several files
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
305 plot_pseudo_spectra <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
306 x,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
307 fid,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
308 sum_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
309 vmz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
310 cor_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
311 refcol,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
312 meaned_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
313 processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
314 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
315 ## du fait de la difference de nombre de colonne entre la dataframe qui
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
316 ## inclue les scans en 1ere col, mzRef se decale de 1
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
317 refcol <- refcol - 1
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
318 ## compute relative intensities max=100%
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
319 rel_int <- sum_int[-1]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
320 rel_int <- rel_int / max(rel_int)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
321
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
322 if (processing_parameters$do_pdf) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
323 ## define max value on vertical axis (need to increase in order to plot the
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
324 ## label of fragments)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
325 ymax <- max(rel_int) + 0.2 * max(rel_int)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
326
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
327 par(mfrow = c(2, 1))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
328 plot(vmz, rel_int, type = "h", ylim = c(0, ymax),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
329 main = processing_parameters$c_name
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
330 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
331 ## low correl coef. will be display in grey
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
332 cor_low <- which(round(cor_abs_int, 2) < processing_parameters$r_threshold)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
333
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
334 lbmzcor <- sprintf("%s(r=%s)", vmz, round(cor_abs_int, 2))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
335
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
336 if (length(cor_low) > 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
337 text(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
338 vmz[cor_low],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
339 rel_int[cor_low],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
340 lbmzcor[cor_low],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
341 cex = 0.5,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
342 col = "grey",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
343 srt = 90,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
344 adj = 0
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
345 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
346 if (length(vmz) - length(cor_low) > 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
347 text(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
348 vmz[-c(refcol, cor_low)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
349 rel_int[-c(refcol, cor_low)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
350 lbmzcor[-c(refcol, cor_low)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
351 cex = 0.6,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
352 col = 1,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
353 srt = 90,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
354 adj = 0
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
355 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
356 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
357 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
358 if (length(vmz) > 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
359 text(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
360 vmz[-c(refcol)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
361 rel_int[-c(refcol)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
362 lbmzcor[-c(refcol)],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
363 cex = 0.6,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
364 col = 1,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
365 srt = 90,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
366 adj = 0
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
367 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
368 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
369 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
370
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
371 text(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
372 vmz[refcol],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
373 rel_int[refcol],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
374 lbmzcor[refcol],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
375 cex = 0.8,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
376 col = 2,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
377 srt = 90,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
378 adj = 0
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
379 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
380 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
381
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
382 ## prepare result file
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
383 cor_valid <- (round(cor_abs_int, 2) >= processing_parameters$r_threshold)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
384
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
385 do_sirius <- TRUE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
386 verbose_catf("Checking sirius parameters...\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
387 if (is.null(processing_parameters$ionization)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
388 do_sirius <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
389 verbose_catf("[KO] No ionization passed in parameter.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
390 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
391 verbose_catf("[OK] Ionization=%s.\n", processing_parameters$ionization)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
392 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
393 if (is.na(processing_parameters$elemcomposition)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
394 do_sirius <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
395 verbose_catf("[KO] Elemental composition is NA.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
396 } else if (length(processing_parameters$elemcomposition) < 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
397 do_sirius <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
398 verbose_catf("[KO] No elemental composition is provided.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
399 } else if (processing_parameters$elemcomposition == "") {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
400 do_sirius <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
401 verbose_catf("[KO] Elemental composition is an empty string.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
402 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
403 verbose_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
404 "[OK] Elemental composition=%s.\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
405 processing_parameters$elemcomposition
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
406 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
407 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
408
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
409 cp_res_length <- length(vmz)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
410 ppm <- rep(NA, cp_res_length)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
411 formulas <- rep(NA, cp_res_length)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
412 if (do_sirius) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
413 verbose_catf("Everything is ok, preparing for sirius.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
414 formulas <- get_formulas(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
415 mzref = processing_parameters$mzref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
416 spectra = data.frame(mz = meaned_mz, intensities = sum_int[-1]),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
417 processing_parameters = processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
418 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
419 if (nrow(formulas) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
420 catf("No formula found.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
421 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
422 ppm <- formulas$ppm
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
423 formulas <- formulas$formula
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
424 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
425 "Found %s formula for %s fragments\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
426 length(formulas[which(!(is.na(formulas)))]),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
427 cp_res_length
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
428 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
429 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
430 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
431 verbose_catf("Sirius cannot be run.\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
432 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
433 cp_res <- data.frame(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
434 rep(processing_parameters$c_name, cp_res_length),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
435 rep(processing_parameters$inchikey, cp_res_length),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
436 rep(processing_parameters$elemcomposition, cp_res_length),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
437 formulas,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
438 meaned_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
439 ppm,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
440 rep(fid, cp_res_length),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
441 cor_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
442 sum_int[-1],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
443 rel_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
444 cor_valid
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
445 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
446
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
447 colnames(cp_res) <- c(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
448 "compoundName",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
449 "inchikey",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
450 "elemcomposition",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
451 "fragment",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
452 "fragment_mz",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
453 "ppm",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
454 "fileid",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
455 "CorWithPrecursor",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
456 "AbsoluteIntensity",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
457 "relativeIntensity",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
458 "corValid"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
459 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
460 return(cp_res)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
461 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
462
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
463 #'
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
464 #' @title extract_fragments
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
465 #'
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
466 #' @param precursors the precursor list from mspurity
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
467 #' @param fragments the fragments list from ms purity
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
468 # ' @param mzref
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
469 # ' @param rtref
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
470 # ' @param c_name
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
471 # ' @param inchikey
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
472 # ' @param elemcomposition
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
473 #' @param processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
474 #' @returns
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
475 #'
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
476 #' @description
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
477 #' function for extraction of fragments corresponding to precursors
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
478 #' detected by MSPurity
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
479 extract_fragments <- function( ## nolint cyclocomp_linter
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
480 precursors,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
481 fragments,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
482 processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
483 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
484 ## filter precursor in the precursors file based on mz and rt in the
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
485 ## compound list
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
486 catf("processing %s\n", processing_parameters$c_name)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
487 verbose_catf("===\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
488 param <- processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
489 selected_precursors <- which(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
490 (abs(precursors$precurMtchMZ - param$mzref) <= param$tolmz)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
491 & (abs(precursors$precurMtchRT - param$rtref) <= param$tolrt)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
492 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
493 rm(param)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
494
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
495 verbose_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
496 "> %s precursors selected with mz=%s±%s and rt=%s±%s\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
497 length(selected_precursors),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
498 processing_parameters$mzref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
499 processing_parameters$tolmz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
500 processing_parameters$rtref,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
501 processing_parameters$tolrt
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
502 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
503
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
504 ## check if there is the precursor in the file
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
505
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
506 if (length(selected_precursors) < 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
507 cat("> non detected in precursor file\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
508 show_end_processing()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
509 return(NULL)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
510 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
511
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
512 precursors <- precursors[selected_precursors, ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
513
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
514 ## check if fragments corresponding to precursor are found in several
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
515 ## files (collision energy)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
516 ## this lead to a processing for each fileid
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
517 file_ids <- as.character(sort(unique(precursors$fileid)))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
518 if (length(file_ids) > 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
519 catf("> several files detected for this compounds :\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
520 } else if (length(file_ids) < 1 || nrow(precursors) < 1) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
521 return(data.frame())
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
522 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
523
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
524 res_comp <- data.frame()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
525 for (curent_file_id in file_ids) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
526 curent_precursors <- precursors[precursors$fileid == curent_file_id, ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
527 selected_fragments <- fragments[
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
528 fragments$grpid %in% as.character(curent_precursors$grpid)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
529 & fragments$fileid == curent_file_id,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
530 ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
531 filtered_fragments <- selected_fragments[
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
532 selected_fragments$ra > processing_parameters$seuil_ra,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
533 ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
534 if (nrow(filtered_fragments) != 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
535 res_comp_by_file <- process_file(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
536 curent_file_id = curent_file_id,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
537 precursor_mz = curent_precursors$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
538 filtered_fragments = filtered_fragments,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
539 processing_parameters = processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
540 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
541 if (!is.null(res_comp_by_file)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
542 res_comp <- rbind(res_comp, res_comp_by_file)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
543 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
544 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
545 catf("No fragment found for in fragment file\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
546 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
547 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
548 return(unique(res_comp))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
549 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
550
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
551 process_file <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
552 curent_file_id,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
553 precursor_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
554 filtered_fragments,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
555 processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
556 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
557 mznominal <- round(x = filtered_fragments$mz, digits = 0)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
558 meaned_mz <- round(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
559 aggregate(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
560 data.frame(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
561 mz = filtered_fragments$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
562 mznominal = mznominal
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
563 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
564 list(mznominal),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
565 FUN = mean
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
566 )$mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
567 digits = processing_parameters$mzdecimal
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
568 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
569 filtered_fragments <- data.frame(filtered_fragments, mznominal)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
570
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
571 ## creation of cross table row=scan col=mz X=ra
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
572
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
573 vmz <- as.character(sort(unique(filtered_fragments$mznominal)))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
574
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
575 ds_abs_int <- create_ds_abs_int(vmz, filtered_fragments)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
576
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
577 if (global_debug) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
578 print(ds_abs_int)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
579 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
580
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
581 ## elimination of mz with less than min_number_scan scans (user defined
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
582 ## parameter)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
583 xmz <- rep(NA, ncol(ds_abs_int) - 1)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
584 sum_int <- rep(NA, ncol(ds_abs_int))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
585 nbxmz <- 0
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
586 nb_scan_check <- min(nrow(ds_abs_int), processing_parameters$min_number_scan)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
587
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
588 for (j in 2:ncol(ds_abs_int)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
589 sum_int[j] <- sum(ds_abs_int[j], na.rm = TRUE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
590 if (sum(!is.na(ds_abs_int[[j]])) < nb_scan_check) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
591 nbxmz <- nbxmz + 1
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
592 xmz[nbxmz] <- j
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
593 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
594 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
595
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
596 xmz <- xmz[-which(is.na(xmz))]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
597 if (length(xmz) > 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
598 ds_abs_int <- ds_abs_int[, -c(xmz)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
599 sum_int <- sum_int[-c(xmz)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
600 ## liste des mz keeped decale de 1 avec ds_abs_int
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
601 vmz <- as.numeric(vmz[-c(xmz - 1)])
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
602 meaned_mz <- meaned_mz[-c(xmz - 1)]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
603 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
604
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
605 ## mz of precursor in data precursor to check correlation with
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
606 mz_prec <- paste0(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
607 "mz",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
608 round(mean(precursor_mz), processing_parameters$mzdecimal)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
609 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
610 ## reference ion for correlation computing = precursor OR maximum
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
611 ## intensity ion in precursor is not present
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
612 refcol <- which(colnames(ds_abs_int) == mz_prec)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
613 if (length(refcol) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
614 refcol <- which(sum_int == max(sum_int, na.rm = TRUE))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
615 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
616
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
617 if (processing_parameters$do_pdf) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
618 start_pdf(processing_parameters, curent_file_id)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
619 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
620
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
621 ## Pearson correlations between absolute intensities computing
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
622 cor_abs_int <- rep(NA, length(vmz))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
623
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
624 if (length(refcol) > 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
625 for (i in 2:length(ds_abs_int)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
626 cor_abs_int[i - 1] <- stats::cor(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
627 x = ds_abs_int[[refcol]],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
628 y = ds_abs_int[[i]],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
629 use = "pairwise.complete.obs",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
630 method = "pearson"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
631 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
632 debug_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
633 "Correlation between %s and %s: %s\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
634 paste(ds_abs_int[[refcol]], collapse = ";"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
635 paste(ds_abs_int[[i]], collapse = ";"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
636 paste(cor_abs_int[i - 1], collapse = ";")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
637 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
638 if (processing_parameters$do_pdf) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
639 pdf_plot_ds_abs_int(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
640 processing_parameters$c_name,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
641 ds_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
642 refcol,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
643 i,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
644 round(cor_abs_int[i - 1], 2)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
645 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
646 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
647 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
648 ## plot pseudo spectra
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
649 res_comp_by_file <- plot_pseudo_spectra(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
650 x = ds_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
651 fid = curent_file_id,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
652 sum_int = sum_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
653 vmz = vmz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
654 cor_abs_int = cor_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
655 refcol = refcol,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
656 meaned_mz = meaned_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
657 processing_parameters = processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
658 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
659 catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
660 "%s has been processed and %s fragments have been found.\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
661 processing_parameters$c_name,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
662 nrow(res_comp_by_file)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
663 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
664 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
665 res_comp_by_file <- NULL
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
666 cat(">> non detected in fragments file \n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
667 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
668 show_end_processing()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
669 if (processing_parameters$do_pdf) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
670 end_pdf()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
671 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
672 return(res_comp_by_file)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
673 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
674
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
675 create_ds_abs_int <- function(vmz, filtered_fragments) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
676 verbose_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
677 ">> fragments: %s\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
678 paste(vmz, collapse = " ")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
679 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
680 ds_abs_int <- create_int_mz(vmz[1], filtered_fragments)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
681 for (mz in vmz[-1]) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
682 int_mz <- create_int_mz(mz, filtered_fragments)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
683 ds_abs_int <- merge(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
684 x = ds_abs_int,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
685 y = int_mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
686 by.x = 1,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
687 by.y = 1,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
688 all.x = TRUE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
689 all.y = TRUE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
690 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
691 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
692 return(ds_abs_int)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
693 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
694
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
695 create_int_mz <- function(mz, filtered_fragments) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
696 ## absolute intensity
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
697 int_mz <- filtered_fragments[
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
698 filtered_fragments$mznominal == mz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
699 c("acquisitionNum", "i")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
700 ]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
701 colnames(int_mz)[2] <- paste0("mz", mz)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
702 ## average intensities of mass in duplicate scans
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
703 comp_scans <- aggregate(x = int_mz, by = list(int_mz[[1]]), FUN = mean)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
704 return(comp_scans[, -1])
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
705 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
706
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
707 show_end_processing <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
708 verbose_catf("==========\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
709 cat("\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
710 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
711
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
712 start_pdf <- function(processing_parameters, curent_file_id) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
713 if (!dir.exists(processing_parameters$pdf_path)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
714 dir.create(processing_parameters$pdf_path, recursive = TRUE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
715 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
716 pdf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
717 file = sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
718 "%s/%s_processing_file%s.pdf",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
719 processing_parameters$pdf_path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
720 processing_parameters$c_name,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
721 curent_file_id
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
722 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
723 width = 8,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
724 height = 11
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
725 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
726 par(mfrow = c(3, 2))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
727 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
728
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
729 pdf_plot_ds_abs_int <- function(c_name, ds_abs_int, refcol, i, r_coef) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
730 plot(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
731 ds_abs_int[[refcol]],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
732 ds_abs_int[[i]],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
733 xlab = colnames(ds_abs_int)[refcol],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
734 ylab = colnames(ds_abs_int)[i],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
735 main = sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
736 "%s corr coeff r=%s", c_name, r_coef
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
737 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
738 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
739 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
740 end_pdf <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
741 dev.off()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
742 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
743
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
744 set_global <- function(var, value) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
745 assign(var, value, envir = globalenv())
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
746 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
747
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
748 set_debug <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
749 set_global("global_debug", TRUE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
750 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
751
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
752 unset_debug <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
753 set_global("global_debug", FALSE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
754 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
755
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
756 set_verbose <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
757 set_global("global_verbose", TRUE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
758 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
759
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
760 unset_verbose <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
761 set_global("global_verbose", FALSE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
762 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
763
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
764 verbose_catf <- function(...) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
765 if (global_verbose) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
766 cat(sprintf(...), sep = "")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
767 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
768 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
769
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
770
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
771 debug_catf <- function(...) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
772 if (global_debug) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
773 cat(sprintf(...), sep = "")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
774 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
775 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
776
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
777 catf <- function(...) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
778 cat(sprintf(...), sep = "")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
779 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
780
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
781 create_parser <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
782 parser <- optparse::OptionParser()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
783 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
784 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
785 c("-v", "--verbose"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
786 action = "store_true",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
787 default = FALSE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
788 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
789 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
790 "Print extra output"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
791 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
792 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
793 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
794 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
795 c("-V", "--version"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
796 action = "store_true",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
797 default = FALSE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
798 help = "Prints version and exits"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
799 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
800 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
801 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
802 c("-d", "--debug"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
803 action = "store_true",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
804 default = FALSE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
805 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
806 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
807 "Print debug outputs"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
808 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
809 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
810 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
811 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
812 c("-o", "--output"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
813 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
814 default = DEFAULT_OUTPUT_PATH,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
815 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
816 help = "Path to the output file [default %default]"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
817 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
818 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
819 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
820 c("-p", "--precursors"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
821 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
822 default = DEFAULT_PRECURSOR_PATH,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
823 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
824 help = "Path to the precursors file [default %default]"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
825 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
826 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
827 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
828 c("-f", "--fragments"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
829 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
830 default = DEFAULT_FRAGMENTS_PATH,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
831 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
832 help = "Path to the fragments file [default %default]"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
833 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
834 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
835 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
836 c("-c", "--compounds"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
837 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
838 default = DEFAULT_COMPOUNDS_PATH,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
839 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
840 help = "Path to the compounds file [default %default]"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
841 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
842 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
843 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
844 c("--tolmz"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
845 type = "numeric",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
846 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
847 default = DEFAULT_TOLMZ,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
848 metavar = "number",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
849 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
850 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
851 "Tolerance for MZ (in Dalton) to match the standard in the compounds"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
852 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
853 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
854 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
855 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
856 c("--tolrt"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
857 type = "integer",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
858 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
859 default = DEFAULT_TOLRT,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
860 metavar = "number",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
861 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
862 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
863 "RT (in seconds) to match the standard in the compounds"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
864 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
865 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
866 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
867 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
868 c("--seuil_ra"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
869 type = "numeric",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
870 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
871 default = DEFAULT_SEUIL_RA,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
872 metavar = "number",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
873 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
874 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
875 "relative intensity threshold"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
876 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
877 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
878 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
879 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
880 c("--mzdecimal"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
881 type = "integer",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
882 default = DEFAULT_MZDECIMAL,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
883 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
884 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
885 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
886 "Number of decimal to write for MZ"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
887 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
888 metavar = "number"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
889 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
890 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
891 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
892 c("--r_threshold"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
893 type = "integer",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
894 default = DEFAULT_R_THRESHOLD,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
895 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
896 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
897 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
898 "R-Pearson correlation threshold between precursor and fragment",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
899 "absolute intensity"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
900 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
901 metavar = "number"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
902 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
903 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
904 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
905 c("--min_number_scan"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
906 type = "numeric",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
907 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
908 default = DEFAULT_MINNUMBERSCAN,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
909 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
910 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
911 "Fragments are kept if there are found in a minimum number",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
912 "of min_number_scan scans"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
913 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
914 metavar = "number"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
915 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
916 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
917 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
918 c("--pdf_path"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
919 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
920 default = DEFAULT_PDF_PATH,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
921 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
922 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
923 "PDF files output path"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
924 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
925 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
926 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
927 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
928 c("--ionization"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
929 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
930 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
931 default = "None",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
932 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
933 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
934 "Which ionization to use for sirius"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
935 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
936 metavar = "character"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
937 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
938 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
939 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
940 c("--fragment_match_delta"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
941 type = "numeric",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
942 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
943 default = DEFAULT_FRAGMENTS_MATCH_DELTA,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
944 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
945 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
946 "Fragment match delta"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
947 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
948 metavar = "numeric"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
949 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
950 parser <- optparse::add_option(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
951 parser,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
952 c("--fragment_match_delta_unit"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
953 type = "character",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
954 action = "store",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
955 default = DEFAULT_FRAGMENTS_MATCH_DELTA_UNIT,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
956 help = paste(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
957 "[default %default]",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
958 "Fragment match delta"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
959 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
960 metavar = "character"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
961 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
962 return(parser)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
963 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
964
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
965 stop_with_status <- function(msg, status) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
966 sink(stderr())
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
967 message(sprintf("Error: %s", msg))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
968 message(sprintf("Error code: %s", status))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
969 sink(NULL)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
970 base::quit(status = status)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
971 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
972
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
973 check_args_validity <- function(args) { ## nolint cyclocomp_linter
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
974 if (length(args$output) == 0 || nchar(args$output[1]) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
975 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
976 "Missing output parameters. Please set it with --output.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
977 MISSING_PARAMETER_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
978 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
979 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
980 if (length(args$precursors) == 0 || nchar(args$precursors[1]) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
981 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
982 "Missing precursors parameters. Please set it with --precursors.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
983 MISSING_PARAMETER_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
984 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
985 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
986 if (length(args$fragments) == 0 || nchar(args$fragments[1]) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
987 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
988 "Missing fragments parameters. Please set it with --fragments.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
989 MISSING_PARAMETER_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
990 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
991 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
992 if (length(args$compounds) == 0 || nchar(args$compounds[1]) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
993 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
994 "Missing compounds parameters. Please set it with --compounds.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
995 MISSING_PARAMETER_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
996 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
997 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
998 if (!file.exists(args$precursors)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
999 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1000 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1001 "Precursors file %s does not exist or cannot be accessed.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1002 args$precursors
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1003 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1004 MISSING_INPUT_FILE_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1005 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1006 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1007 if (!file.exists(args$fragments)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1008 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1009 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1010 "Fragments file %s does not exist or cannot be accessed.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1011 args$fragments
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1012 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1013 MISSING_INPUT_FILE_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1014 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1015 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1016 if (!file.exists(args$compounds)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1017 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1018 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1019 "Compounds file %s does not exist or cannot be accessed.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1020 args$compounds
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1021 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1022 MISSING_INPUT_FILE_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1023 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1024 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1025 if (in_galaxy_env()) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1026 check_galaxy_args_validity(args)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1027 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1028 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1029
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1030 in_galaxy_env <- function() {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1031 sysvars <- Sys.getenv()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1032 sysvarnames <- names(sysvars)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1033 return(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1034 "_GALAXY_JOB_HOME_DIR" %in% sysvarnames
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1035 || "_GALAXY_JOB_TMP_DIR" %in% sysvarnames
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1036 || "GALAXY_MEMORY_MB" %in% sysvarnames
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1037 || "GALAXY_MEMORY_MB_PER_SLOT" %in% sysvarnames
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1038 || "GALAXY_SLOTS" %in% sysvarnames
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1039 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1040 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1041
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1042 check_galaxy_args_validity <- function(args) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1043 if (!file.exists(args$output)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1044 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1045 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1046 "Output file %s does not exist or cannot be accessed.",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1047 args$output
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1048 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1049 MISSING_INPUT_FILE_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1050 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1051 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1052 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1053
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1054 get_csv_or_tsv <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1055 path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1056 sep_stack = c("\t", ",", ";"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1057 sep_names = c("tab", "comma", "semicolon"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1058 header = TRUE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1059 quote = "\""
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1060 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1061 sep <- determine_csv_or_tsv_sep(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1062 path = path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1063 sep_stack = sep_stack,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1064 header = header,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1065 quote = quote
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1066 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1067 verbose_catf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1068 "%s separator has been determined for %s.\n",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1069 sep_names[sep_stack == sep],
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1070 path
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1071 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1072 return(read.table(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1073 file = path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1074 sep = sep,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1075 header = header,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1076 quote = quote
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1077 ))
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1078 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1079
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1080 determine_csv_or_tsv_sep <- function(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1081 path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1082 sep_stack = c("\t", ",", ";"),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1083 header = TRUE,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1084 quote = "\""
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1085 ) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1086 count <- -1
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1087 best_sep <- sep_stack[1]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1088 for (sep in sep_stack) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1089 tryCatch({
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1090 table <- read.table(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1091 file = path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1092 sep = sep,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1093 header = header,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1094 quote = quote,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1095 nrows = 1
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1096 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1097 if (ncol(table) > count) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1098 count <- ncol(table)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1099 best_sep <- sep
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1100 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1101 })
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1102 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1103 return(best_sep)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1104 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1105
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1106 uniformize_columns <- function(df) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1107 cols <- colnames(df)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1108 for (func in c(tolower)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1109 cols <- func(cols)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1110 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1111 colnames(df) <- cols
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1112 return(df)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1113 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1114
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1115 handle_galaxy_param <- function(args) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1116 for (param in names(args)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1117 if (is.character(args[[param]])) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1118 args[[param]] <- gsub("__ob__", "[", args[[param]])
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1119 args[[param]] <- gsub("__cb__", "]", args[[param]])
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1120 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1121 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1122 return(args)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1123 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1124
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1125 zip_pdfs <- function(processing_parameters) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1126 if (processing_parameters$do_pdf) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1127 if (zip <- Sys.getenv("R_ZIPCMD", "zip") == "") {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1128 catf("R could not fin the zip executable. Trying luck: zip = \"zip\"")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1129 zip <- "zip"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1130 } else {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1131 catf("Found zip executable at %s .", zip)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1132 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1133 utils::zip(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1134 processing_parameters$pdf_zip_path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1135 processing_parameters$pdf_path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1136 zip = zip
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1137 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1138 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1139 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1140
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1141 main <- function(args) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1142 if (args$version) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1143 catf("%s\n", MS2SNOOP_VERSION)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1144 base::quit(status = 0)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1145 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1146 if (in_galaxy_env()) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1147 print(sessionInfo())
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1148 cat("\n\n")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1149 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1150 check_args_validity(args)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1151 args <- handle_galaxy_param(args)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1152 if (args$ionization == "None") {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1153 args$ionization <- NULL
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1154 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1155 if (args$debug) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1156 set_debug()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1157 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1158 if (args$verbose) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1159 set_verbose()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1160 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1161 precursors <- get_csv_or_tsv(args$precursors)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1162 fragments <- get_csv_or_tsv(args$fragments)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1163 compounds <- get_csv_or_tsv(args$compounds)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1164
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1165 compounds <- uniformize_columns(compounds)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1166 mandatory_columns <- c(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1167 "compound_name",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1168 "mz",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1169 "rtsec",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1170 "inchikey"
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1171 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1172 presents <- mandatory_columns %in% colnames(compounds)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1173 if (!all(presents)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1174 stop_with_status(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1175 sprintf(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1176 "Some columns are missing: %s",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1177 paste(mandatory_columns[which(!presents)], collapse = ", ")
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1178 ),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1179 BAD_PARAMETER_VALUE_ERROR
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1180 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1181 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1182
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1183 res_all <- data.frame()
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1184 processing_parameters <- list(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1185 min_number_scan = args$min_number_scan,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1186 mzdecimal = args$mzdecimal,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1187 r_threshold = args$r_threshold,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1188 seuil_ra = args$seuil_ra,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1189 tolmz = args$tolmz,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1190 tolrt = args$tolrt,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1191 ionization = args$ionization,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1192 do_pdf = nchar(args$pdf_path) > 0,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1193 pdf_zip_path = args$pdf_path,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1194 pdf_path = tempdir(),
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1195 fragment_match_delta = args$fragment_match_delta,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1196 fragment_match_delta_unit = args$fragment_match_delta_unit
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1197 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1198 for (i in seq_len(nrow(compounds))) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1199 processing_parameters$mzref <- compounds[["mz"]][i]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1200 processing_parameters$rtref <- compounds[["rtsec"]][i]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1201 processing_parameters$c_name <- compounds[["compound_name"]][i]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1202 processing_parameters$inchikey <- compounds[["inchikey"]][i]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1203 processing_parameters$elemcomposition <- compounds[["elemcomposition"]][i]
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1204 res_cor <- extract_fragments(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1205 precursors = precursors,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1206 fragments = fragments,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1207 processing_parameters = processing_parameters
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1208 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1209 if (!is.null(res_cor)) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1210 res_all <- rbind(res_all, res_cor)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1211 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1212 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1213
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1214 if (nrow(res_all) == 0) {
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1215 stop_with_status("No result at all!", NO_ANY_RESULT_ERROR)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1216 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1217
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1218 write.table(
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1219 x = res_all,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1220 file = args$output,
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1221 sep = "\t",
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1222 row.names = FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1223 )
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1224 zip_pdfs(processing_parameters)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1225 unlink(processing_parameters$pdf_path, recursive = TRUE)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1226 }
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1227
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1228 global_debug <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1229 global_verbose <- FALSE
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1230 args <- optparse::parse_args(create_parser())
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1231 main(args)
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1232
77abacd33c31 planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
workflow4metabolomics
parents: 5
diff changeset
1233 warnings()