libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
"
30
#include "
pappsomspp/core/exception/exceptionnotfound.h
"
31
#include <cmath>
32
33
34
void
35
pappso::cbor::mzcbor::IsolationWindow::fromQCborMap
(
const
QCborMap &cbor_map)
36
{
37
QString txt_value;
38
for
(
auto
it_binarr = cbor_map.cbegin(); it_binarr != cbor_map.cend(); it_binarr++)
39
{
40
txt_value = it_binarr.key().toString();
41
qDebug() << txt_value;
42
if
(txt_value ==
"cvParam"
)
43
{
44
cvParamMap
.fromQCborArray(it_binarr.value().toArray());
45
// reader.next();
46
}
47
}
48
}
49
void
50
pappso::cbor::mzcbor::IsolationWindow::fromCbor
(
CborStreamReader
&reader)
51
{
52
QString txt_value;
53
reader.enterContainer();
54
qDebug() << txt_value;
55
while
(reader.hasNext() && (!reader.isInvalid()))
56
{
57
if
(reader.isString())
58
{
59
if
(reader.
decodeString
(txt_value))
60
{
61
qDebug() << txt_value;
62
if
(txt_value ==
"cvParam"
)
63
{
64
cvParamMap
.fromCbor(reader);
65
// reader.next();
66
}
67
else
68
{
69
reader.next();
70
}
71
}
72
else
73
{
74
reader.next();
75
}
76
}
77
else
78
{
79
reader.next();
80
}
81
}
82
reader.leaveContainer();
83
}
84
85
double
86
pappso::cbor::mzcbor::IsolationWindow::getTargetMz
()
const
87
{
88
auto
it =
cvParamMap
.find(
"MS:1000827"
);
89
90
if
(it ==
cvParamMap
.end())
91
{
92
throw
pappso::ExceptionNotFound
(
93
QObject::tr(
"isolation window target m/z MS:1000827 not found in cvParam map"
));
94
}
95
96
if
(std::isnan(it->second.valueDouble))
97
{
98
return
(
double
)it->second.valueInt;
99
}
100
return
it->second.valueDouble;
101
}
102
103
double
104
pappso::cbor::mzcbor::IsolationWindow::getLowerMz
()
const
105
{
106
double
mz =
getTargetMz
();
107
108
auto
it =
cvParamMap
.find(
"MS:1000828"
);
109
110
if
(it ==
cvParamMap
.end())
111
{
112
throw
pappso::ExceptionNotFound
(
113
QObject::tr(
"isolation window lower offset MS:1000828 not found in cvParam map"
));
114
}
115
116
if
(std::isnan(it->second.valueDouble))
117
{
118
return
mz - (double)it->second.valueInt;
119
}
120
return
mz - it->second.valueDouble;
121
}
122
123
QJsonObject
124
pappso::cbor::mzcbor::IsolationWindow::toJsonObject
()
const
125
{
126
QJsonObject isolationWindow;
127
isolationWindow.insert(
"cvParam"
,
cvParamMap
.toJsonArray());
128
return
isolationWindow;
129
}
130
QJsonObject
131
pappso::cbor::mzcbor::Precursor::toJsonObject
()
const
132
{
133
QJsonObject precursor;
134
if
(!
spectrumRef
.isEmpty())
135
precursor.insert(
"spectrumRef"
,
spectrumRef
);
136
precursor.insert(
"isolationWindow"
,
isolationWindow
.toJsonObject());
137
return
precursor;
138
}
139
140
double
141
pappso::cbor::mzcbor::IsolationWindow::getUpperMz
()
const
142
{
143
144
double
mz =
getTargetMz
();
145
146
auto
it =
cvParamMap
.find(
"MS:1000829"
);
147
148
if
(it ==
cvParamMap
.end())
149
{
150
throw
pappso::ExceptionNotFound
(
151
QObject::tr(
"isolation window upper offset MS:1000829 not found in cvParam map"
));
152
}
153
154
if
(std::isnan(it->second.valueDouble))
155
{
156
return
mz + (double)it->second.valueInt;
157
}
158
return
mz + it->second.valueDouble;
159
}
160
161
void
162
pappso::cbor::mzcbor::SelectedIon::fromQCborMap
(
const
QCborMap &cbor_map)
163
{
164
QString txt_value;
165
for
(
auto
it_binarr = cbor_map.cbegin(); it_binarr != cbor_map.cend(); it_binarr++)
166
{
167
txt_value = it_binarr.key().toString();
168
qDebug() << txt_value;
169
if
(txt_value ==
"cvParam"
)
170
{
171
cvParamMap
.fromQCborArray(it_binarr.value().toArray());
172
// reader.next();
173
}
174
}
175
}
176
void
177
pappso::cbor::mzcbor::SelectedIon::fromCbor
(
CborStreamReader
&reader)
178
{
179
QString txt_value;
180
reader.enterContainer();
181
qDebug() << txt_value;
182
while
(reader.hasNext() && (!reader.isInvalid()))
183
{
184
if
(reader.isString())
185
{
186
if
(reader.
decodeString
(txt_value))
187
{
188
qDebug() << txt_value;
189
if
(txt_value ==
"cvParam"
)
190
{
191
cvParamMap
.fromCbor(reader);
192
// reader.next();
193
}
194
else
195
{
196
reader.next();
197
}
198
}
199
else
200
{
201
reader.next();
202
}
203
}
204
else
205
{
206
reader.next();
207
}
208
}
209
reader.leaveContainer();
210
}
211
212
213
int
214
pappso::cbor::mzcbor::SelectedIon::getChargeState
()
const
215
{
216
217
// <cvParam cvRef="MS" accession="MS:1000041" value="3" name="charge state" />
218
219
auto
it =
cvParamMap
.find(
"MS:1000041"
);
220
if
(it ==
cvParamMap
.end())
221
{
222
throw
pappso::ExceptionNotFound
(
223
QObject::tr(
"Charge state not found in SelectedIon cvParam map"
));
224
}
225
qDebug() << it->first <<
" "
<< it->second.valueInt;
226
return
it->second.valueInt;
227
}
228
229
double
230
pappso::cbor::mzcbor::SelectedIon::getIntensity
(
bool
*isok)
const
231
{
232
233
// <cvParam cvRef="MS" accession="MS:1000042" value="248032.25" name="peak intensity"
234
// unitAccession="MS:1000131" unitName="number of detector counts" unitCvRef="MS" />
235
// MS:1000042
236
auto
it =
cvParamMap
.find(
"MS:1000042"
);
237
if
(it ==
cvParamMap
.end())
238
{
239
// throw pappso::ExceptionNotFound(
240
// QObject::tr("Intensity not found in SelectedIon cvParam map"));
241
*isok =
false
;
242
return
0;
243
}
244
qDebug() << it->first <<
" "
<< it->second.valueDouble;
245
double
intensity = it->second.valueDouble;
246
*isok =
true
;
247
if
(std::isnan(intensity))
248
{
249
return
it->second.valueInt;
250
}
251
return
intensity;
252
}
253
254
double
255
pappso::cbor::mzcbor::SelectedIon::getMz
()
const
256
{
257
258
// <cvParam cvRef="MS" accession="MS:1000744" value="506.2513" name="selected ion m/z"
259
// unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
260
261
auto
it =
cvParamMap
.find(
"MS:1000744"
);
262
if
(it ==
cvParamMap
.end())
263
{
264
throw
pappso::ExceptionNotFound
(QObject::tr(
"m/z not found in SelectedIon cvParam map"
));
265
}
266
qDebug() << it->first <<
" "
<< it->second.valueDouble;
267
return
it->second.valueDouble;
268
}
269
270
271
void
272
pappso::cbor::mzcbor::Precursor::fromCbor
(
CborStreamReader
&reader)
273
{
274
275
QString txt_value;
276
reader.enterContainer();
277
qDebug() << txt_value;
278
while
(reader.hasNext() && (!reader.isInvalid()))
279
{
280
if
(reader.isString())
281
{
282
if
(reader.
decodeString
(txt_value))
283
{
284
qDebug() << txt_value;
285
if
(txt_value ==
"cvParam"
)
286
{
287
// precursorListCvParamMap = CvParam::getCvParamsMapFromCbor(reader);
288
reader.next();
289
}
290
else
if
(txt_value ==
"isolationWindow"
)
291
{
292
isolationWindow
.fromCbor(reader);
293
}
294
else
if
(txt_value ==
"selectedIonList"
)
295
{
296
297
reader.enterContainer();
298
299
while
(reader.hasNext() && (!reader.isInvalid()))
300
{
301
if
(reader.isString())
302
{
303
if
(reader.
decodeString
(txt_value))
304
{
305
qDebug() << txt_value;
306
if
(txt_value ==
"cvParam"
)
307
{
308
selectedIonListCvParamMap
.fromCbor(reader);
309
}
310
else
if
(txt_value ==
"selectedIon"
)
311
{
312
313
reader.enterContainer();
// array
314
315
while
(reader.hasNext() && (!reader.isInvalid()))
316
{
317
SelectedIon
selected_ion;
318
selected_ion.
fromCbor
(reader);
319
selectedIonList
.emplace_back(selected_ion);
320
}
321
reader.leaveContainer();
// array
322
}
323
else
324
{
325
reader.next();
326
}
327
}
328
else
329
{
330
reader.next();
331
}
332
}
333
else
334
{
335
reader.next();
336
}
337
}
338
reader.leaveContainer();
339
}
340
else
if
(txt_value ==
"activation"
)
341
{
342
qDebug();
343
reader.next();
344
}
345
346
else
if
(txt_value ==
"spectrumRef"
)
347
{
348
reader.
decodeString
(txt_value);
349
qDebug() << txt_value;
350
spectrumRef
= txt_value;
351
}
352
else
353
{
354
reader.next();
355
}
356
}
357
else
358
{
359
reader.next();
360
}
361
}
362
else
363
{
364
reader.next();
365
}
366
}
367
reader.leaveContainer();
368
}
pappso::ExceptionNotFound
Definition
exceptionnotfound.h:32
pappso::cbor::CborStreamReader
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...
Definition
cborstreamreader.h:47
pappso::cbor::CborStreamReader::decodeString
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...
Definition
cborstreamreader.cpp:48
exceptionnotfound.h
precursor.h
PSI precursor object for mzML/mzCBOR.
pappso::cbor::mzcbor::IsolationWindow::getUpperMz
double getUpperMz() const
compute isolation window upper m/z given cvParam informations
Definition
precursor.cpp:141
pappso::cbor::mzcbor::IsolationWindow::getLowerMz
double getLowerMz() const
compute isolation window lower m/z given cvParam informations
Definition
precursor.cpp:104
pappso::cbor::mzcbor::IsolationWindow::getTargetMz
double getTargetMz() const
get isolation window target m/z given cvParam informations
Definition
precursor.cpp:86
pappso::cbor::mzcbor::IsolationWindow::toJsonObject
QJsonObject toJsonObject() const
write the structure to a JSON object
Definition
precursor.cpp:124
pappso::cbor::mzcbor::IsolationWindow::fromQCborMap
void fromQCborMap(const QCborMap &reader)
Definition
precursor.cpp:35
pappso::cbor::mzcbor::IsolationWindow::cvParamMap
CvParamMap cvParamMap
Definition
precursor.h:68
pappso::cbor::mzcbor::IsolationWindow::fromCbor
void fromCbor(CborStreamReader &reader)
Definition
precursor.cpp:50
pappso::cbor::mzcbor::Precursor::isolationWindow
IsolationWindow isolationWindow
Definition
precursor.h:96
pappso::cbor::mzcbor::Precursor::spectrumRef
QString spectrumRef
Definition
precursor.h:94
pappso::cbor::mzcbor::Precursor::toJsonObject
QJsonObject toJsonObject() const
write the structure to a JSON object
Definition
precursor.cpp:131
pappso::cbor::mzcbor::Precursor::selectedIonList
std::vector< SelectedIon > selectedIonList
Definition
precursor.h:100
pappso::cbor::mzcbor::Precursor::selectedIonListCvParamMap
CvParamMap selectedIonListCvParamMap
Definition
precursor.h:98
pappso::cbor::mzcbor::Precursor::fromCbor
void fromCbor(CborStreamReader &reader)
Definition
precursor.cpp:272
pappso::cbor::mzcbor::SelectedIon
Definition
precursor.h:72
pappso::cbor::mzcbor::SelectedIon::getMz
double getMz() const
Definition
precursor.cpp:255
pappso::cbor::mzcbor::SelectedIon::fromQCborMap
void fromQCborMap(const QCborMap &reader)
Definition
precursor.cpp:162
pappso::cbor::mzcbor::SelectedIon::getChargeState
int getChargeState() const
Definition
precursor.cpp:214
pappso::cbor::mzcbor::SelectedIon::cvParamMap
CvParamMap cvParamMap
Definition
precursor.h:80
pappso::cbor::mzcbor::SelectedIon::fromCbor
void fromCbor(CborStreamReader &reader)
Definition
precursor.cpp:177
pappso::cbor::mzcbor::SelectedIon::getIntensity
double getIntensity(bool *isok) const
Definition
precursor.cpp:230
pappsomspp
core
processing
cbor
mzcbor
precursor.cpp
Generated on
for libpappsomspp by
1.17.0