annotate MS2snoop.R @ 4:856001213966 draft

planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
author workflow4metabolomics
date Wed, 06 Jul 2022 10:38:39 +0000
parents c68c94865667
children 78d5a12406c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
1 #'
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
2 #' read and process mspurity W4M files
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
3 #' create a summary of fragment for each precursor and a graphics of peseudo
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
4 #' spectra + correlation on which checking of fragment is based on
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
5 #' V3 try to identify and process multiple files for 1 precursor which may
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
6 #' occur if different collision energy are used
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
7 #' V4 elimination of correlation = NA. Correlation is done with precursor, if
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
8 #' precursor is not present correlation with most intense peak
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
9 #' author: Jean-Francois Martin
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
10 #' V5 is versionned, lintR-compliant, packaged, unit-tested, documented and
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
11 #' tested against data from other labs.
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
12 #' new maintainer: Lain Pavot - lain.pavot@inrae.fr
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
13 #'
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
14 #' @import optparse
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
15 #'
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
16
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
17
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
18 assign("MS2SNOOP_VERSION", "2.0.0")
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
19 lockBinding("MS2SNOOP_VERSION", globalenv())
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
20
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
21 assign("MISSING_PARAMETER_ERROR", 1)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
22 lockBinding("MISSING_PARAMETER_ERROR", globalenv())
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
23
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
24 assign("BAD_PARAMETER_VALUE_ERROR", 2)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
25 lockBinding("BAD_PARAMETER_VALUE_ERROR", globalenv())
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
26
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
27 assign("MISSING_INPUT_FILE_ERROR", 3)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
28 lockBinding("MISSING_INPUT_FILE_ERROR", globalenv())
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
29
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
30 assign("NO_ANY_RESULT_ERROR", 255)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
31 lockBinding("NO_ANY_RESULT_ERROR", globalenv())
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
32
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
33 assign("DEFAULT_PRECURSOR_PATH", "peaklist_precursors.tsv")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
34 assign("DEFAULT_FRAGMENTS_PATH", "peaklist_fragments.tsv")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
35 assign("DEFAULT_COMPOUNDS_PATH", "compounds_pos.txt")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
36 assign("DEFAULT_OUTPUT_PATH", "compound_fragments_result.txt")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
37 assign("DEFAULT_TOLMZ", 0.01)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
38 assign("DEFAULT_TOLRT", 20)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
39 assign("DEFAULT_MZDECIMAL", 0)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
40 assign("DEFAULT_R_THRESHOLD", 0.85)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
41 assign("DEFAULT_MINNUMBERSCAN", 8)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
42 assign("DEFAULT_SEUIL_RA", 0.5)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
43 lockBinding("DEFAULT_PRECURSOR_PATH", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
44 lockBinding("DEFAULT_FRAGMENTS_PATH", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
45 lockBinding("DEFAULT_COMPOUNDS_PATH", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
46 lockBinding("DEFAULT_OUTPUT_PATH", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
47 lockBinding("DEFAULT_TOLMZ", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
48 lockBinding("DEFAULT_TOLRT", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
49 lockBinding("DEFAULT_MZDECIMAL", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
50 lockBinding("DEFAULT_R_THRESHOLD", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
51 lockBinding("DEFAULT_MINNUMBERSCAN", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
52 lockBinding("DEFAULT_SEUIL_RA", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
53
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
54 assign("DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD", 0.85)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
55 assign("DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA", 0.1)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
56 assign("DEFAULT_EXTRACT_FRAGMENTS_TOLMZ", 0.01)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
57 assign("DEFAULT_EXTRACT_FRAGMENTS_TOLRT", 60)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
58 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
59 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
60 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_TOLMZ", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
61 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_TOLRT", globalenv())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
62
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
63
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
64 ########################################################################
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
65
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
66 #' @title plot_pseudo_spectra
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
67 #' @param x
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
68 #' @param r_threshold
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
69 #' @param fid
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
70 #' @param sum_int
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
71 #' @param vmz
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
72 #' @param cor_abs_int
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
73 #' @param refcol
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
74 #' @param c_name
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
75 #' @description plot_pseudo_spectra
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
76 #' function to compute sum of intensities among scans for all
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
77 #' m/z kept (cor > r_threshold & minimum number of scans)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
78 #' and plot pseudo spectra
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
79 #' x dataframe scan X fragments with scans number in the 1st column and
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
80 #' ions in next with intensities
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
81 #' fid file id when several a precursor has been detected in several files
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
82 plot_pseudo_spectra <- function(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
83 x,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
84 r_threshold,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
85 fid,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
86 sum_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
87 vmz,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
88 cor_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
89 refcol,
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
90 c_name,
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
91 inchikey,
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
92 elemcomposition
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
93 ) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
94 ## du fait de la difference de nombre de colonne entre la dataframe qui
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
95 ## inclue les scans en 1ere col, mzRef se decale de 1
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
96 refcol <- refcol - 1
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
97 ## compute relative intensities max=100%
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
98 rel_int <- sum_int[-1]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
99 rel_int <- rel_int / max(rel_int)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
100
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
101 ## define max value on vertical axis (need to increase in order to plot the
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
102 ## label of fragments)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
103 ymax <- max(rel_int) + 0.2 * max(rel_int)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
104
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
105 par(mfrow = c(2, 1))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
106 plot(vmz, rel_int, type = "h", ylim = c(0, ymax), main = c_name)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
107 ## low correl coef. will be display in grey
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
108 cor_low <- which(round(cor_abs_int, 2) < r_threshold)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
109
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
110 lbmzcor <- sprintf("%s(r=%s)", vmz, round(cor_abs_int, 2))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
111
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
112 if (length(cor_low) > 0) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
113 text(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
114 vmz[cor_low],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
115 rel_int[cor_low],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
116 lbmzcor[cor_low],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
117 cex = 0.5,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
118 col = "grey",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
119 srt = 90,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
120 adj = 0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
121 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
122 if (length(vmz) - length(cor_low) > 1) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
123 text(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
124 vmz[-c(refcol, cor_low)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
125 rel_int[-c(refcol, cor_low)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
126 lbmzcor[-c(refcol, cor_low)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
127 cex = 0.6,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
128 col = 1,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
129 srt = 90,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
130 adj = 0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
131 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
132 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
133 } else {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
134 if (length(vmz) > 1) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
135 text(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
136 vmz[-c(refcol)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
137 rel_int[-c(refcol)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
138 lbmzcor[-c(refcol)],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
139 cex = 0.6,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
140 col = 1,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
141 srt = 90,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
142 adj = 0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
143 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
144 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
145 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
146
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
147 text(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
148 vmz[refcol],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
149 rel_int[refcol],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
150 lbmzcor[refcol],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
151 cex = 0.8,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
152 col = 2,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
153 srt = 90,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
154 adj = 0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
155 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
156
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
157 ## prepare result file
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
158 corValid <- (round(cor_abs_int, 2) >= r_threshold) ##nolint object_name_linter
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
159 cp_res <- data.frame(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
160 rep(c_name, length(vmz)),
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
161 rep(inchikey, length(vmz)),
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
162 rep(elemcomposition, length(vmz)),
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
163 rep(fid, length(vmz)),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
164 vmz,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
165 cor_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
166 sum_int[-1],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
167 rel_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
168 corValid
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
169 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
170
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
171 colnames(cp_res) <- c(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
172 "compoundName",
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
173 "inchikey",
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
174 "elemcomposition",
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
175 "fileid",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
176 "fragments_mz",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
177 "CorWithPrecursor",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
178 "AbsoluteIntensity",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
179 "relativeIntensity",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
180 "corValid"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
181 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
182 return(cp_res)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
183
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
184 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
185
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
186 #'
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
187 #' @title extract_fragments
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
188 #'
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
189 #' @param precursors the precursor list from mspurity
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
190 #' @param fragments the fragments list from ms purity
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
191 #' @param mzref
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
192 #' @param rtref
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
193 #' @param c_name
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
194 #' @param r_threshold default = DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
195 #' @param seuil_ra default = DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
196 #' @param tolmz default = DEFAULT_EXTRACT_FRAGMENTS_TOLMZ
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
197 #' @param tolrt default = DEFAULT_EXTRACT_FRAGMENTS_TOLRT
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
198 #' @returns
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
199 #'
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
200 #' @description
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
201 #' function for extraction of fragments corresponding to precursors
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
202 #' detected by MSPurity
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
203 extract_fragments <- function( ## nolint cyclocomp_linter
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
204 precursors,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
205 fragments,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
206 mzref,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
207 rtref,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
208 c_name,
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
209 inchikey,
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
210 elemcomposition,
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
211 min_number_scan,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
212 mzdecimal,
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
213 r_threshold = DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
214 seuil_ra = DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
215 tolmz = DEFAULT_EXTRACT_FRAGMENTS_TOLMZ,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
216 tolrt = DEFAULT_EXTRACT_FRAGMENTS_TOLRT
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
217 ) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
218 ## filter precursor in the precursors file based on mz and rt in the
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
219 ## compound list
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
220 cat("processing ", c_name, "\n")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
221 selected_precursors <- which(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
222 (abs(precursors$precurMtchMZ - mzref) <= tolmz)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
223 & (abs(precursors$precurMtchRT - rtref) <= tolrt)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
224 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
225
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
226 ## check if there is the precursor in the file
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
227 if (length(selected_precursors) > 0) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
228
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
229 sprecini <- precursors[selected_precursors, ]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
230
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
231 ## check if fragments corresponding to precursor are found in several
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
232 ## files (collision energy)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
233 ## this lead to a processing for each fileid
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
234 mf <- levels(as.factor(sprecini$fileid))
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
235 if (length(mf) > 1 && global_verbose) {
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
236 cat(" several files detected for this compounds :\n")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
237 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
238
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
239 for (f in seq_along(mf)) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
240
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
241 sprec <- sprecini[sprecini$fileid == mf[f], ]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
242
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
243 ## selection of fragment in the fragments file with the grpid common in
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
244 ## both fragments and precursors
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
245 selfrgt <- levels(as.factor(sprec$grpid))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
246 sfrgt <- fragments[
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
247 fragments$grpid %in% selfrgt
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
248 & fragments$fileid == mf[f],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
249 ]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
250
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
251 ## filter fragments on relative intensity seuil_ra = user defined
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
252 ## parameter (MSpurity flags could be used here)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
253 sfrgtfil <- sfrgt[sfrgt$ra > seuil_ra, ]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
254
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
255 mznominal <- round(x = sfrgtfil$mz, mzdecimal)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
256 sfrgtfil <- data.frame(sfrgtfil, mznominal)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
257
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
258 ## creation of cross table row=scan col=mz X=ra
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
259 vmz <- levels(as.factor(sfrgtfil$mznominal))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
260
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
261 if (global_verbose) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
262 cat(" fragments :", vmz)
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
263 cat("\n")
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
264 }
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
265
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
266 ## mz of precursor in data precursor to check correlation with
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
267 mz_prec <- paste0("mz", round(mean(sprec$mz), mzdecimal))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
268
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
269 for (m in seq_along(vmz)) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
270
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
271 ## absolute intensity
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
272 cln <- c(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
273 which(colnames(sfrgtfil) == "acquisitionNum"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
274 which(colnames(sfrgtfil) == "i")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
275 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
276 int_mz <- sfrgtfil[sfrgtfil$mznominal == vmz[m], cln]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
277 colnames(int_mz)[2] <- paste0("mz", vmz[m])
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
278
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
279 ## average intensities of mass in duplicate scans
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
280 comp_scans <- aggregate(x = int_mz, by = list(int_mz[[1]]), FUN = mean)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
281 int_mz <- comp_scans[, -1]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
282
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
283 if (m == 1) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
284 ds_abs_int <- int_mz
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
285 } else {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
286 ds_abs_int <- merge(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
287 x = ds_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
288 y = int_mz,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
289 by.x = 1,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
290 by.y = 1,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
291 all.x = TRUE,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
292 all.y = TRUE
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
293 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
294 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
295 }
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
296 if (global_debug) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
297 print(ds_abs_int)
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
298 write.table(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
299 x = ds_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
300 file = paste0(c_name, "ds_abs_int.txt"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
301 row.names = FALSE,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
302 sep = "\t"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
303 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
304 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
305
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
306 ## elimination of mz with less than min_number_scan scans (user defined
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
307 ## parameter)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
308 xmz <- rep(NA, ncol(ds_abs_int) - 1)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
309 sum_int <- rep(NA, ncol(ds_abs_int))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
310 nbxmz <- 0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
311 nb_scan_check <- min(nrow(ds_abs_int), min_number_scan)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
312
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
313 for (j in 2:ncol(ds_abs_int)) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
314 sum_int[j] <- sum(ds_abs_int[j], na.rm = TRUE)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
315 if (sum(!is.na(ds_abs_int[[j]])) < nb_scan_check) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
316 nbxmz <- nbxmz + 1
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
317 xmz[nbxmz] <- j
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
318 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
319 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
320
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
321 xmz <- xmz[-which(is.na(xmz))]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
322 if (length(xmz) > 0) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
323 ds_abs_int <- ds_abs_int[, -c(xmz)]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
324 sum_int <- sum_int[-c(xmz)]
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
325 ## liste des mz keeped decale de 1 avec ds_abs_int
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
326 vmz <- as.numeric(vmz[-c(xmz - 1)])
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
327 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
328
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
329 ## reference ion for correlation computing = precursor OR maximum
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
330 ## intensity ion in precursor is not present
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
331 refcol <- which(colnames(ds_abs_int) == mz_prec)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
332 if (length(refcol) == 0) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
333 refcol <- which(sum_int == max(sum_int, na.rm = TRUE))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
334 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
335 pdf(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
336 file = sprintf("%s_processing_file%s.pdf", c_name, mf[f]),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
337 width = 8,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
338 height = 11
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
339 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
340 par(mfrow = c(3, 2))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
341
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
342 ## Pearson correlations between absolute intensities computing
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
343 cor_abs_int <- rep(NA, length(vmz))
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
344
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
345 if (length(refcol) > 0) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
346 for (i in 2:length(ds_abs_int)) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
347 cor_abs_int[i - 1] <- cor(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
348 x = ds_abs_int[[refcol]],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
349 y = ds_abs_int[[i]],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
350 use = "pairwise.complete.obs",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
351 method = "pearson"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
352 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
353 plot(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
354 ds_abs_int[[refcol]],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
355 ds_abs_int[[i]],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
356 xlab = colnames(ds_abs_int)[refcol],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
357 ylab = colnames(ds_abs_int)[i],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
358 main = sprintf(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
359 "%s corr coeff r=%s", c_name, round(cor_abs_int[i - 1], 2)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
360 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
361 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
362 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
363 ## plot pseudo spectra
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
364 res_comp_by_file <- plot_pseudo_spectra(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
365 x = ds_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
366 r_threshold = r_threshold,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
367 fid = mf[f],
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
368 sum_int = sum_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
369 vmz = vmz,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
370 cor_abs_int = cor_abs_int,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
371 refcol = refcol,
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
372 c_name = c_name,
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
373 inchikey = inchikey,
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
374 elemcomposition = elemcomposition
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
375 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
376 if (f == 1) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
377 res_comp <- res_comp_by_file
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
378 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
379 } else {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
380 res_comp_by_file <- NULL
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
381 cat(" non detected in fragments file \n")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
382 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
383 if (!is.null(res_comp_by_file)) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
384 res_comp <- rbind(res_comp, res_comp_by_file)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
385 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
386 dev.off()
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
387 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
388 } else {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
389 res_comp <- NULL
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
390 cat(" non detected in precursor file \n")
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
391 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
392 return(res_comp)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
393 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
394
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
395 set_global <- function(var, value) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
396 assign(var, value, envir = globalenv())
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
397 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
398
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
399 set_debug <- function() {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
400 set_global("global_debug", TRUE)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
401 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
402
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
403 unset_debug <- function() {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
404 set_global("global_debug", FALSE)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
405 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
406
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
407 set_verbose <- function() {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
408 set_global("global_verbose", TRUE)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
409 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
410
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
411 unset_verbose <- function() {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
412 set_global("global_verbose", FALSE)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
413 }
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
414
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
415 create_parser <- function() {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
416 parser <- optparse::OptionParser()
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
417 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
418 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
419 c("-v", "--verbose"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
420 action = "store_true",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
421 default = FALSE,
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
422 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
423 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
424 "Print extra output"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
425 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
426 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
427 parser <- optparse::add_option(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
428 parser,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
429 c("-V", "--version"),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
430 action = "store_true",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
431 default = FALSE,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
432 help = "Prints version and exits"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
433 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
434 parser <- optparse::add_option(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
435 parser,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
436 c("-d", "--debug"),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
437 action = "store_true",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
438 default = FALSE,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
439 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
440 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
441 "Print debug outputs"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
442 )
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
443 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
444 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
445 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
446 c("-o", "--output"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
447 type = "character",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
448 default = DEFAULT_OUTPUT_PATH,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
449 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
450 help = "Path to the output file [default %default]"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
451 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
452 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
453 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
454 c("-p", "--precursors"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
455 type = "character",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
456 default = DEFAULT_PRECURSOR_PATH,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
457 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
458 help = "Path to the precursors file [default %default]"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
459 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
460 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
461 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
462 c("-f", "--fragments"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
463 type = "character",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
464 default = DEFAULT_FRAGMENTS_PATH,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
465 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
466 help = "Path to the fragments file [default %default]"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
467 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
468 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
469 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
470 c("-c", "--compounds"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
471 type = "character",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
472 default = DEFAULT_COMPOUNDS_PATH,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
473 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
474 help = "Path to the compounds file [default %default]"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
475 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
476 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
477 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
478 c("--tolmz"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
479 type = "numeric",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
480 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
481 default = DEFAULT_TOLMZ,
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
482 metavar = "number",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
483 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
484 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
485 "Tolerance for MZ (in Dalton) to match the standard in the compounds"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
486 )
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
487 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
488 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
489 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
490 c("--tolrt"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
491 type = "integer",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
492 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
493 default = DEFAULT_TOLRT,
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
494 metavar = "number",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
495 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
496 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
497 "RT (in seconds) to match the standard in the compounds"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
498 )
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
499 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
500 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
501 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
502 c("--seuil_ra"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
503 type = "numeric",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
504 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
505 default = DEFAULT_SEUIL_RA,
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
506 metavar = "number",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
507 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
508 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
509 "relative intensity threshold"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
510 ),
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
511 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
512 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
513 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
514 c("--mzdecimal"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
515 type = "integer",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
516 default = DEFAULT_MZDECIMAL,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
517 action = "store",
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
518 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
519 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
520 "Number of decimal to write for MZ"
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
521 ),
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
522 metavar = "number"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
523 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
524 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
525 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
526 c("--r_threshold"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
527 type = "integer",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
528 default = DEFAULT_R_THRESHOLD,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
529 action = "store",
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
530 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
531 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
532 "R-Pearson correlation threshold between precursor and fragment",
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
533 "absolute intensity"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
534 ),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
535 metavar = "number"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
536 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
537 parser <- optparse::add_option(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
538 parser,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
539 c("--min_number_scan"),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
540 type = "numeric",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
541 action = "store",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
542 default = DEFAULT_MINNUMBERSCAN,
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
543 help = paste(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
544 "[default %default]",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
545 "Fragments are kept if there are found in a minimum number",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
546 "of min_number_scan scans"
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
547 ),
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
548 metavar = "number"
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
549 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
550 return(parser)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
551 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
552
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
553 stop_with_status <- function(msg, status) {
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
554 sink(stderr())
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
555 message(sprintf("Error: %s", msg))
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
556 message(sprintf("Error code: %s", status))
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
557 sink(NULL)
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
558 base::quit(status = status)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
559 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
560
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
561 check_args_validity <- function(args) { ## nolint cyclocomp_linter
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
562 sysvars <- Sys.getenv()
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
563 sysvarnames <- names(sysvars)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
564 if (length(args$output) == 0 || nchar(args$output[1]) == 0) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
565 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
566 "Missing output parameters. Please set it with --output.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
567 MISSING_PARAMETER_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
568 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
569 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
570 if (length(args$precursors) == 0 || nchar(args$precursors[1]) == 0) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
571 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
572 "Missing precursors parameters. Please set it with --precursors.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
573 MISSING_PARAMETER_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
574 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
575 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
576 if (length(args$fragments) == 0 || nchar(args$fragments[1]) == 0) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
577 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
578 "Missing fragments parameters. Please set it with --fragments.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
579 MISSING_PARAMETER_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
580 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
581 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
582 if (length(args$compounds) == 0 || nchar(args$compounds[1]) == 0) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
583 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
584 "Missing compounds parameters. Please set it with --compounds.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
585 MISSING_PARAMETER_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
586 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
587 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
588 if (!file.exists(args$precursors)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
589 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
590 sprintf(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
591 "Precursors file %s does not exist or cannot be accessed.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
592 args$precursors
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
593 ),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
594 MISSING_INPUT_FILE_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
595 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
596 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
597 if (!file.exists(args$fragments)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
598 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
599 sprintf(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
600 "Fragments file %s does not exist or cannot be accessed.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
601 args$fragments
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
602 ),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
603 MISSING_INPUT_FILE_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
604 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
605 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
606 if (!file.exists(args$compounds)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
607 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
608 sprintf(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
609 "Compounds file %s does not exist or cannot be accessed.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
610 args$compounds
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
611 ),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
612 MISSING_INPUT_FILE_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
613 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
614 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
615 if (
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
616 "_GALAXY_JOB_HOME_DIR" %in% sysvarnames
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
617 || "_GALAXY_JOB_TMP_DIR" %in% sysvarnames
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
618 || "GALAXY_MEMORY_MB" %in% sysvarnames
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
619 || "GALAXY_MEMORY_MB_PER_SLOT" %in% sysvarnames
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
620 || "GALAXY_SLOTS" %in% sysvarnames
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
621 ) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
622 check_galaxy_args_validity(args)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
623 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
624 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
625
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
626 check_galaxy_args_validity <- function(args) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
627 if (!file.exists(args$output)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
628 stop_with_status(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
629 sprintf(
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
630 "Output file %s does not exist or cannot be accessed.",
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
631 args$output
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
632 ),
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
633 MISSING_INPUT_FILE_ERROR
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
634 )
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
635 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
636 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
637
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
638 get_csv_or_tsv <- function(
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
639 path,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
640 sep_stack = c("\t", ",", ";"),
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
641 header = TRUE,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
642 quote = "\""
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
643 ) {
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
644 sep <- sep_stack[1]
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
645 result <- tryCatch({
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
646 read.table(
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
647 file = path,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
648 sep = sep,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
649 header = header,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
650 quote = quote
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
651 )
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
652 }, error = function(e) {
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
653 return(data.frame())
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
654 })
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
655 if (length(sep_stack) == 1) {
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
656 return(result)
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
657 }
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
658 # if (
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
659 # ncol(result) == 0 || ## failed
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
660 # ncol(result) == 1 ## only one row, suspicious, possible fail # nolint
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
661 # ) {
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
662 new_result <- get_csv_or_tsv(
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
663 path,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
664 sep_stack = sep_stack[-1],
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
665 header = header,
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
666 quote = quote
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
667 )
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
668 if (ncol(new_result) > ncol(result)) {
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
669 return(new_result)
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
670 }
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
671 # }
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
672 return(result)
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
673 }
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
674
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
675 uniformize_columns <- function(df) {
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
676 cols <- colnames(df)
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
677 for (func in c(tolower)) {
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
678 cols <- func(cols)
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
679 }
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
680 colnames(df) <- cols
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
681 return(df)
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
682 }
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
683
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
684 main <- function(args) {
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
685 if (args$version) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
686 cat(sprintf("%s\n", MS2SNOOP_VERSION))
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
687 base::quit(status = 0)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
688 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
689 sessionInfo()
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
690 check_args_validity(args)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
691 if (args$debug) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
692 set_debug()
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
693 }
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
694 if (args$verbose) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
695 set_verbose()
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
696 }
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
697 ## MSpurity precursors file
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
698 precursors <- get_csv_or_tsv(args$precursors)
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
699 ## MSpurity fragments file
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
700 fragments <- get_csv_or_tsv(args$fragments)
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
701 ## list of compounds : col1=Name of molecule, col2=m/z, col3=retention time
3
c68c94865667 planemo upload commit 09540e3a13b630b078a35afd3e129bc18c9953f0
workflow4metabolomics
parents: 1
diff changeset
702 compounds <- get_csv_or_tsv(args$compounds)
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
703
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
704 compounds <- uniformize_columns(compounds)
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
705 mandatory_columns <- c(
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
706 "compound_name",
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
707 "mz",
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
708 "rtsec",
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
709 "inchikey"
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
710 )
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
711 presents <- mandatory_columns %in% colnames(compounds)
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
712 if (!all(presents)) {
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
713 stop_with_status(
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
714 sprintf(
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
715 "Some columns are missing: %s",
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
716 paste(mandatory_columns[which(!presents)], collapse = ", ")
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
717 ),
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
718 BAD_PARAMETER_VALUE_ERROR
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
719 )
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
720 }
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
721
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
722 res_all <- NULL
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
723 for (i in seq_len(nrow(compounds))) {
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
724 ## loop execution for all compounds in the compounds file
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
725 res_cor <- NULL
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
726 res_cor <- extract_fragments(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
727 precursors = precursors,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
728 fragments = fragments,
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
729 mzref = compounds[["mz"]][i],
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
730 rtref = compounds[["rtsec"]][i],
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
731 c_name = compounds[["compound_name"]][i],
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
732 inchikey = compounds[["inchikey"]][i],
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
733 elemcomposition = compounds[["elemcomposition"]][i],
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
734 min_number_scan = args$min_number_scan,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
735 mzdecimal = args$mzdecimal,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
736 r_threshold = args$r_threshold,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
737 seuil_ra = args$seuil_ra,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
738 tolmz = args$tolmz,
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
739 tolrt = args$tolrt
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
740 )
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
741 if (!is.null(res_cor)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
742 if (is.null(res_all)) {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
743 res_all <- res_cor
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
744 } else {
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
745 res_all <- rbind(res_all, res_cor)
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
746 }
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
747 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
748 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
749
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
750 if (is.null(res_all)) {
1
df2672c37732 planemo upload commit 42359ca78388ce5221bc88905a78c996c758aa43
workflow4metabolomics
parents: 0
diff changeset
751 stop_with_status("No result at all!", NO_ANY_RESULT_ERROR)
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
752 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
753 write.table(
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
754 x = res_all,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
755 file = args$output,
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
756 sep = "\t",
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
757 row.names = FALSE
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
758 )
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
759 }
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
760
4
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
761 global_debug <- FALSE
856001213966 planemo upload commit 53543b5d911fc1f2d204f314a4d2aaf93a8c7715
workflow4metabolomics
parents: 3
diff changeset
762 global_verbose <- FALSE
0
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
763 args <- optparse::parse_args(create_parser())
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
764 main(args)
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
765
91a3242fd67f "planemo upload commit c7676a9c7ac542043691d735285ae19e430bf032"
workflow4metabolomics
parents:
diff changeset
766 warnings()