libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
qcborspectrum.cpp
Go to the documentation of this file.
1
/**
2
* \file pappsomspp/core/processing/cbor/mzcbor/copyreplace/qcborspectrum.cpp
3
* \date 2/10/2026
4
* \author Olivier Langella
5
* \brief Low level CBOR map to store an mzCBOR Spectrum object
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2026 Olivier Langella <Olivier.Langella@cnrs.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
#include "
qcborspectrum.h
"
29
#include <cstddef>
30
#include <QCborMap>
31
#include <QCborValue>
32
#include <QCborArray>
33
#include <QDebug>
34
#include <qcborarray.h>
35
#include <qcbormap.h>
36
#include <qcborvalue.h>
37
#include <qlogging.h>
38
#include "
pappsomspp/core/pappsoexception.h
"
39
#include "
pappsomspp/core/exception/exceptionnotfound.h
"
40
#include "
pappsomspp/core/processing/cbor/mzcbor/copyreplace/qcborspectrumprecursor.h
"
41
#include "
pappsomspp/core/processing/cbor/mzcbor/binarydataarray.h
"
42
#include "
pappsomspp/core/processing/cbor/mzcbor/scan.h
"
43
44
namespace
pappso
45
{
46
namespace
cbor
47
{
48
namespace
mzcbor
49
{
50
QcborSpectrum::QcborSpectrum
() : QCborMap()
51
{
52
}
53
QcborSpectrum::QcborSpectrum
(
const
QcborSpectrum
&other) : QCborMap(other)
54
{
55
}
56
std::vector<QcborSpectrumPrecursor>
57
QcborSpectrum::getPrecursorList
()
const
58
{
59
std::vector<QcborSpectrumPrecursor> precursor_list;
60
qDebug();
61
auto
itout = constFind(QCborValue(
"precursorList"
));
62
if
(itout != end())
63
{
64
auto
it = itout.value().toMap().constFind(QCborValue(
"precursor"
));
65
if
(it != end())
66
{
67
for
(
auto
it_cv = it->toArray().cbegin(); it_cv != it->toArray().cend(); it_cv++)
68
{
69
qDebug();
70
QcborSpectrumPrecursor
precursor(it_cv->toMap());
71
precursor_list.push_back(precursor);
72
}
73
return
precursor_list;
74
}
75
else
76
{
77
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no precursor array in QcborSpectrum"
));
78
}
79
}
80
else
81
{
82
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no precursorList in QcborSpectrum"
));
83
}
84
}
85
86
double
87
QcborSpectrum::getRetentionTimeInSeconds
()
const
88
{
89
auto
itout = constFind(QCborValue(
"scanList"
));
90
if
(itout != end())
91
{
92
auto
it = itout.value().toMap().constFind(QCborValue(
"scan"
));
93
if
(it != end())
94
{
95
for
(
auto
it_cv = it->toArray().cbegin(); it_cv != it->toArray().cend(); it_cv++)
96
{
97
qDebug();
98
Scan
scan;
99
scan.
fromQCborMap
(it_cv->toMap());
100
return
scan.
getRtInSeconds
();
101
}
102
}
103
else
104
{
105
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no scan array in QcborSpectrum"
));
106
}
107
}
108
else
109
{
110
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no scanList in QcborSpectrum"
));
111
}
112
return
0.0;
113
}
114
void
115
QcborSpectrum::setPrecursorList
(std::vector<QcborSpectrumPrecursor> &precursor_list)
116
{
117
QCborMap cbor_precursor_list;
118
// auto itout = find(QCborValue("precursorList"));
119
// qDebug();
120
// if(itout != end())
121
// {
122
qDebug();
123
cbor_precursor_list.insert(QCborValue(
"count"
), (qint64)precursor_list.size());
124
qDebug();
125
126
QCborArray cbor_arr;
127
for
(
auto
&it_prec : precursor_list)
128
{
129
cbor_arr.push_back(it_prec);
130
}
131
cbor_precursor_list.insert(QCborValue(
"precursor"
), cbor_arr);
132
133
insert(QCborValue(
"precursorList"
), cbor_precursor_list);
134
// auto it2 = itout.value().toMap().find(QCborValue("precursor"));
135
// if(it2 != end())
136
// {
137
// QCborArray cbor_arr;
138
// for(auto &it_prec : precursor_list)
139
// {
140
// cbor_arr.push_back(it_prec);
141
// }
142
// qDebug() << cbor_arr.size();
143
// // it2. = QCborValue(cbor_arr);
144
// itout.value().toMap().insert(QCborValue("precursor"), cbor_arr);
145
// }
146
// else
147
// {
148
// throw pappso::PappsoException(
149
// QObject::tr("ERROR: no precursor in precursorList QcborSpectrum"));
150
// }
151
// qDebug();
152
// }
153
// else
154
// {
155
// throw pappso::PappsoException(QObject::tr("ERROR: no precursorList in QcborSpectrum"));
156
// }
157
}
158
QString
159
QcborSpectrum::getId
()
const
160
{
161
// <spectrum
162
// id="controllerType=0 controllerNumber=1 scan=1"
163
// index="0"
164
// defaultArrayLength="1552"
165
// >
166
QCborValue id(
"id"
);
167
auto
it = constFind(
id
);
168
if
(it != end())
169
{
170
qDebug() << *it;
171
return
it.value().toString();
172
}
173
else
174
{
175
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no id in QcborSpectrum"
));
176
}
177
}
178
std::size_t
179
QcborSpectrum::getDefaultArrayLength
()
const
180
{
181
QCborValue id(
"defaultArrayLength"
);
182
auto
it = constFind(
id
);
183
if
(it != end())
184
{
185
qDebug() << *it;
186
return
it.value().toInteger();
187
}
188
else
189
{
190
throw
pappso::PappsoException
(
191
QObject::tr(
"ERROR: no defaultArrayLength in QcborSpectrum %1"
).arg(
getId
()));
192
}
193
}
194
void
195
QcborSpectrum::setId
(
const
QString &
id
)
196
{
197
// <spectrum
198
// id="controllerType=0 controllerNumber=1 scan=1"
199
// index="0"
200
// defaultArrayLength="1552"
201
// >
202
QCborValue native_id(
"id"
);
203
auto
it = find(native_id);
204
if
(it != end())
205
{
206
qDebug() << *it;
207
it.value() = QCborValue(
id
);
208
}
209
else
210
{
211
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no id in QcborSpectrum"
));
212
}
213
}
214
std::size_t
215
QcborSpectrum::getIndex
()
const
216
{
217
QCborValue id(
"index"
);
218
auto
it = constFind(
id
);
219
if
(it != end())
220
{
221
qDebug() << *it;
222
return
(std::size_t)it.value().toInteger();
223
}
224
else
225
{
226
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no index in QcborSpectrum"
));
227
}
228
}
229
void
230
QcborSpectrum::setIndex
(std::size_t index)
231
{
232
// <spectrum
233
// id="controllerType=0 controllerNumber=1 scan=1"
234
// index="0"
235
// defaultArrayLength="1552"
236
// >
237
QCborValue id(
"index"
);
238
auto
it = find(
id
);
239
if
(it != end())
240
{
241
qDebug() << *it;
242
it.value() = QCborValue((qint64)index);
243
}
244
else
245
{
246
throw
pappso::PappsoException
(QObject::tr(
"ERROR: no index in QcborSpectrum"
));
247
}
248
}
249
250
int
251
QcborSpectrum::getMsLevel
()
const
252
{
253
//"cvParam":[{"cvRef":"MS","accession":"MS:1000511","name":"ms level","value":1}
254
255
QCborValue cv_param(
"cvParam"
);
256
auto
it = constFind(cv_param);
257
if
(it != end())
258
{
259
for
(
auto
it_cv = it->toArray().cbegin(); it_cv != it->toArray().cend(); it_cv++)
260
{
261
auto
it_accession = it_cv->toMap().constFind(QCborValue(
"accession"
));
262
if
(it_accession->toString() ==
"MS:1000511"
)
263
{
264
auto
it_value = it_cv->toMap().find(QCborValue(
"value"
));
265
return
(it_value.value().toInteger());
266
}
267
}
268
269
throw
pappso::ExceptionNotFound
(
270
QObject::tr(
"ERROR: MS level not found in QcborSpectrum %1"
).arg(
getId
()));
271
}
272
else
273
{
274
throw
pappso::PappsoException
(
275
QObject::tr(
"ERROR: no cvparam in QcborSpectrum %1"
).arg(
getId
()));
276
}
277
}
278
279
void
280
QcborSpectrum::decodeTrace
(
pappso::Trace
&trace)
const
281
{
282
qDebug();
283
std::vector<pappso_double> xVector;
284
std::vector<pappso_double> yVector;
285
std::size_t length =
getDefaultArrayLength
();
286
287
288
auto
it = constFind(QCborValue(
"binaryDataArray"
));
289
if
(it != end())
290
{
291
for
(
auto
it_binarr = it->toArray().cbegin(); it_binarr != it->toArray().cend(); it_binarr++)
292
{
293
BinaryDataArray
binary_array;
294
binary_array.
fromQCborMap
(it_binarr->toMap());
295
qDebug();
296
if
(binary_array.
isIntensity
())
297
{
298
qDebug();
299
binary_array.
decodeVector
(length, yVector);
300
}
301
else
if
(binary_array.
isMz
())
302
{
303
qDebug();
304
binary_array.
decodeVector
(length, xVector);
305
}
306
else
307
{
308
309
throw
pappso::ExceptionNotFound
(
310
QObject::tr(
"error in QcborSpectrum::decodeTrace binary vector "
311
"type not found"
));
312
}
313
qDebug();
314
}
315
}
316
else
317
{
318
throw
pappso::PappsoException
(
319
QObject::tr(
"ERROR: no binaryDataArray in QcborSpectrum %1"
).arg(
getId
()));
320
}
321
qDebug();
322
trace.
initialize
(xVector, yVector);
323
qDebug();
324
}
325
}
// namespace mzcbor
326
}
// namespace cbor
327
}
// namespace pappso
binarydataarray.h
PSI BinaryDataArray object for mzML/mzCBOR.
pappso::ExceptionNotFound
Definition
exceptionnotfound.h:32
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
pappso::Trace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition
trace.cpp:597
pappso::cbor::mzcbor::QcborSpectrumPrecursor
Definition
qcborspectrumprecursor.h:47
pappso::cbor::mzcbor::QcborSpectrum::getDefaultArrayLength
std::size_t getDefaultArrayLength() const
Definition
qcborspectrum.cpp:179
pappso::cbor::mzcbor::QcborSpectrum::decodeTrace
void decodeTrace(pappso::Trace &trace) const
Definition
qcborspectrum.cpp:280
pappso::cbor::mzcbor::QcborSpectrum::getPrecursorList
std::vector< QcborSpectrumPrecursor > getPrecursorList() const
Definition
qcborspectrum.cpp:57
pappso::cbor::mzcbor::QcborSpectrum::getRetentionTimeInSeconds
double getRetentionTimeInSeconds() const
Definition
qcborspectrum.cpp:87
pappso::cbor::mzcbor::QcborSpectrum::QcborSpectrum
QcborSpectrum()
Definition
qcborspectrum.cpp:50
pappso::cbor::mzcbor::QcborSpectrum::getIndex
std::size_t getIndex() const
Definition
qcborspectrum.cpp:215
pappso::cbor::mzcbor::QcborSpectrum::setId
void setId(const QString &id)
Definition
qcborspectrum.cpp:195
pappso::cbor::mzcbor::QcborSpectrum::getId
QString getId() const
Definition
qcborspectrum.cpp:159
pappso::cbor::mzcbor::QcborSpectrum::setPrecursorList
void setPrecursorList(std::vector< QcborSpectrumPrecursor > &precursor_list)
Definition
qcborspectrum.cpp:115
pappso::cbor::mzcbor::QcborSpectrum::getMsLevel
int getMsLevel() const
Definition
qcborspectrum.cpp:251
pappso::cbor::mzcbor::QcborSpectrum::setIndex
void setIndex(std::size_t index)
Definition
qcborspectrum.cpp:230
exceptionnotfound.h
pappso::cbor::mzcbor
Definition
binarydataarray.h:41
pappso::cbor
Definition
cborstreamreader.cpp:35
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappsoexception.h
qcborspectrum.h
Low level CBOR map to store an mzCBOR Spectrum object.
qcborspectrumprecursor.h
Low level CBOR map to store an mzCBOR Spectrum object.
scan.h
PSI scan object for mzML/mzCBOR.
pappso::cbor::mzcbor::BinaryDataArray
Definition
binarydataarray.h:44
pappso::cbor::mzcbor::BinaryDataArray::isMz
bool isMz() const
Definition
binarydataarray.cpp:619
pappso::cbor::mzcbor::BinaryDataArray::fromQCborMap
void fromQCborMap(const QCborMap &cbor_map)
Definition
binarydataarray.cpp:111
pappso::cbor::mzcbor::BinaryDataArray::isIntensity
bool isIntensity() const
Definition
binarydataarray.cpp:610
pappso::cbor::mzcbor::BinaryDataArray::decodeVector
void decodeVector(std::size_t estimated_length, std::vector< double > &double_list) const
Definition
binarydataarray.cpp:500
pappso::cbor::mzcbor::Scan
Definition
scan.h:45
pappso::cbor::mzcbor::Scan::fromQCborMap
void fromQCborMap(const QCborMap &reader)
Definition
scan.cpp:34
pappso::cbor::mzcbor::Scan::getRtInSeconds
double getRtInSeconds() const
Definition
scan.cpp:49
pappsomspp
core
processing
cbor
mzcbor
copyreplace
qcborspectrum.cpp
Generated on
for libpappsomspp by
1.17.0