annotate MS2snoop.R @ 7:2a1f120a6874 draft default tip

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