libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
precursor.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/core/processing/cbor/mzcbor/precursor.h
3 * \date 24/11/2025
4 * \author Olivier Langella
5 * \brief PSI precursor object for mzML/mzCBOR
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28
29#include "precursor.h"
31
32
33void
35{
36 QString txt_value;
37 reader.enterContainer();
38 qDebug() << txt_value;
39 while(reader.hasNext() && (!reader.isInvalid()))
40 {
41 if(reader.isString())
42 {
43 if(reader.decodeString(txt_value))
44 {
45 qDebug() << txt_value;
46 if(txt_value == "cvParam")
47 {
48 cvParamMap.fromCbor(reader);
49 // reader.next();
50 }
51 else
52 {
53 reader.next();
54 }
55 }
56 else
57 {
58 reader.next();
59 }
60 }
61 else
62 {
63 reader.next();
64 }
65 }
66 reader.leaveContainer();
67}
68
69double
71{
72 auto it = cvParamMap.find("MS:1000827");
73
74 if(it == cvParamMap.end())
75 {
77 QObject::tr("isolation window target m/z MS:1000827 not found in cvParam map"));
78 }
79
80 return it->second.valueDouble;
81}
82
83double
85{
86 double mz = getTargetMz();
87
88 auto it = cvParamMap.find("MS:1000828");
89
90 if(it == cvParamMap.end())
91 {
93 QObject::tr("isolation window lower offset MS:1000828 not found in cvParam map"));
94 }
95
96 return mz - it->second.valueDouble;
97}
98
99QJsonObject
101{
102 QJsonObject isolationWindow;
103 isolationWindow.insert("cvParam", cvParamMap.toJsonArray());
104 return isolationWindow;
105}
106QJsonObject
108{
109 QJsonObject precursor;
110 if(!spectrumRef.isEmpty())
111 precursor.insert("spectrumRef", spectrumRef);
112 precursor.insert("isolationWindow", isolationWindow.toJsonObject());
113 return precursor;
114}
115
116double
118{
119
120 double mz = getTargetMz();
121
122 auto it = cvParamMap.find("MS:1000829");
123
124 if(it == cvParamMap.end())
125 {
127 QObject::tr("isolation window upper offset MS:1000829 not found in cvParam map"));
128 }
129
130 return mz + it->second.valueDouble;
131}
132
133void
135{
136 QString txt_value;
137 reader.enterContainer();
138 qDebug() << txt_value;
139 while(reader.hasNext() && (!reader.isInvalid()))
140 {
141 if(reader.isString())
142 {
143 if(reader.decodeString(txt_value))
144 {
145 qDebug() << txt_value;
146 if(txt_value == "cvParam")
147 {
148 cvParamMap.fromCbor(reader);
149 // reader.next();
150 }
151 else
152 {
153 reader.next();
154 }
155 }
156 else
157 {
158 reader.next();
159 }
160 }
161 else
162 {
163 reader.next();
164 }
165 }
166 reader.leaveContainer();
167}
168
169
170int
172{
173
174 // <cvParam cvRef="MS" accession="MS:1000041" value="3" name="charge state" />
175
176 auto it = cvParamMap.find("MS:1000041");
177 if(it == cvParamMap.end())
178 {
180 QObject::tr("Charge state not found in SelectedIon cvParam map"));
181 }
182 qDebug() << it->first << " " << it->second.valueInt;
183 return it->second.valueInt;
184}
185
186double
188{
189
190 // <cvParam cvRef="MS" accession="MS:1000042" value="248032.25" name="peak intensity"
191 // unitAccession="MS:1000131" unitName="number of detector counts" unitCvRef="MS" />
192 // MS:1000042
193 auto it = cvParamMap.find("MS:1000042");
194 if(it == cvParamMap.end())
195 {
196 // throw pappso::ExceptionNotFound(
197 // QObject::tr("Intensity not found in SelectedIon cvParam map"));
198 *isok = false;
199 return 0;
200 }
201 qDebug() << it->first << " " << it->second.valueDouble;
202 double intensity = it->second.valueDouble;
203 *isok = true;
204 if(std::isnan(intensity))
205 {
206 return it->second.valueInt;
207 }
208 return intensity;
209}
210
211double
213{
214
215 // <cvParam cvRef="MS" accession="MS:1000744" value="506.2513" name="selected ion m/z"
216 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
217
218 auto it = cvParamMap.find("MS:1000744");
219 if(it == cvParamMap.end())
220 {
221 throw pappso::ExceptionNotFound(QObject::tr("m/z not found in SelectedIon cvParam map"));
222 }
223 qDebug() << it->first << " " << it->second.valueDouble;
224 return it->second.valueDouble;
225}
226
227
228void
230{
231
232 QString txt_value;
233 reader.enterContainer();
234 qDebug() << txt_value;
235 while(reader.hasNext() && (!reader.isInvalid()))
236 {
237 if(reader.isString())
238 {
239 if(reader.decodeString(txt_value))
240 {
241 qDebug() << txt_value;
242 if(txt_value == "cvParam")
243 {
244 // precursorListCvParamMap = CvParam::getCvParamsMapFromCbor(reader);
245 reader.next();
246 }
247 else if(txt_value == "isolationWindow")
248 {
249 isolationWindow.fromCbor(reader);
250 }
251 else if(txt_value == "selectedIonList")
252 {
253
254 reader.enterContainer();
255
256 while(reader.hasNext() && (!reader.isInvalid()))
257 {
258 if(reader.isString())
259 {
260 if(reader.decodeString(txt_value))
261 {
262 qDebug() << txt_value;
263 if(txt_value == "cvParam")
264 {
265 selectedIonListCvParamMap.fromCbor(reader);
266 }
267 else if(txt_value == "selectedIon")
268 {
269
270 reader.enterContainer(); // array
271
272 while(reader.hasNext() && (!reader.isInvalid()))
273 {
274 SelectedIon selected_ion;
275 selected_ion.fromCbor(reader);
276 selectedIonList.emplace_back(selected_ion);
277 }
278 reader.leaveContainer(); // array
279 }
280 else
281 {
282 reader.next();
283 }
284 }
285 else
286 {
287 reader.next();
288 }
289 }
290 else
291 {
292 reader.next();
293 }
294 }
295 reader.leaveContainer();
296 }
297 else if(txt_value == "activation")
298 {
299 qDebug();
300 reader.next();
301 }
302
303 else if(txt_value == "spectrumRef")
304 {
305 reader.decodeString(txt_value);
306 qDebug() << txt_value;
307 spectrumRef = txt_value;
308 }
309 else
310 {
311 reader.next();
312 }
313 }
314 else
315 {
316 reader.next();
317 }
318 }
319 else
320 {
321 reader.next();
322 }
323 }
324 reader.leaveContainer();
325}
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...
bool decodeString(QString &the_str)
decode the current cbor value as a string the point to the next value the current value is decoded as...
PSI precursor object for mzML/mzCBOR.
double getUpperMz() const
compute isolation window upper m/z given cvParam informations
double getLowerMz() const
compute isolation window lower m/z given cvParam informations
Definition precursor.cpp:84
double getTargetMz() const
get isolation window target m/z given cvParam informations
Definition precursor.cpp:70
QJsonObject toJsonObject() const
write the structure to a JSON object
void fromCbor(CborStreamReader &reader)
Definition precursor.cpp:34
IsolationWindow isolationWindow
Definition precursor.h:93
QJsonObject toJsonObject() const
write the structure to a JSON object
std::vector< SelectedIon > selectedIonList
Definition precursor.h:97
void fromCbor(CborStreamReader &reader)
void fromCbor(CborStreamReader &reader)
double getIntensity(bool *isok) const