libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
qcborspectrumprecursor.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/core/processing/cbor/mzcbor/copyreplace/qcborspectrumprecursor.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
32#include <QCborArray>
33#include <qcborarray.h>
34#include <qcbormap.h>
35#include <qcborvalue.h>
36#include <qlogging.h>
37
38namespace pappso
39{
40namespace cbor
41{
42namespace mzcbor
43{
44QcborSpectrumPrecursor::QcborSpectrumPrecursor(const QCborMap &cbor_map) : QCborMap(cbor_map)
45{
46}
51QString
53{
54 //"spectrumRef":"controllerType=0 controllerNumber=1 scan=2711",
55 //
56 auto it = constFind(QCborValue("spectrumRef"));
57 if(it != end())
58 {
59 return it.value().toString();
60 }
61 else
62 {
64 QObject::tr("ERROR: no spectrumRef in QcborSpectrumPrecursor"));
65 }
66}
67
68void
69QcborSpectrumPrecursor::setSpectrumRef(const QString &spectrum_ref)
70{
71 auto it = find(QCborValue("spectrumRef"));
72 if(it != end())
73 {
74 insert(QCborValue("spectrumRef"), spectrum_ref);
75 }
76 else
77 {
79 QObject::tr("ERROR: no spectrumRef in QcborSpectrumPrecursor"));
80 }
81}
82
83
86{
87 auto it = constFind(QCborValue("isolationWindow"));
88 if(it != end())
89 {
90 IsolationWindow isolation_window;
91 isolation_window.fromQCborMap(it->toMap());
92 return isolation_window;
93 }
94 else
95 {
97 QObject::tr("ERROR: no isolationWindow in QcborSpectrumPrecursor"));
98 }
99}
100
101void
102QcborSpectrumPrecursor::setSelectedIon(double mz, double intensity, int charge)
103{
104 auto it = find(QCborValue("selectedIonList"));
105 if(it != end())
106 {
107 QCborMap new_selected_ion_list;
108 new_selected_ion_list.insert(QString("count"), 1);
109
110 QCborMap new_selected_ion;
111 // <cvParam cvRef="MS" accession="MS:1000041" value="3" name="charge state"/>
112 QCborArray cv_param_list;
113 QCborMap cv_param;
114 cv_param.insert(QString("cvRef"), QCborValue("MS"));
115 cv_param.insert(QString("accession"), QCborValue("MS:1000041"));
116 cv_param.insert(QString("value"), QCborValue(charge));
117 cv_param.insert(QString("name"), QCborValue("charge state"));
118 cv_param_list.push_back(cv_param);
119 // <cvParam cvRef="MS" accession="MS:1000042" value="248032.25" name="peak intensity"
120 // unitAccession="MS:1000131" unitName="number of detector counts" unitCvRef="MS"/>
121 //
122 QCborMap cv_param_intensity;
123 cv_param_intensity.insert(QString("cvRef"), QCborValue("MS"));
124 cv_param_intensity.insert(QString("accession"), QCborValue("MS:1000042"));
125 cv_param_intensity.insert(QString("value"), QCborValue(intensity));
126 cv_param_intensity.insert(QString("name"), QCborValue("peak intensity"));
127 cv_param_list.push_back(cv_param_intensity);
128 // <cvParam
129 // cvRef="MS" accession="MS:1000744" value="506.2513" name="selected ion m/z"
130 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS"/>
131 QCborMap cv_param_mz;
132 cv_param_mz.insert(QString("cvRef"), QCborValue("MS"));
133 cv_param_mz.insert(QString("accession"), QCborValue("MS:1000744"));
134 cv_param_mz.insert(QString("value"), QCborValue(mz));
135 cv_param_mz.insert(QString("name"), QCborValue("selected ion m/z"));
136 cv_param_list.push_back(cv_param_mz);
137
138 new_selected_ion.insert(QString("cvParam"), cv_param_list);
139
140
141 QCborArray new_selected_ion_arr;
142 new_selected_ion_arr.push_back(new_selected_ion);
143
144
145 new_selected_ion_list.insert(QString("selectedIon"), new_selected_ion_arr);
146 qDebug();
147 // it.value() = new_selected_ion_list;
148 insert(QCborValue("selectedIonList"), new_selected_ion_list);
149 qDebug();
150 }
151
152 else
153 {
155 QObject::tr("ERROR: no selectedIonList in QcborSpectrumPrecursor"));
156 }
157}
158std::vector<SelectedIon>
160{
161 std::vector<SelectedIon> selected_ion_list;
162 auto itout = constFind(QCborValue("selectedIonList"));
163 if(itout != end())
164 {
165 auto it = itout.value().toMap().constFind(QCborValue("selectedIon"));
166 if(it != end())
167 {
168 for(auto it_cv = it->toArray().cbegin(); it_cv != it->toArray().cend(); it_cv++)
169 {
170 SelectedIon precursor;
171 precursor.fromQCborMap(it_cv->toMap());
172 selected_ion_list.push_back(precursor);
173 }
174 return selected_ion_list;
175 }
176 else
177 {
179 QObject::tr("ERROR: no selectedIon array in QcborSpectrumPrecursor"));
180 }
181 }
182 else
183 {
185 QObject::tr("ERROR: no selectedIonList in QcborSpectrumPrecursor"));
186 }
187}
188} // namespace mzcbor
189} // namespace cbor
190} // namespace pappso
std::vector< SelectedIon > getSelectedIonList() const
void setSelectedIon(double mz, double intensity, int charge)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
PSI precursor object for mzML/mzCBOR.
Low level CBOR map to store an mzCBOR Spectrum object.
void fromQCborMap(const QCborMap &reader)
Definition precursor.cpp:35
void fromQCborMap(const QCborMap &reader)