libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader Class Reference

#include <mzcborspectrumcollectionreader.h>

Inheritance diagram for pappso::cbor::mzcbor::MzcborSpectrumCollectionReader:
pappso::cbor::mzcbor::MzcborReaderBase pappso::cbor::CborStreamReaderInterface

Public Member Functions

 MzcborSpectrumCollectionReader (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)
virtual ~MzcborSpectrumCollectionReader ()
void setMsRunId (const MsRunIdCstSPtr &msrun_id)
void setNativeId2SpectrumIndexMapPtr (const std::map< QString, std::size_t > *nativeId2SpectrumIndexMap)
Public Member Functions inherited from pappso::cbor::mzcbor::MzcborReaderBase
 MzcborReaderBase ()
virtual ~MzcborReaderBase ()
virtual void readCbor (QFile *cborp, pappso::UiMonitorInterface &monitor)
 read mzCBOR file
virtual void readCbor (QIODevice *cborp, pappso::UiMonitorInterface &monitor)
 read mzCBOR from any device (memory buffer or else)
virtual void close ()
 convenient function to clean pointer before leaving
bool isMzcbor () const
const QStringList & getMsrunIdList () const
Public Member Functions inherited from pappso::cbor::CborStreamReaderInterface
 CborStreamReaderInterface ()
virtual ~CborStreamReaderInterface ()

Protected Member Functions

virtual void readMsrun () override
 read only the targeted msrun
void readSpectrumListAndLeave ()
 only the spectrum list of targeted msrun, then stop parsing
void readSpectrum (std::size_t index_count, bool want_binary_data)
 read each spectrum in the targeted msrun (msrunId)
std::map< QString, CvParamreadScan ()
Protected Member Functions inherited from pappso::cbor::mzcbor::MzcborReaderBase
void readRoot (pappso::UiMonitorInterface &monitor)
virtual void readReferenceableParamGroupList ()
std::map< QString, CvParamgetCvParamsMap ()
 read the array containing cvParams to give accessions and values
Protected Member Functions inherited from pappso::cbor::CborStreamReaderInterface
bool getExpectedString ()
void initCborReader (QFile *pcborfile)
void initCborReader (QIODevice *pcborfile)

Private Attributes

const MsRunReadConfigm_msRunReadConfig
SpectrumCollectionHandlerInterfacem_SpectrumCollectionHandlerInterface
MsRunIdCstSPtr mcsp_msRunId
QString m_xmlMzMlRunId
const std::map< QString, std::size_t > * mp_nativeId2SpectrumIndexMap = nullptr

Additional Inherited Members

Protected Attributes inherited from pappso::cbor::mzcbor::MzcborReaderBase
bool m_stopParsing = false
Protected Attributes inherited from pappso::cbor::CborStreamReaderInterface
CborStreamReadermpa_cborReader = nullptr
QString m_expectedString
QByteArray m_data

Detailed Description

Todo
write docs

Definition at line 45 of file mzcborspectrumcollectionreader.h.

Constructor & Destructor Documentation

◆ MzcborSpectrumCollectionReader()

pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::MzcborSpectrumCollectionReader ( const MsRunReadConfig & config,
SpectrumCollectionHandlerInterface & handler )

◆ ~MzcborSpectrumCollectionReader()

pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::~MzcborSpectrumCollectionReader ( )
virtual

Destructor

Definition at line 42 of file mzcborspectrumcollectionreader.cpp.

43{
44}

Member Function Documentation

◆ readMsrun()

void pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readMsrun ( )
overrideprotectedvirtual

read only the targeted msrun

Reimplemented from pappso::cbor::mzcbor::MzcborReaderBase.

Definition at line 62 of file mzcborspectrumcollectionreader.cpp.

63{
64 // qDebug();
65
66 mpa_cborReader->enterContainer();
67 bool ms_run_to_read = false;
68
69 while(getExpectedString())
70 {
71 if(m_expectedString == "id")
72 {
74
75 if((m_expectedString == m_xmlMzMlRunId) || (m_xmlMzMlRunId.isEmpty()))
76 {
77 ms_run_to_read = true;
78 }
79 }
80 else if(m_expectedString == "spectrumList")
81 {
82 if(ms_run_to_read)
83 {
85 }
86 else
87 {
88 mpa_cborReader->next();
89 }
90 }
91 else
92 {
93 mpa_cborReader->next();
94 }
95 }
96
97 mpa_cborReader->leaveContainer();
98}
void readSpectrumListAndLeave()
only the spectrum list of targeted msrun, then stop parsing

References pappso::cbor::CborStreamReaderInterface::getExpectedString(), pappso::cbor::CborStreamReaderInterface::m_expectedString, m_xmlMzMlRunId, pappso::cbor::CborStreamReaderInterface::mpa_cborReader, and readSpectrumListAndLeave().

◆ readScan()

std::map< QString, pappso::cbor::mzcbor::CvParam > pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readScan ( )
protected

Definition at line 336 of file mzcborspectrumcollectionreader.cpp.

337{
338 std::map<QString, CvParam> cv_params;
339 mpa_cborReader->enterContainer();
340 while(getExpectedString())
341 {
342 qDebug() << m_expectedString;
343 if(m_expectedString == "cvParam")
344 {
345 cv_params = getCvParamsMap();
346 }
347 else
348 {
349 mpa_cborReader->next();
350 }
351 }
352 mpa_cborReader->leaveContainer();
353 return cv_params;
354}
std::map< QString, CvParam > getCvParamsMap()
read the array containing cvParams to give accessions and values

References pappso::cbor::mzcbor::MzcborReaderBase::getCvParamsMap(), pappso::cbor::CborStreamReaderInterface::getExpectedString(), pappso::cbor::CborStreamReaderInterface::m_expectedString, and pappso::cbor::CborStreamReaderInterface::mpa_cborReader.

◆ readSpectrum()

void pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum ( std::size_t index_count,
bool want_binary_data )
protected

read each spectrum in the targeted msrun (msrunId)

Definition at line 179 of file mzcborspectrumcollectionreader.cpp.

181{
182
183 qDebug() << index_count << " " << want_binary_data;
184 Spectrum cbor_spectrum;
185 cbor_spectrum.fromCbor(*mpa_cborReader, want_binary_data);
186 //<spectrum id="controllerType=0 controllerNumber=1 scan=1" index="0" defaultArrayLength="1552">
187
188
189 // Now, with or without the peak list, we have to craft a qualified mass
190 // spectrum that will hold all the metadata about the data potentially
191 // found in it.
192 QualifiedMassSpectrum qualified_mass_spectrum;
193
194 MassSpectrumId spectrum_id(mcsp_msRunId, cbor_spectrum.index);
195 spectrum_id.setNativeId(cbor_spectrum.id);
196
197 spectrum_id.setSpectrumIndex(cbor_spectrum.index);
198
199 qualified_mass_spectrum.setMassSpectrumId(spectrum_id);
200 qualified_mass_spectrum.setRtInSeconds(cbor_spectrum.getRtInSeconds());
201
202 if(cbor_spectrum.precursorList.size() > 0)
203 {
204 qualified_mass_spectrum.setPrecursorNativeId(cbor_spectrum.precursorList.at(0).spectrumRef);
205 if(mp_nativeId2SpectrumIndexMap != nullptr)
206 {
207 auto it =
208 mp_nativeId2SpectrumIndexMap->find(cbor_spectrum.precursorList.at(0).spectrumRef);
209 if(it != mp_nativeId2SpectrumIndexMap->end())
210 {
211 qualified_mass_spectrum.setPrecursorSpectrumIndex(it->second);
212 }
213 }
214 }
215
216
217 qualified_mass_spectrum.setMsLevel(cbor_spectrum.getMsLevel());
218 qualified_mass_spectrum.setEmptyMassSpectrum(!cbor_spectrum.defaultArrayLength);
219
220 if(cbor_spectrum.binaryDataArrayList.size() == 2)
221 {
222 MassSpectrumSPtr mass_spectrum_sp = std::make_shared<MassSpectrum>();
223 cbor_spectrum.decodeTrace(*(mass_spectrum_sp.get()));
224 qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum_sp);
225 }
226
227 qDebug() << "spectrum_id.getNativeId()=" << spectrum_id.getNativeId();
228 qDebug() << "rt=" << qualified_mass_spectrum.getRtInSeconds();
229 qDebug() << "mslevel=" << qualified_mass_spectrum.getMsLevel();
230
231 if(m_msRunReadConfig.acceptMsLevel(qualified_mass_spectrum.getMsLevel()))
232 {
233 if(m_msRunReadConfig.acceptRetentionTimeInSeconds(qualified_mass_spectrum.getRtInSeconds()))
234 {
235
236 if(qualified_mass_spectrum.getMassSpectrumId().getSpectrumIndex() ==
237 std::numeric_limits<std::size_t>::max())
238 {
239 throw pappso::PappsoException(
240 QObject::tr("ERROR in %1 spectrum index not initialised").arg(__FUNCTION__));
241 }
242 m_SpectrumCollectionHandlerInterface.setQualifiedMassSpectrum(qualified_mass_spectrum);
243 }
244 }
245
246 /*
247 *
248 <cvParam cvRef="MS" accession="MS:1000579" value="" name="MS1 spectrum" />
249 <cvParam cvRef="MS" accession="MS:1000130" value="" name="positive scan" />
250 <cvParam cvRef="MS" accession="MS:1000285" value="17377980" name="total ion current" />
251 <cvParam cvRef="MS" accession="MS:1000127" value="" name="centroid spectrum" />
252 <cvParam cvRef="MS" accession="MS:1000504" value="519.138854980469" name="base peak m/z"
253 unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
254 <cvParam cvRef="MS"
255 accession="MS:1000505" value="1702482.375" name="base peak intensity" unitAccession="MS:1000131"
256 unitName="number of detector counts" unitCvRef="MS" />
257 <cvParam cvRef="MS" accession="MS:1000528"
258 value="400.153411865234" name="lowest observed m/z" unitAccession="MS:1000040" unitName="m/z"
259 unitCvRef="MS" />
260 <cvParam cvRef="MS" accession="MS:1000527" value="1013.12335205078"
261 name="highest observed m/z" unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" /> <scanList
262 count="1">
263 <cvParam cvRef="MS" accession="MS:1000795" value="" name="no combination" />
264 <scan
265 instrumentConfigurationRef="IC1"> <cvParam cvRef="MS" accession="MS:1000016" value="0.0048758833"
266 name="scan start time" unitAccession="UO:0000031" unitName="minute" unitCvRef="UO" /> <cvParam
267 cvRef="MS" accession="MS:1000512" value="FTMS + p NSI Full lock ms [400.00-1400.00]" name="filter
268 string" /> <cvParam cvRef="MS" accession="MS:1000927" value="250" name="ion injection time"
269 unitAccession="UO:0000028" unitName="millisecond" unitCvRef="UO" /> <scanWindowList count="1">
270 <scanWindow>
271 <cvParam cvRef="MS" accession="MS:1000501" value="400" name="scan window lower
272 limit" unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" /> <cvParam cvRef="MS"
273 accession="MS:1000500" value="1400" name="scan window upper limit" unitAccession="MS:1000040"
274 unitName="m/z" unitCvRef="MS" />
275 </scanWindow>
276 </scanWindowList>
277 </scan>
278 </scanList>
279 <binaryDataArrayList count="2">
280 */
281
282 // qDebug();
283 // Get the native pwiz-spectrum from the spectrum list.
284 // Note that this pointer is a shared pointer from pwiz.
285 /*
286 pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
287 getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
288 // qDebug();
289
290 // Instantiate the mass spectrum id that will hold critical information
291 // like the the native id string and the spectrum index.
292
293 MassSpectrumId massSpectrumId(mcsp_msRunId, iter);
294
295 // qDebug();
296 // Get the spectrum native id as a QString to store it in the mass
297 // spectrum id class. This is will allow later to refer to the same
298 // spectrum starting back from the file.
299
300 QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
301 massSpectrumId.setNativeId(native_id);
302
303 // Finally, instantiate the qualified mass spectrum with its id. This
304 // function will continue performing pappso-spectrum detailed
305 // qualification.
306
307 bool ok = false;
308
309 QualifiedMassSpectrum qualified_mass_spectrum = qualifiedMassSpectrumFromPwizSpectrumPtr(
310 massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
311
312 if(!ok)
313 {
314 // qDebug() << "Encountered a mass spectrum for which the returned "
315 //"status is bad.";
316 continue;
317 }
318
319 // qDebug();
320 // Before handing the mass spectrum out to the m_SpectrumCollectionHandlerInterface, see if
321 // the native mass spectrum was empty or not.
322
323 // if(!native_pwiz_spectrum_sp->defaultArrayLength)
324 // qDebug() << "The mass spectrum has not defaultArrayLength";
325
326 qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
327
328 // The m_SpectrumCollectionHandlerInterface will receive the index of the mass spectrum in the
329 // current run via the mass spectrum id member datum.
330
331 // qDebug();
332 */
333}
const std::map< QString, std::size_t > * mp_nativeId2SpectrumIndexMap
std::shared_ptr< MassSpectrum > MassSpectrumSPtr

References pappso::cbor::mzcbor::Spectrum::binaryDataArrayList, pappso::cbor::mzcbor::Spectrum::decodeTrace(), pappso::cbor::mzcbor::Spectrum::defaultArrayLength, pappso::cbor::mzcbor::Spectrum::fromCbor(), pappso::QualifiedMassSpectrum::getMassSpectrumId(), pappso::cbor::mzcbor::Spectrum::getMsLevel(), pappso::QualifiedMassSpectrum::getMsLevel(), pappso::MassSpectrumId::getNativeId(), pappso::cbor::mzcbor::Spectrum::getRtInSeconds(), pappso::QualifiedMassSpectrum::getRtInSeconds(), pappso::MassSpectrumId::getSpectrumIndex(), pappso::cbor::mzcbor::Spectrum::id, pappso::cbor::mzcbor::Spectrum::index, m_msRunReadConfig, m_SpectrumCollectionHandlerInterface, mcsp_msRunId, mp_nativeId2SpectrumIndexMap, pappso::cbor::CborStreamReaderInterface::mpa_cborReader, pappso::cbor::mzcbor::Spectrum::precursorList, pappso::QualifiedMassSpectrum::setEmptyMassSpectrum(), pappso::QualifiedMassSpectrum::setMassSpectrumId(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::MassSpectrumId::setNativeId(), pappso::QualifiedMassSpectrum::setPrecursorNativeId(), pappso::QualifiedMassSpectrum::setPrecursorSpectrumIndex(), pappso::QualifiedMassSpectrum::setRtInSeconds(), and pappso::MassSpectrumId::setSpectrumIndex().

Referenced by readSpectrumListAndLeave().

◆ readSpectrumListAndLeave()

void pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrumListAndLeave ( )
protected

only the spectrum list of targeted msrun, then stop parsing

Definition at line 101 of file mzcborspectrumcollectionreader.cpp.

102{
103 mpa_cborReader->enterContainer();
104 // We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
105 // create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
106 // spectrum has been fully qualified (that is, the member data have been
107 // set), it is transferred to the m_SpectrumCollectionHandlerInterface passed as parameter to this
108 // function for the consumer to do what it wants with it.
109
110 // Does the m_SpectrumCollectionHandlerInterface consuming the mass spectra read from file want
111 // these mass spectra to hold the binary data arrays (mz/i vectors)?
112
113 const bool want_binary_data = m_msRunReadConfig.needPeakList();
114
115
116 // qDebug();
117
118 // We'll need it to perform the looping in the spectrum list.
119 std::size_t spectrum_list_size = 0;
120
121 // qDebug() << "The spectrum list has size:" << spectrum_list_size;
122
123 while(getExpectedString())
124 {
125
126 qDebug() << m_expectedString;
127 if(m_expectedString == "count")
128 {
129 if(mpa_cborReader->isUnsignedInteger())
130 {
131 spectrum_list_size = mpa_cborReader->toUnsignedInteger();
132 mpa_cborReader->next();
133 qDebug() << "spectrum count=" << spectrum_list_size;
134 }
135
136 // Inform the m_SpectrumCollectionHandlerInterface of the spectrum list so that it can
137 // handle feedback to the user.
138 m_SpectrumCollectionHandlerInterface.spectrumListHasSize(spectrum_list_size);
139 }
140 else if(m_expectedString == "spectrum")
141 {
142
143 mpa_cborReader->enterContainer(); // start array
144
145 std::size_t index_count = 0;
146 while(mpa_cborReader->hasNext())
147 {
148 // If the user of this reader instance wants to stop reading the
149 // spectra, then break this loop.
151 {
152 qDebug() << "The operation was cancelled. Breaking the loop.";
153 m_stopParsing = true;
154 return;
155 }
156
157 readSpectrum(index_count, want_binary_data);
158 index_count++;
159 }
160
161 mpa_cborReader->leaveContainer(); // stop array
162 }
163 else
164 {
165 mpa_cborReader->next();
166 }
167 }
168
169
170 qDebug() << "Loading ended";
172
173 mpa_cborReader->leaveContainer();
174 m_stopParsing = true;
175}
void readSpectrum(std::size_t index_count, bool want_binary_data)
read each spectrum in the targeted msrun (msrunId)

References pappso::cbor::CborStreamReaderInterface::getExpectedString(), pappso::cbor::CborStreamReaderInterface::m_expectedString, m_msRunReadConfig, m_SpectrumCollectionHandlerInterface, pappso::cbor::mzcbor::MzcborReaderBase::m_stopParsing, pappso::cbor::CborStreamReaderInterface::mpa_cborReader, and readSpectrum().

Referenced by readMsrun().

◆ setMsRunId()

void pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::setMsRunId ( const MsRunIdCstSPtr & msrun_id)

Definition at line 47 of file mzcborspectrumcollectionreader.cpp.

48{
49 mcsp_msRunId = msrun_id;
50 m_xmlMzMlRunId = mcsp_msRunId.get()->getRunId();
51}

References m_xmlMzMlRunId, and mcsp_msRunId.

Referenced by pappso::MzcborMsRunReader::readSpectrumCollectionWithMsrunReadConfig().

◆ setNativeId2SpectrumIndexMapPtr()

void pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::setNativeId2SpectrumIndexMapPtr ( const std::map< QString, std::size_t > * nativeId2SpectrumIndexMap)

Member Data Documentation

◆ m_msRunReadConfig

const MsRunReadConfig& pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_msRunReadConfig
private

◆ m_SpectrumCollectionHandlerInterface

SpectrumCollectionHandlerInterface& pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_SpectrumCollectionHandlerInterface
private

◆ m_xmlMzMlRunId

QString pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_xmlMzMlRunId
private

Definition at line 84 of file mzcborspectrumcollectionreader.h.

Referenced by readMsrun(), and setMsRunId().

◆ mcsp_msRunId

MsRunIdCstSPtr pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::mcsp_msRunId
private

Definition at line 83 of file mzcborspectrumcollectionreader.h.

Referenced by readSpectrum(), and setMsRunId().

◆ mp_nativeId2SpectrumIndexMap

const std::map<QString, std::size_t>* pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::mp_nativeId2SpectrumIndexMap = nullptr
private

The documentation for this class was generated from the following files: