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
186qint64
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
193 auto it = cvParamMap.find("MS:1000042");
194 if(it == cvParamMap.end())
195 {
197 QObject::tr("Intensity not found in SelectedIon cvParam map"));
198 }
199 qDebug() << it->first << " " << it->second.valueInt;
200 return it->second.valueInt;
201}
202
203double
205{
206
207 // <cvParam cvRef="MS" accession="MS:1000744" value="506.2513" name="selected ion m/z"
208 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
209
210 auto it = cvParamMap.find("MS:1000744");
211 if(it == cvParamMap.end())
212 {
213 throw pappso::ExceptionNotFound(QObject::tr("m/z not found in SelectedIon cvParam map"));
214 }
215 qDebug() << it->first << " " << it->second.valueDouble;
216 return it->second.valueDouble;
217}
218
219
220void
222{
223
224 QString txt_value;
225 reader.enterContainer();
226 qDebug() << txt_value;
227 while(reader.hasNext() && (!reader.isInvalid()))
228 {
229 if(reader.isString())
230 {
231 if(reader.decodeString(txt_value))
232 {
233 qDebug() << txt_value;
234 if(txt_value == "cvParam")
235 {
236 // precursorListCvParamMap = CvParam::getCvParamsMapFromCbor(reader);
237 reader.next();
238 }
239 else if(txt_value == "isolationWindow")
240 {
241 isolationWindow.fromCbor(reader);
242 }
243 else if(txt_value == "selectedIonList")
244 {
245
246 reader.enterContainer();
247
248 while(reader.hasNext() && (!reader.isInvalid()))
249 {
250 if(reader.isString())
251 {
252 if(reader.decodeString(txt_value))
253 {
254 qDebug() << txt_value;
255 if(txt_value == "cvParam")
256 {
257 selectedIonListCvParamMap.fromCbor(reader);
258 }
259 else if(txt_value == "selectedIon")
260 {
261
262 reader.enterContainer(); // array
263
264 while(reader.hasNext() && (!reader.isInvalid()))
265 {
266 SelectedIon selected_ion;
267 selected_ion.fromCbor(reader);
268 selectedIonList.emplace_back(selected_ion);
269 }
270 reader.leaveContainer(); // array
271 }
272 else
273 {
274 reader.next();
275 }
276 }
277 else
278 {
279 reader.next();
280 }
281 }
282 else
283 {
284 reader.next();
285 }
286 }
287 reader.leaveContainer();
288 }
289 else if(txt_value == "activation")
290 {
291 qDebug();
292 reader.next();
293 }
294
295 else if(txt_value == "spectrumRef")
296 {
297 reader.decodeString(txt_value);
298 qDebug() << txt_value;
299 spectrumRef = txt_value;
300 }
301 else
302 {
303 reader.next();
304 }
305 }
306 else
307 {
308 reader.next();
309 }
310 }
311 else
312 {
313 reader.next();
314 }
315 }
316 reader.leaveContainer();
317}
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)