annotate MS2snoop.R @ 0:67733206be53 draft

" master branch Updating"
author lain
date Thu, 14 Apr 2022 10:23:15 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
1 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
2 #' read and process mspurity W4M files
67733206be53 " master branch Updating"
lain
parents:
diff changeset
3 #' create a summary of fragment for each precursor and a graphics of peseudo
67733206be53 " master branch Updating"
lain
parents:
diff changeset
4 #' spectra + correlation on which checking of fragment is based on
67733206be53 " master branch Updating"
lain
parents:
diff changeset
5 #' V3 try to identify and process multiple files for 1 precursor which may
67733206be53 " master branch Updating"
lain
parents:
diff changeset
6 #' occur if different collision energy are used
67733206be53 " master branch Updating"
lain
parents:
diff changeset
7 #' V4 elimination of correlation = NA. Correlation is done with precursor, if
67733206be53 " master branch Updating"
lain
parents:
diff changeset
8 #' precursor is not present correlation with most intense peak
67733206be53 " master branch Updating"
lain
parents:
diff changeset
9 #' author: Jean-Francois Martin
67733206be53 " master branch Updating"
lain
parents:
diff changeset
10 #' V5 is versionned, lintR-compliant, packaged, unit-tested, documented and
67733206be53 " master branch Updating"
lain
parents:
diff changeset
11 #' tested against data from other labs.
67733206be53 " master branch Updating"
lain
parents:
diff changeset
12 #' new maintainer: Lain Pavot - lain.pavot@inrae.fr
67733206be53 " master branch Updating"
lain
parents:
diff changeset
13 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
14 #' @import optparse
67733206be53 " master branch Updating"
lain
parents:
diff changeset
15 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
16 NULL
67733206be53 " master branch Updating"
lain
parents:
diff changeset
17
67733206be53 " master branch Updating"
lain
parents:
diff changeset
18
67733206be53 " master branch Updating"
lain
parents:
diff changeset
19 assign("DEFAULT_PRECURSOR_PATH", "peaklist_precursors.tsv")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
20 assign("DEFAULT_FRAGMENTS_PATH", "peaklist_fragments.tsv")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
21 assign("DEFAULT_COMPOUNDS_PATH", "compounds_pos.txt")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
22 assign("DEFAULT_OUTPUT_PATH", "compound_fragments_result.txt")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
23 assign("DEFAULT_TOLMZ", 0.01)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
24 assign("DEFAULT_TOLRT", 20)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
25 assign("DEFAULT_MZDECIMAL", 0)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
26 assign("DEFAULT_R_THRESHOLD", 0.85)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
27 assign("DEFAULT_MINNUMBERSCAN", 8)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
28 assign("DEFAULT_SEUIL_RA", 0.5)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
29 lockBinding("DEFAULT_PRECURSOR_PATH", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
30 lockBinding("DEFAULT_FRAGMENTS_PATH", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
31 lockBinding("DEFAULT_COMPOUNDS_PATH", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
32 lockBinding("DEFAULT_OUTPUT_PATH", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
33 lockBinding("DEFAULT_TOLMZ", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
34 lockBinding("DEFAULT_TOLRT", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
35 lockBinding("DEFAULT_MZDECIMAL", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
36 lockBinding("DEFAULT_R_THRESHOLD", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
37 lockBinding("DEFAULT_MINNUMBERSCAN", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
38 lockBinding("DEFAULT_SEUIL_RA", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
39
67733206be53 " master branch Updating"
lain
parents:
diff changeset
40 assign("DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD", 0.85)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
41 assign("DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA", 0.1)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
42 assign("DEFAULT_EXTRACT_FRAGMENTS_TOLMZ", 0.01)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
43 assign("DEFAULT_EXTRACT_FRAGMENTS_TOLRT", 60)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
44 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
45 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
46 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_TOLMZ", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
47 lockBinding("DEFAULT_EXTRACT_FRAGMENTS_TOLRT", globalenv())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
48
67733206be53 " master branch Updating"
lain
parents:
diff changeset
49
67733206be53 " master branch Updating"
lain
parents:
diff changeset
50 debug <- FALSE
67733206be53 " master branch Updating"
lain
parents:
diff changeset
51
67733206be53 " master branch Updating"
lain
parents:
diff changeset
52
67733206be53 " master branch Updating"
lain
parents:
diff changeset
53 ########################################################################
67733206be53 " master branch Updating"
lain
parents:
diff changeset
54
67733206be53 " master branch Updating"
lain
parents:
diff changeset
55 #' @title plot_pseudo_spectra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
56 #' @param x
67733206be53 " master branch Updating"
lain
parents:
diff changeset
57 #' @param r_threshold
67733206be53 " master branch Updating"
lain
parents:
diff changeset
58 #' @param fid
67733206be53 " master branch Updating"
lain
parents:
diff changeset
59 #' @param sum_int
67733206be53 " master branch Updating"
lain
parents:
diff changeset
60 #' @param vmz
67733206be53 " master branch Updating"
lain
parents:
diff changeset
61 #' @param cor_abs_int
67733206be53 " master branch Updating"
lain
parents:
diff changeset
62 #' @param refcol
67733206be53 " master branch Updating"
lain
parents:
diff changeset
63 #' @param c_name
67733206be53 " master branch Updating"
lain
parents:
diff changeset
64 #' @description plot_pseudo_spectra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
65 #' function to compute sum of intensities among scans for all
67733206be53 " master branch Updating"
lain
parents:
diff changeset
66 #' m/z kept (cor > r_threshold & minimum number of scans)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
67 #' and plot pseudo spectra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
68 #' x dataframe scan X fragments with scans number in the 1st column and
67733206be53 " master branch Updating"
lain
parents:
diff changeset
69 #' ions in next with intensities
67733206be53 " master branch Updating"
lain
parents:
diff changeset
70 #' fid file id when several a precursor has been detected in several files
67733206be53 " master branch Updating"
lain
parents:
diff changeset
71 plot_pseudo_spectra <- function(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
72 x,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
73 r_threshold,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
74 fid,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
75 sum_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
76 vmz,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
77 cor_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
78 refcol,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
79 c_name
67733206be53 " master branch Updating"
lain
parents:
diff changeset
80 ) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
81 ## du fait de la difference de nombre de colonne entre la dataframe qui
67733206be53 " master branch Updating"
lain
parents:
diff changeset
82 ## inclue les scans en 1ere col, mzRef se decale de 1
67733206be53 " master branch Updating"
lain
parents:
diff changeset
83 refcol <- refcol - 1
67733206be53 " master branch Updating"
lain
parents:
diff changeset
84 ## compute relative intensities max=100%
67733206be53 " master branch Updating"
lain
parents:
diff changeset
85 rel_int <- sum_int[-1]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
86 rel_int <- rel_int / max(rel_int)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
87
67733206be53 " master branch Updating"
lain
parents:
diff changeset
88 ## define max value on vertical axis (need to increase in order to plot the
67733206be53 " master branch Updating"
lain
parents:
diff changeset
89 ## label of fragments)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
90 ymax <- max(rel_int) + 0.2 * max(rel_int)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
91
67733206be53 " master branch Updating"
lain
parents:
diff changeset
92 par(mfrow = c(2, 1))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
93 plot(vmz, rel_int, type = "h", ylim = c(0, ymax), main = c_name)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
94 ## low correl coef. will be display in grey
67733206be53 " master branch Updating"
lain
parents:
diff changeset
95 cor_low <- which(round(cor_abs_int, 2) < r_threshold)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
96
67733206be53 " master branch Updating"
lain
parents:
diff changeset
97 lbmzcor <- sprintf("%s(r=%s)", vmz, round(cor_abs_int, 2))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
98
67733206be53 " master branch Updating"
lain
parents:
diff changeset
99 if (length(cor_low) > 0) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
100 text(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
101 vmz[cor_low],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
102 rel_int[cor_low],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
103 lbmzcor[cor_low],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
104 cex = 0.5,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
105 col = "grey",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
106 srt = 90,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
107 adj = 0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
108 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
109 if (length(vmz) - length(cor_low) > 1) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
110 text(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
111 vmz[-c(refcol, cor_low)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
112 rel_int[-c(refcol, cor_low)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
113 lbmzcor[-c(refcol, cor_low)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
114 cex = 0.6,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
115 col = 1,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
116 srt = 90,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
117 adj = 0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
118 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
119 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
120 } else {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
121 if (length(vmz) > 1) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
122 text(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
123 vmz[-c(refcol)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
124 rel_int[-c(refcol)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
125 lbmzcor[-c(refcol)],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
126 cex = 0.6,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
127 col = 1,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
128 srt = 90,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
129 adj = 0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
130 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
131 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
132 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
133
67733206be53 " master branch Updating"
lain
parents:
diff changeset
134 text(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
135 vmz[refcol],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
136 rel_int[refcol],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
137 lbmzcor[refcol],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
138 cex = 0.8,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
139 col = 2,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
140 srt = 90,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
141 adj = 0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
142 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
143
67733206be53 " master branch Updating"
lain
parents:
diff changeset
144 ## prepare result file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
145 corValid <- (round(cor_abs_int, 2) >= r_threshold) ##nolint object_name_linter
67733206be53 " master branch Updating"
lain
parents:
diff changeset
146 cp_res <- data.frame(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
147 rep(c_name, length(vmz)),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
148 rep(fid, length(vmz)),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
149 vmz,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
150 cor_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
151 sum_int[-1],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
152 rel_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
153 corValid
67733206be53 " master branch Updating"
lain
parents:
diff changeset
154 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
155
67733206be53 " master branch Updating"
lain
parents:
diff changeset
156 colnames(cp_res) <- c(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
157 "compoundName",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
158 "fileid",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
159 "fragments_mz",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
160 "CorWithPrecursor",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
161 "AbsoluteIntensity",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
162 "relativeIntensity",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
163 "corValid"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
164 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
165 return(cp_res)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
166
67733206be53 " master branch Updating"
lain
parents:
diff changeset
167 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
168
67733206be53 " master branch Updating"
lain
parents:
diff changeset
169 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
170 #' @title extract_fragments
67733206be53 " master branch Updating"
lain
parents:
diff changeset
171 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
172 #' @param precursors the precursor list from mspurity
67733206be53 " master branch Updating"
lain
parents:
diff changeset
173 #' @param fragments the fragments list from ms purity
67733206be53 " master branch Updating"
lain
parents:
diff changeset
174 #' @param mzref
67733206be53 " master branch Updating"
lain
parents:
diff changeset
175 #' @param rtref
67733206be53 " master branch Updating"
lain
parents:
diff changeset
176 #' @param c_name
67733206be53 " master branch Updating"
lain
parents:
diff changeset
177 #' @param r_threshold default = DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD
67733206be53 " master branch Updating"
lain
parents:
diff changeset
178 #' @param seuil_ra default = DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA
67733206be53 " master branch Updating"
lain
parents:
diff changeset
179 #' @param tolmz default = DEFAULT_EXTRACT_FRAGMENTS_TOLMZ
67733206be53 " master branch Updating"
lain
parents:
diff changeset
180 #' @param tolrt default = DEFAULT_EXTRACT_FRAGMENTS_TOLRT
67733206be53 " master branch Updating"
lain
parents:
diff changeset
181 #' @returns
67733206be53 " master branch Updating"
lain
parents:
diff changeset
182 #'
67733206be53 " master branch Updating"
lain
parents:
diff changeset
183 #' @description
67733206be53 " master branch Updating"
lain
parents:
diff changeset
184 #' function for extraction of fragments corresponding to precursors
67733206be53 " master branch Updating"
lain
parents:
diff changeset
185 #' detected by MSPurity
67733206be53 " master branch Updating"
lain
parents:
diff changeset
186 extract_fragments <- function( ## nolint cyclocomp_linter
67733206be53 " master branch Updating"
lain
parents:
diff changeset
187 precursors,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
188 fragments,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
189 mzref,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
190 rtref,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
191 c_name,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
192 min_number_scan,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
193 mzdecimal,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
194 r_threshold=DEFAULT_EXTRACT_FRAGMENTS_R_THRESHOLD,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
195 seuil_ra=DEFAULT_EXTRACT_FRAGMENTS_SEUIL_RA,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
196 tolmz=DEFAULT_EXTRACT_FRAGMENTS_TOLMZ,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
197 tolrt=DEFAULT_EXTRACT_FRAGMENTS_TOLRT
67733206be53 " master branch Updating"
lain
parents:
diff changeset
198 ) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
199 ## filter precursor in the precursors file based on mz and rt in the
67733206be53 " master branch Updating"
lain
parents:
diff changeset
200 ## compound list
67733206be53 " master branch Updating"
lain
parents:
diff changeset
201 cat("processing ", c_name, "\n")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
202 selected_precursors <- which(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
203 (abs(precursors$precurMtchMZ - mzref) <= tolmz)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
204 & (abs(precursors$precurMtchRT - rtref) <= tolrt)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
205 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
206
67733206be53 " master branch Updating"
lain
parents:
diff changeset
207 ## check if there is the precursor in the file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
208 if (length(selected_precursors) > 0) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
209
67733206be53 " master branch Updating"
lain
parents:
diff changeset
210 sprecini <- precursors[selected_precursors, ]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
211
67733206be53 " master branch Updating"
lain
parents:
diff changeset
212 ## check if fragments corresponding to precursor are found in several
67733206be53 " master branch Updating"
lain
parents:
diff changeset
213 ## files (collision energy)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
214 ## this lead to a processing for each fileid
67733206be53 " master branch Updating"
lain
parents:
diff changeset
215 mf <- levels(as.factor(sprecini$fileid))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
216 if (length(mf) > 1) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
217 cat(" several files detected for this compounds :\n")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
218 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
219
67733206be53 " master branch Updating"
lain
parents:
diff changeset
220 for (f in seq_along(mf)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
221
67733206be53 " master branch Updating"
lain
parents:
diff changeset
222 sprec <- sprecini[sprecini$fileid == mf[f], ]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
223
67733206be53 " master branch Updating"
lain
parents:
diff changeset
224 ## selection of fragment in the fragments file with the grpid common in
67733206be53 " master branch Updating"
lain
parents:
diff changeset
225 ## both fragments and precursors
67733206be53 " master branch Updating"
lain
parents:
diff changeset
226 selfrgt <- levels(as.factor(sprec$grpid))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
227 sfrgt <- fragments[
67733206be53 " master branch Updating"
lain
parents:
diff changeset
228 fragments$grpid %in% selfrgt
67733206be53 " master branch Updating"
lain
parents:
diff changeset
229 & fragments$fileid == mf[f],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
230 ]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
231
67733206be53 " master branch Updating"
lain
parents:
diff changeset
232 ## filter fragments on relative intensity seuil_ra = user defined
67733206be53 " master branch Updating"
lain
parents:
diff changeset
233 ## parameter (MSpurity flags could be used here)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
234 sfrgtfil <- sfrgt[sfrgt$ra > seuil_ra, ]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
235
67733206be53 " master branch Updating"
lain
parents:
diff changeset
236 mznominal <- round(x = sfrgtfil$mz, mzdecimal)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
237 sfrgtfil <- data.frame(sfrgtfil, mznominal)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
238
67733206be53 " master branch Updating"
lain
parents:
diff changeset
239 ## creation of cross table row=scan col=mz X=ra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
240 vmz <- levels(as.factor(sfrgtfil$mznominal))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
241
67733206be53 " master branch Updating"
lain
parents:
diff changeset
242 cat(" fragments :", vmz)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
243
67733206be53 " master branch Updating"
lain
parents:
diff changeset
244 ## mz of precursor in data precursor to check correlation with
67733206be53 " master branch Updating"
lain
parents:
diff changeset
245 mz_prec <- paste0("mz", round(mean(sprec$mz), mzdecimal))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
246
67733206be53 " master branch Updating"
lain
parents:
diff changeset
247 for (m in seq_along(vmz)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
248
67733206be53 " master branch Updating"
lain
parents:
diff changeset
249 ## absolute intensity
67733206be53 " master branch Updating"
lain
parents:
diff changeset
250 cln <- c(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
251 which(colnames(sfrgtfil) == "acquisitionNum"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
252 which(colnames(sfrgtfil) == "i")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
253 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
254 int_mz <- sfrgtfil[sfrgtfil$mznominal == vmz[m], cln]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
255 colnames(int_mz)[2] <- paste0("mz", vmz[m])
67733206be53 " master branch Updating"
lain
parents:
diff changeset
256
67733206be53 " master branch Updating"
lain
parents:
diff changeset
257 ## average intensities of mass in duplicate scans
67733206be53 " master branch Updating"
lain
parents:
diff changeset
258 comp_scans <- aggregate(x = int_mz, by = list(int_mz[[1]]), FUN = mean)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
259 int_mz <- comp_scans[, -1]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
260
67733206be53 " master branch Updating"
lain
parents:
diff changeset
261 if (m == 1) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
262 ds_abs_int <- int_mz
67733206be53 " master branch Updating"
lain
parents:
diff changeset
263 } else {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
264 ds_abs_int <- merge(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
265 x = ds_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
266 y = int_mz,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
267 by.x = 1,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
268 by.y = 1,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
269 all.x = TRUE,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
270 all.y = TRUE
67733206be53 " master branch Updating"
lain
parents:
diff changeset
271 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
272 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
273 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
274 if (debug) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
275 write.table(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
276 x = ds_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
277 file = paste0(c_name, "ds_abs_int.txt"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
278 row.names = FALSE,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
279 sep = "\t"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
280 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
281 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
282
67733206be53 " master branch Updating"
lain
parents:
diff changeset
283 ## elimination of mz with less than min_number_scan scans (user defined
67733206be53 " master branch Updating"
lain
parents:
diff changeset
284 ## parameter)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
285 xmz <- rep(NA, ncol(ds_abs_int) - 1)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
286 sum_int <- rep(NA, ncol(ds_abs_int))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
287 nbxmz <- 0
67733206be53 " master branch Updating"
lain
parents:
diff changeset
288 nb_scan_check <- min(nrow(ds_abs_int), min_number_scan)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
289
67733206be53 " master branch Updating"
lain
parents:
diff changeset
290 for (j in 2:ncol(ds_abs_int)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
291 sum_int[j] <- sum(ds_abs_int[j], na.rm = TRUE)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
292 if (sum(!is.na(ds_abs_int[[j]])) < nb_scan_check) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
293 nbxmz <- nbxmz + 1
67733206be53 " master branch Updating"
lain
parents:
diff changeset
294 xmz[nbxmz] <- j
67733206be53 " master branch Updating"
lain
parents:
diff changeset
295 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
296 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
297
67733206be53 " master branch Updating"
lain
parents:
diff changeset
298 xmz <- xmz[-which(is.na(xmz))]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
299 if (length(xmz) > 0) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
300 ds_abs_int <- ds_abs_int[, -c(xmz)]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
301 sum_int <- sum_int[-c(xmz)]
67733206be53 " master branch Updating"
lain
parents:
diff changeset
302 ## liste des mz keeped decale de 1 avec ds_abs_int
67733206be53 " master branch Updating"
lain
parents:
diff changeset
303 vmz <- as.numeric(vmz[-c(xmz - 1)])
67733206be53 " master branch Updating"
lain
parents:
diff changeset
304 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
305
67733206be53 " master branch Updating"
lain
parents:
diff changeset
306 ## reference ion for correlation computing = precursor OR maximum
67733206be53 " master branch Updating"
lain
parents:
diff changeset
307 ## intensity ion in precursor is not present
67733206be53 " master branch Updating"
lain
parents:
diff changeset
308 refcol <- which(colnames(ds_abs_int) == mz_prec)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
309 if (length(refcol) == 0) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
310 refcol <- which(sum_int == max(sum_int, na.rm = TRUE))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
311 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
312 pdf(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
313 file = sprintf("%s_processing_file%s.pdf", c_name, mf[f]),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
314 width = 8,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
315 height = 11
67733206be53 " master branch Updating"
lain
parents:
diff changeset
316 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
317 par(mfrow = c(3, 2))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
318
67733206be53 " master branch Updating"
lain
parents:
diff changeset
319 ## Pearson correlations between absolute intensities computing
67733206be53 " master branch Updating"
lain
parents:
diff changeset
320 cor_abs_int <- rep(NA, length(vmz))
67733206be53 " master branch Updating"
lain
parents:
diff changeset
321
67733206be53 " master branch Updating"
lain
parents:
diff changeset
322 if (length(refcol) > 0) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
323 for (i in 2:length(ds_abs_int)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
324 cor_abs_int[i - 1] <- cor(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
325 x = ds_abs_int[[refcol]],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
326 y = ds_abs_int[[i]],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
327 use = "pairwise.complete.obs",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
328 method = "pearson"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
329 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
330 plot(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
331 ds_abs_int[[refcol]],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
332 ds_abs_int[[i]],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
333 xlab = colnames(ds_abs_int)[refcol],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
334 ylab = colnames(ds_abs_int)[i],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
335 main = sprintf(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
336 "%s corr coeff r=%s", c_name, round(cor_abs_int[i - 1], 2)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
337 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
338 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
339 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
340 ## plot pseudo spectra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
341 res_comp_by_file <- plot_pseudo_spectra(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
342 x = ds_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
343 r_threshold = r_threshold,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
344 fid = mf[f],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
345 sum_int = sum_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
346 vmz = vmz,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
347 cor_abs_int = cor_abs_int,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
348 refcol = refcol,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
349 c_name = c_name
67733206be53 " master branch Updating"
lain
parents:
diff changeset
350 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
351 if (f == 1) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
352 res_comp <- res_comp_by_file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
353 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
354 } else {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
355 res_comp_by_file <- NULL
67733206be53 " master branch Updating"
lain
parents:
diff changeset
356 cat(" non detected in fragments file \n")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
357 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
358 if (!is.null(res_comp_by_file)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
359 res_comp <- rbind(res_comp, res_comp_by_file)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
360 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
361 cat("\n")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
362 dev.off()
67733206be53 " master branch Updating"
lain
parents:
diff changeset
363 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
364 } else {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
365 res_comp <- NULL
67733206be53 " master branch Updating"
lain
parents:
diff changeset
366 cat(" non detected in precursor file \n")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
367 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
368 return(res_comp)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
369 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
370
67733206be53 " master branch Updating"
lain
parents:
diff changeset
371
67733206be53 " master branch Updating"
lain
parents:
diff changeset
372 create_parser <- function() {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
373 parser <- optparse::OptionParser()
67733206be53 " master branch Updating"
lain
parents:
diff changeset
374 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
375 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
376 c("-v", "--verbose"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
377 action = "store_true",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
378 default = FALSE,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
379 help = "Print extra output [default %default]"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
380 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
381 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
382 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
383 c("-o", "--output"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
384 type = "character",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
385 default = DEFAULT_OUTPUT_PATH,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
386 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
387 help = "Path to the output file [default %default]"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
388 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
389 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
390 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
391 c("-p", "--precursors"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
392 type = "character",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
393 default = DEFAULT_PRECURSOR_PATH,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
394 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
395 help = "Path to the precursors file [default %default]"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
396 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
397 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
398 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
399 c("-f", "--fragments"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
400 type = "character",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
401 default = DEFAULT_FRAGMENTS_PATH,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
402 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
403 help = "Path to the fragments file [default %default]"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
404 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
405 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
406 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
407 c("-c", "--compounds"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
408 type = "character",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
409 default = DEFAULT_COMPOUNDS_PATH,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
410 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
411 help = "Path to the compounds file [default %default]"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
412 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
413 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
414 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
415 c("--tolmz"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
416 type = "numeric",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
417 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
418 default = DEFAULT_TOLMZ,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
419 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
420 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
421 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
422 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
423 c("--tolrt"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
424 type = "integer",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
425 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
426 default = DEFAULT_TOLRT,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
427 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
428 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
429 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
430 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
431 c("--seuil_ra"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
432 type = "numeric",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
433 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
434 help = "relative intensity threshold",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
435 default = DEFAULT_SEUIL_RA,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
436 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
437 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
438 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
439 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
440 c("--mzdecimal"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
441 type = "integer",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
442 default = DEFAULT_MZDECIMAL,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
443 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
444 help = "nb decimal for mz",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
445 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
446 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
447 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
448 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
449 c("--r_threshold"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
450 type = "integer",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
451 default = DEFAULT_R_THRESHOLD,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
452 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
453 help = paste0(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
454 "r pearson correlation threshold between precursor and fragment ",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
455 "absolute intensity"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
456 ),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
457 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
458 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
459 parser <- optparse::add_option(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
460 parser,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
461 c("--min_number_scan"),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
462 type = "numeric",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
463 action = "store",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
464 default = DEFAULT_MINNUMBERSCAN,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
465 help = paste0(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
466 "fragments are kept if there are found in a minimum number ",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
467 "of scans"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
468 ),
67733206be53 " master branch Updating"
lain
parents:
diff changeset
469 metavar = "number"
67733206be53 " master branch Updating"
lain
parents:
diff changeset
470 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
471 return(parser)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
472 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
473
67733206be53 " master branch Updating"
lain
parents:
diff changeset
474 main <- function(args) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
475 ## FOLDER AND FILES
67733206be53 " master branch Updating"
lain
parents:
diff changeset
476 ## MSpurity precursors file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
477 precursors <- read.table(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
478 file = args$precursors,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
479 header = TRUE,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
480 sep = "\t",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
481 quote = "\""
67733206be53 " master branch Updating"
lain
parents:
diff changeset
482 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
483 ## MSpurity fragments file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
484 fragments <- read.table(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
485 file = args$fragments,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
486 header = TRUE,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
487 sep = "\t",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
488 quote = "\""
67733206be53 " master branch Updating"
lain
parents:
diff changeset
489 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
490 ## list of compounds : col1=Name of molecule, col2=m/z, col3=retention time
67733206be53 " master branch Updating"
lain
parents:
diff changeset
491 compounds <- read.table(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
492 file = args$compounds,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
493 sep = "\t",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
494 quote = "\"",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
495 header = TRUE
67733206be53 " master branch Updating"
lain
parents:
diff changeset
496 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
497 ## PARAMETERS
67733206be53 " master branch Updating"
lain
parents:
diff changeset
498 ## tolerance for mz(dalton) rt(seconds) to match the standard in the compounds
67733206be53 " master branch Updating"
lain
parents:
diff changeset
499 ## list with the precursor MSpurity file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
500 tolmz <- args$tolmz
67733206be53 " master branch Updating"
lain
parents:
diff changeset
501 tolrt <- args$tolrt
67733206be53 " master branch Updating"
lain
parents:
diff changeset
502
67733206be53 " master branch Updating"
lain
parents:
diff changeset
503 ## relative intensity threshold
67733206be53 " master branch Updating"
lain
parents:
diff changeset
504 seuil_ra <- args$seuil_ra
67733206be53 " master branch Updating"
lain
parents:
diff changeset
505 ## nb decimal for mz
67733206be53 " master branch Updating"
lain
parents:
diff changeset
506 mzdecimal <- args$mzdecimal
67733206be53 " master branch Updating"
lain
parents:
diff changeset
507 ## r pearson correlation threshold between precursor and
67733206be53 " master branch Updating"
lain
parents:
diff changeset
508 # #fragment absolute intensity
67733206be53 " master branch Updating"
lain
parents:
diff changeset
509 r_threshold <- args$r_threshold
67733206be53 " master branch Updating"
lain
parents:
diff changeset
510 ## fragments are kept if there are found in a minimum number of scans
67733206be53 " master branch Updating"
lain
parents:
diff changeset
511 min_number_scan <- args$min_number_scan
67733206be53 " master branch Updating"
lain
parents:
diff changeset
512
67733206be53 " master branch Updating"
lain
parents:
diff changeset
513 for (i in seq_len(nrow(compounds))) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
514 ## loop execution for all compounds in the compounds file
67733206be53 " master branch Updating"
lain
parents:
diff changeset
515 res_cor <- NULL
67733206be53 " master branch Updating"
lain
parents:
diff changeset
516 res_cor <- extract_fragments(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
517 precursors = precursors,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
518 fragments = fragments,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
519 mzref = compounds[[2]][i],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
520 rtref = compounds[[3]][i] * 60,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
521 c_name = compounds[[1]][i],
67733206be53 " master branch Updating"
lain
parents:
diff changeset
522 min_number_scan = min_number_scan,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
523 mzdecimal = mzdecimal,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
524 r_threshold = r_threshold,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
525 seuil_ra = seuil_ra,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
526 tolmz = tolmz,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
527 tolrt = tolrt
67733206be53 " master branch Updating"
lain
parents:
diff changeset
528 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
529 if (i == 1 & !is.null(res_cor)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
530 res_all <- res_cor
67733206be53 " master branch Updating"
lain
parents:
diff changeset
531 } else if (!is.null(res_cor)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
532 res_all <- rbind(res_all, res_cor)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
533 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
534 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
535
67733206be53 " master branch Updating"
lain
parents:
diff changeset
536 if (is.null(res_all)) {
67733206be53 " master branch Updating"
lain
parents:
diff changeset
537 stop("No result at all!")
67733206be53 " master branch Updating"
lain
parents:
diff changeset
538 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
539 write.table(
67733206be53 " master branch Updating"
lain
parents:
diff changeset
540 x = res_all,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
541 file = args$output,
67733206be53 " master branch Updating"
lain
parents:
diff changeset
542 sep = "\t",
67733206be53 " master branch Updating"
lain
parents:
diff changeset
543 row.names = FALSE
67733206be53 " master branch Updating"
lain
parents:
diff changeset
544 )
67733206be53 " master branch Updating"
lain
parents:
diff changeset
545 }
67733206be53 " master branch Updating"
lain
parents:
diff changeset
546
67733206be53 " master branch Updating"
lain
parents:
diff changeset
547 args <- optparse::parse_args(create_parser())
67733206be53 " master branch Updating"
lain
parents:
diff changeset
548 sessionInfo()
67733206be53 " master branch Updating"
lain
parents:
diff changeset
549 main(args)
67733206be53 " master branch Updating"
lain
parents:
diff changeset
550
67733206be53 " master branch Updating"
lain
parents:
diff changeset
551 warnings()