libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
cborscanmapbase.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/psm/cborscanmapbase.h
3 * \date 13/07/2025
4 * \author Olivier Langella
5 * \brief Base class to handle scan cbor map
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#include "cborscanmapbase.h"
30#include "psmfilescanprocess.h"
31#include <QCborArray>
32
33
34namespace pappso
35{
36namespace cbor
37{
38
40 : m_PsmFileScanProcess(psm_file_scan_process)
41{
42}
43
47
48void
52
53QCborMap
55{
56 if(!keys().contains("id"))
57 {
58 throw pappso::PappsoException(QObject::tr("missing id in scan"));
59 }
60 return value("id").toMap();
61}
62
63QCborMap
65{
66 if(!keys().contains("precursor"))
67 {
68 throw pappso::PappsoException(QObject::tr("missing precursor in scan"));
69 }
70 return value("precursor").toMap();
71}
72
73QCborArray
75{
76 if(!keys().contains("psm_list"))
77 {
78 throw pappso::PappsoException(QObject::tr("missing psm_list in scan"));
79 }
80 return value("psm_list").toArray();
81}
82
83
84std::vector<double>::iterator
86 const QString &eval_name,
87 const QString &eval_value_key,
88 std::vector<double>::iterator itbegin,
89 std::vector<double>::const_iterator itend)
90{
91 std::vector<double>::iterator it = itbegin;
92 if(keys().contains("psm_list"))
93 {
94
95
96 QCborArray new_psm_arr;
97 for(QCborValue cbor_psm : value("psm_list").toArray())
98 {
99 QCborMap cbor_psm_map = cbor_psm.toMap();
100
101 if(!cbor_psm_map.keys().contains("proforma"))
102 {
104 QObject::tr("missing proforma in psm %1").arg(cbor_psm_map.keys().size()));
105 }
106 QCborMap cbor_psm_eval_newvalues;
107
108
109 if(it == itend)
110 {
112 QObject::tr("no more values to add in psm %1").arg(cbor_psm_map.keys().size()));
113 }
114 cbor_psm_eval_newvalues.insert(eval_value_key, *it);
115 it++;
116
117
118 QCborMap psm_eval = cbor_psm_map.value("eval").toMap();
119 psm_eval.remove(eval_name);
120 psm_eval.insert(eval_name, cbor_psm_eval_newvalues);
121 cbor_psm_map.remove(QString("eval"));
122 cbor_psm_map.insert(QString("eval"), psm_eval);
123
124 new_psm_arr.push_back(cbor_psm_map);
125 }
126
127 // insert(QString("psm_list"), new_psm_arr);
128 remove(QString("psm_list"));
129 insert(QString("psm_list"), new_psm_arr);
130 }
131 return it;
132}
133
134
137{
138 if(isEmpty())
139 {
140 throw pappso::PappsoException(QObject::tr("ERROR: cbor scan map is empty"));
141 }
142 if(!contains(QString("precursor")))
143 {
144 throw pappso::PappsoException(QObject::tr("ERROR: no precursor in scan"));
145 }
146 const QCborMap cbor_precursor(value("precursor").toMap());
147 if(!contains(QString("ms2")))
148 {
149 throw pappso::PappsoException(QObject::tr("ERROR: ms2 is empty in scan"));
150 }
151 const QCborMap cbor_ms2(value("ms2").toMap());
152
153 if(!contains(QString("id")))
154 {
155 throw pappso::PappsoException(QObject::tr("ERROR: id is empty in scan"));
156 }
157 const QCborMap cbor_id(value("id").toMap());
158
159 if(!cbor_id.keys().contains("index"))
160 {
161 throw pappso::PappsoException("There is no scan index");
162 }
163 if(!cbor_ms2.keys().contains("mz"))
164 {
165 throw pappso::PappsoException("There is no ms2 mz values");
166 }
167 if(!cbor_ms2.keys().contains("intensity"))
168 {
169 throw pappso::PappsoException("There is no ms2 intensity values");
170 }
171 pappso::MsRunId msrun_id(m_PsmFileScanProcess.m_currentPeaklistFile.name);
172 msrun_id.setSampleName(m_PsmFileScanProcess.m_currentSampleName);
173 pappso::MsRunIdCstSPtr msrun_id_sp = std::make_shared<const pappso::MsRunId>(msrun_id);
174 pappso::MassSpectrumId ms_id(msrun_id_sp);
175 ms_id.setSpectrumIndex(cbor_id.value("index").toInteger());
176
177 // native_id
178 if(cbor_id.keys().contains("native_id"))
179 {
180 ms_id.setNativeId(cbor_id.value("native_id").toString());
181 }
182
183 std::vector<DataPoint> data_point_vector;
184 std::size_t i = 0;
185 for(auto cbor_mz_value : cbor_ms2.value("mz").toArray())
186 {
187 data_point_vector.push_back(
188 {cbor_mz_value.toDouble(), cbor_ms2.value("intensity").toArray().at(i).toDouble()});
189 i++;
190 }
191
192
193 MassSpectrum mass_spectrum(data_point_vector);
194 pappso::PrecursorIonData precursor_ion_data;
195
196 pappso::QualifiedMassSpectrum qualified_mass_spectrum(ms_id);
197 qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum.makeMassSpectrumSPtr());
198 qualified_mass_spectrum.setMsLevel(2);
199
200 if(cbor_precursor.keys().contains("z"))
201 {
202 precursor_ion_data.charge = cbor_precursor.value("z").toInteger();
203 }
204 if(cbor_precursor.keys().contains("mz"))
205 {
206 precursor_ion_data.mz = cbor_precursor.value("mz").toDouble();
207 }
208 if(cbor_precursor.keys().contains("intensity"))
209 {
210 precursor_ion_data.intensity = cbor_precursor.value("intensity").toDouble();
211 }
212 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
213 if(cbor_ms2.keys().contains("rt"))
214 {
215 qualified_mass_spectrum.setRtInSeconds(cbor_ms2.value("rt").toDouble());
216 }
217
218
219 return qualified_mass_spectrum.makeQualifiedMassSpectrumSPtr();
220}
221
222
223} // namespace cbor
224} // namespace pappso
void setNativeId(const QString &native_id)
void setSpectrumIndex(std::size_t index)
Class to represent a mass spectrum.
MassSpectrumSPtr makeMassSpectrumSPtr() const
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition msrunid.h:54
void setSampleName(const QString &name)
set a sample name for this MsRunId
Definition msrunid.cpp:79
Class representing a fully specified mass spectrum.
void appendPrecursorIonData(const PrecursorIonData &precursor_ion_data)
void setMsLevel(uint ms_level)
Set the mass spectrum level.
QualifiedMassSpectrumSPtr makeQualifiedMassSpectrumSPtr() const
void setMassSpectrumSPtr(MassSpectrumSPtr massSpectrum)
Set the MassSpectrumSPtr.
void setRtInSeconds(pappso_double rt)
Set the retention time in seconds.
std::vector< double >::iterator addPsmEvalVectorDouble(const QString &eval_name, const QString &eval_value_key, std::vector< double >::iterator begin, std::vector< double >::const_iterator end)
add a new eval key and double values (from a vector) to each PSM
const PsmFileScanProcess & m_PsmFileScanProcess
CborScanMapBase(const PsmFileScanProcess &psm_file_scan_process)
pappso::QualifiedMassSpectrumSPtr getCurrentQualifiedMassSpectrumSPtr() const
Basic PSM file reader to process scan (parallelized scan processing)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< QualifiedMassSpectrum > QualifiedMassSpectrumSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46