libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
mzcborbuildindexreader.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/core/processing/cbor/mzcbor/mzcborbuildindexreader.cpp
3 * \date 24/11/2025
4 * \author Olivier Langella
5 * \brief read mzcbor to build an index
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
31
32
33namespace pappso
34{
35namespace cbor
36{
37namespace mzcbor
38{
40 : mcsp_msRunId(msrun_id)
41{
42 m_xmlMzMlRunId = msrun_id.get()->getRunId();
43}
44
48
49
50void
52{
53 qDebug();
54 initCborReader((QIODevice *)cborp);
55
56 if(mpa_cborReader->device() == nullptr)
57 {
58 throw pappso::PappsoException(QObject::tr("device is null"));
59 }
60
61 qDebug();
62 if(mpa_cborReader->isMap())
63 {
64 readRoot(monitor);
65 }
66 qDebug();
67}
68
69const std::vector<qint64> &
74
75const std::map<QString, std::size_t> &
80void
82{
83 // qDebug();
84
85 mpa_cborReader->enterContainer();
86 bool ms_run_to_read = false;
87
88 while(getExpectedString())
89 {
90 if(m_expectedString == "id")
91 {
93
94 if((m_expectedString == m_xmlMzMlRunId) || (m_xmlMzMlRunId.isEmpty()))
95 {
96 ms_run_to_read = true;
97 }
98 }
99 else if(m_expectedString == "spectrumList")
100 {
101 if(ms_run_to_read)
102 {
104 }
105 else
106 {
107 mpa_cborReader->next();
108 }
109 }
110 else
111 {
112 mpa_cborReader->next();
113 }
114 }
115
116 mpa_cborReader->leaveContainer();
117}
118
119
120void
122{
123
124 mpa_cborReader->enterContainer();
125
126
127 // qDebug();
128
129 // We'll need it to perform the looping in the spectrum list.
130 std::size_t spectrum_list_size = 0;
131
132 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
133
134 while(getExpectedString())
135 {
136
137 qDebug() << m_expectedString;
138 if(m_expectedString == "count")
139 {
140 if(mpa_cborReader->isUnsignedInteger())
141 {
142 spectrum_list_size = mpa_cborReader->toUnsignedInteger();
143 mpa_cborReader->next();
144 qDebug() << "spectrum count=" << spectrum_list_size;
145 }
146 }
147 else if(m_expectedString == "spectrum")
148 {
149
150 mpa_cborReader->enterContainer(); // start array
151 qint64 pos = mpa_cborReader->currentOffset();
152
153 std::size_t index_count = 0;
154 while(mpa_cborReader->hasNext())
155 {
156 qDebug();
157 qDebug();
158 readSpectrum(pos, index_count);
159 index_count++;
160 pos = mpa_cborReader->currentOffset();
161 }
162
163 mpa_cborReader->leaveContainer(); // stop array
164 }
165 else
166 {
167 mpa_cborReader->next();
168 }
169 }
170
171
172 mpa_cborReader->leaveContainer();
173 m_stopParsing = true;
174}
175
176
177void
178MzcborBuildIndexReader::readSpectrum(qint64 position_of_spectrum_in_file, std::size_t index_count)
179{
180 qDebug();
181 mpa_cborReader->enterContainer();
182 //<spectrum id="controllerType=0 controllerNumber=1 scan=1" index="0" defaultArrayLength="1552">
183 QString native_id;
184 std::size_t given_index = 0;
185 std::map<QString, CvParam> spectrum_parameters;
186 std::map<QString, CvParam> scan_parameters;
187
188
189 while(getExpectedString())
190 {
191 qDebug() << m_expectedString;
192 if(m_expectedString == "id")
193 {
195 native_id = m_expectedString;
196 qDebug() << m_expectedString;
197 }
198 else if(m_expectedString == "index")
199 {
200 if(mpa_cborReader->isUnsignedInteger())
201 {
202 given_index = mpa_cborReader->toUnsignedInteger();
203 mpa_cborReader->next();
204
205 qDebug() << given_index;
206 // qFatal();
207 }
208 else
209 {
210 }
211 }
212 else if(m_expectedString == "cvParam")
213 {
214
215 mpa_cborReader->next();
216 // spectrum_parameters = getCvParamsMap();
217 }
218 else if(m_expectedString == "scanList")
219 {
220 mpa_cborReader->next();
221 }
222 else if(m_expectedString == "binaryDataArray")
223 {
224 mpa_cborReader->next();
225 }
226 else
227 {
228 mpa_cborReader->next();
229 }
230 }
231 if((given_index != index_count) || (index_count != m_spectrumIndexPositionInFile.size()))
232 {
233 throw pappso::PappsoException(QObject::tr("index inconsistency %1 %2 %3")
234 .arg(given_index)
235 .arg(index_count)
236 .arg(m_spectrumIndexPositionInFile.size()));
237 }
238 m_spectrumIndexPositionInFile.push_back(position_of_spectrum_in_file);
239
240 m_nativeId2SpectrumIndexMap.insert({native_id, given_index});
241
242 mpa_cborReader->leaveContainer();
243}
244
245} // namespace mzcbor
246} // namespace cbor
247} // namespace pappso
void readSpectrumListAndLeave()
only the spectrum list of targeted msrun, then stop parsing
std::map< QString, std::size_t > m_nativeId2SpectrumIndexMap
const std::vector< qint64 > & getSpectrumIndexPositionInFile() const
virtual void readMsrun() override
read only the targeted msrun
virtual void readCbor(QFile *cborp, pappso::UiMonitorInterface &monitor) override
read mzCBOR file
const std::map< QString, std::size_t > & getNativeId2SpectrumIndexMap() const
MzcborBuildIndexReader(const MsRunIdCstSPtr &msrun_id)
void readSpectrum(qint64 position_of_spectrum_in_file, std::size_t index_count)
read each spectrum in the targeted msrun (msrunId)
void readRoot(pappso::UiMonitorInterface &monitor)
read mzcbor to build an index
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46