libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::MzcborMsRunReader Class Reference

#include <mzcbormsrunreader.h>

Inheritance diagram for pappso::MzcborMsRunReader:
pappso::MsRunReader

Public Member Functions

 MzcborMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
virtual ~MzcborMsRunReader ()
virtual MassSpectrumSPtr massSpectrumSPtr (std::size_t spectrum_index) override
 get a MassSpectrumSPtr class given its spectrum index
virtual MassSpectrumCstSPtr massSpectrumCstSPtr (std::size_t spectrum_index) override
virtual QualifiedMassSpectrum qualifiedMassSpectrum (std::size_t spectrum_index, bool want_binary_data=true) const override
 get a QualifiedMassSpectrum class given its scan number
virtual void readSpectrumCollection (SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
virtual void readSpectrumCollection2 (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
virtual pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex (std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum index
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum (const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
 get a xic coordinate object from a given spectrum
virtual void readSpectrumCollectionByMsLevel (SpectrumCollectionHandlerInterface &handler, unsigned int ms_level) override
 function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels
virtual std::size_t spectrumListSize () const override
 get the totat number of spectrum conained in the MSrun data file
virtual bool releaseDevice () override
 release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object
virtual bool acquireDevice () override
 acquire data back end device
virtual std::size_t spectrumStringIdentifier2SpectrumIndex (const QString &spectrum_identifier) override
 if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found
virtual bool hasScanNumbers () const override
 tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file if there are some Thermo native ids, this should be set to true
virtual std::size_t scanNumber2SpectrumIndex (std::size_t scan_number) override
 if possible, converts a scan number into a spectrum index This is a convenient function to help transition from the old scan number (not implemented by all vendors) to more secure spectrum index (not vendor dependant). It is better to not rely on this function.
const std::vector< qint64 > & getSpectrumIndexPositionInFile () const
virtual const OboPsiModTerm getOboPsiModTermInstrumentModelName () const override
 get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: instrument model def: "Instrument model name not including the vendor's name." [PSI:MS] relationship: part_of MS:1000463 ! instrument
virtual Trace getTicChromatogram () override
 get a TIC chromatogram
virtual std::vector< double > getRetentionTimeLine () override
 retention timeline get retention times along the MSrun in seconds
std::shared_ptr< pappso::cbor::mzcbor::SpectrumgetMzcborSpectrumSp (std::size_t spectrum_index, bool want_binary_data) const
 get spectrum mzML element
Public Member Functions inherited from pappso::MsRunReader
 MsRunReader (const MsRunIdCstSPtr &ms_run_id)
 MsRunReader (const MsRunReader &other)
virtual ~MsRunReader ()
const MsRunIdCstSPtrgetMsRunId () const
void setMonoThread (bool is_mono_thread)
 set only one is_mono_thread to true
bool isMonoThread () const

Protected Member Functions

virtual void initialize () override
virtual bool accept (const QString &file_name) const override
 tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format
virtual void fillMzcborSpectrum (std::size_t spectrum_index, pappso::cbor::mzcbor::Spectrum &spectrum, bool want_binary_data) const

Protected Attributes

QFileInfo m_cborFileInfo
std::vector< qint64 > m_spectrumIndexPositionInFile
std::vector< qint64 > m_spectrumTotalIonCountList
std::vector< std::uint8_t > m_spectrumMsLevelList
std::vector< double > m_spectrumRtList
std::map< QString, std::size_t > m_nativeId2SpectrumIndexMap
std::map< std::size_t, std::size_t > m_scan2SpectrumIndexMap
QFile * mpa_mzcborFileDevice = nullptr
Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr mcsp_msRunId
MsRunReaderScanNumberMultiMapmpa_multiMapScanNumber = nullptr

Private Member Functions

void readSpectrumCollectionWithMsrunReadConfig (const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)

Detailed Description

Todo
write docs

Definition at line 40 of file mzcbormsrunreader.h.

Constructor & Destructor Documentation

◆ MzcborMsRunReader()

pappso::MzcborMsRunReader::MzcborMsRunReader ( MsRunIdCstSPtr & msrun_id_csp)

Default constructor

Definition at line 40 of file mzcbormsrunreader.cpp.

41 : pappso::MsRunReader(msrun_id_csp)
42{
43 initialize();
44 qDebug();
45}
virtual void initialize() override
class PMSPP_LIB_DECL MsRunReader
Definition msrunreader.h:56

References pappso::MsRunReader::MsRunReader(), and initialize().

◆ ~MzcborMsRunReader()

pappso::MzcborMsRunReader::~MzcborMsRunReader ( )
virtual

Destructor

Definition at line 47 of file mzcbormsrunreader.cpp.

48{
50}
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...

References releaseDevice().

Member Function Documentation

◆ accept()

bool pappso::MzcborMsRunReader::accept ( const QString & file_name) const
overrideprotectedvirtual

tells if the reader is able to handle this file must be implemented by private MS run reader, specific of one or more file format

Implements pappso::MsRunReader.

Definition at line 194 of file mzcbormsrunreader.cpp.

195{
196
197 throw pappso::ExceptionNotImplemented(
198 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
199}

◆ acquireDevice()

bool pappso::MzcborMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 210 of file mzcbormsrunreader.cpp.

211{
212 if(mpa_mzcborFileDevice == nullptr)
213 {
214 mpa_mzcborFileDevice = new QFile(m_cborFileInfo.absoluteFilePath());
215 mpa_mzcborFileDevice->open(QIODevice::ReadOnly);
216 }
217 return true;
218}

References m_cborFileInfo, and mpa_mzcborFileDevice.

Referenced by initialize(), massSpectrumSPtr(), and readSpectrumCollectionWithMsrunReadConfig().

◆ fillMzcborSpectrum()

void pappso::MzcborMsRunReader::fillMzcborSpectrum ( std::size_t spectrum_index,
pappso::cbor::mzcbor::Spectrum & spectrum,
bool want_binary_data ) const
protectedvirtual

Definition at line 530 of file mzcbormsrunreader.cpp.

533{
534
535 if(spectrum_index >= m_spectrumIndexPositionInFile.size())
536 {
537 throw pappso::ExceptionNotFound(
538 QObject::tr("spectrum index %1 not found").arg(spectrum_index));
539 }
540 if(mpa_mzcborFileDevice == nullptr)
541 {
542
543 throw pappso::PappsoException(
544 QObject::tr("mzCBOR file device is not ready, use acquireDevice() before access"));
545 }
546 qDebug() << spectrum_index << " " << m_spectrumIndexPositionInFile[spectrum_index];
547
548
549 // qDebug() << spectrum_index << " " << m_spectrumIndexPositionInFile[spectrum_index-1];
550
551
552 if(mpa_mzcborFileDevice->seek(m_spectrumIndexPositionInFile[spectrum_index]))
553 {
554 pappso::cbor::CborStreamReader cbor_stream_reader(mpa_mzcborFileDevice);
555 cbor_stream_reader.setDevice(mpa_mzcborFileDevice);
556
557
558 try
559 {
560 spectrum.fromCbor(cbor_stream_reader, want_binary_data);
561 }
562 catch(const pappso::PappsoException &error)
563 {
564
565 throw pappso::PappsoException(QObject::tr("ERROR reading spectrum %1 cbor:\n%2")
566 .arg(spectrum_index)
567 .arg(error.qwhat()));
568 }
569 // cbor_stream_reader.leaveContainer();
570
571 if(spectrum.id.isEmpty())
572 {
573 throw pappso::PappsoException(
574 QObject::tr("ERROR reading spectrum %1 cbor:\nspectrum not found").arg(spectrum_index));
575 }
576 }
577 else
578 {
579 throw pappso::PappsoException(
580 QObject::tr("ERROR reading spectrum %1 cbor:\nseek failed").arg(spectrum_index));
581 }
582 // mzcbor_file.close();
583}
std::vector< qint64 > m_spectrumIndexPositionInFile
virtual const QString & qwhat() const
void fromCbor(CborStreamReader &reader, bool want_binary_data)
fill the structure reading data from a CBOR stream
Definition spectrum.cpp:40

References pappso::cbor::mzcbor::Spectrum::fromCbor(), pappso::cbor::mzcbor::Spectrum::id, m_spectrumIndexPositionInFile, mpa_mzcborFileDevice, and pappso::PappsoException::qwhat().

Referenced by getMzcborSpectrumSp(), massSpectrumSPtr(), newXicCoordSPtrFromSpectrumIndex(), and qualifiedMassSpectrum().

◆ getMzcborSpectrumSp()

std::shared_ptr< pappso::cbor::mzcbor::Spectrum > pappso::MzcborMsRunReader::getMzcborSpectrumSp ( std::size_t spectrum_index,
bool want_binary_data ) const

get spectrum mzML element

Parameters
spectrum_indexspectrum to retrieve
want_binary_datatrue to get peak list
Returns
shared pointer on spectrum structure

Definition at line 632 of file mzcbormsrunreader.cpp.

633{
634 std::shared_ptr<pappso::cbor::mzcbor::Spectrum> cbor_spectrum_sp =
635 std::make_shared<pappso::cbor::mzcbor::Spectrum>();
636
637 fillMzcborSpectrum(spectrum_index, *cbor_spectrum_sp, want_binary_data);
638
639 return cbor_spectrum_sp;
640}
virtual void fillMzcborSpectrum(std::size_t spectrum_index, pappso::cbor::mzcbor::Spectrum &spectrum, bool want_binary_data) const

References fillMzcborSpectrum().

◆ getOboPsiModTermInstrumentModelName()

const OboPsiModTerm pappso::MzcborMsRunReader::getOboPsiModTermInstrumentModelName ( ) const
overridevirtual

get OboPsiModTerm corresponding to the instrument model name child of : [Term] id: MS:1000031 name: instrument model def: "Instrument model name not including the vendor's name." [PSI:MS] relationship: part_of MS:1000463 ! instrument

Reimplemented from pappso::MsRunReader.

Definition at line 203 of file mzcbormsrunreader.cpp.

204{
205 throw pappso::ExceptionNotImplemented(
206 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
207}

◆ getRetentionTimeLine()

std::vector< double > pappso::MzcborMsRunReader::getRetentionTimeLine ( )
overridevirtual

retention timeline get retention times along the MSrun in seconds

Returns
vector of retention times (seconds)

Reimplemented from pappso::MsRunReader.

Definition at line 610 of file mzcbormsrunreader.cpp.

611{
612 qDebug();
613 std::vector<double> time_line;
614 if((m_spectrumRtList.size() > 0) && (m_spectrumMsLevelList.size() == m_spectrumRtList.size()))
615 {
616 for(std::size_t i = 0; i < m_spectrumRtList.size(); i++)
617 {
618 if(m_spectrumMsLevelList.at(i) == 1)
619 {
620 time_line.push_back(m_spectrumRtList.at(i));
621 }
622 }
623 }
624 else
625 {
627 }
628 return time_line;
629}
virtual std::vector< double > getRetentionTimeLine()
retention timeline get retention times along the MSrun in seconds
std::vector< double > m_spectrumRtList
std::vector< std::uint8_t > m_spectrumMsLevelList

References pappso::MsRunReader::getRetentionTimeLine(), m_spectrumMsLevelList, and m_spectrumRtList.

◆ getSpectrumIndexPositionInFile()

const std::vector< qint64 > & pappso::MzcborMsRunReader::getSpectrumIndexPositionInFile ( ) const

Definition at line 54 of file mzcbormsrunreader.cpp.

55{
56
58}

References m_spectrumIndexPositionInFile.

◆ getTicChromatogram()

Trace pappso::MzcborMsRunReader::getTicChromatogram ( )
overridevirtual

get a TIC chromatogram

for each retention time, computes the sum of all intensities. For IM-MS, combines the mobility spectra

Note that, formally, a TIC chromatogram is computed only for MS1 spectra.

Returns
a trace (x=rt, y=intensities)

Reimplemented from pappso::MsRunReader.

Definition at line 587 of file mzcbormsrunreader.cpp.

588{
589 qDebug() << m_spectrumMsLevelList.size() << " " << m_spectrumTotalIonCountList.size();
590 Trace chromatogram;
591 if((m_spectrumTotalIonCountList.size() > 0) &&
593 {
594 for(std::size_t i = 0; i < m_spectrumTotalIonCountList.size(); i++)
595 {
596 if(m_spectrumMsLevelList.at(i) == 1)
597 {
598 chromatogram.push_back(
599 {m_spectrumRtList.at(i), (double)m_spectrumTotalIonCountList.at(i)});
600 }
601 }
602 }
603 else
604 {
606 }
607 return chromatogram;
608}
virtual Trace getTicChromatogram()
get a TIC chromatogram
std::vector< qint64 > m_spectrumTotalIonCountList

References pappso::MsRunReader::getTicChromatogram(), m_spectrumMsLevelList, m_spectrumRtList, and m_spectrumTotalIonCountList.

◆ hasScanNumbers()

bool pappso::MzcborMsRunReader::hasScanNumbers ( ) const
overridevirtual

tells if spectra can be accessed using scan numbers by default, it returns false. Only overrided functions can check if scan numbers are available in the current file if there are some Thermo native ids, this should be set to true

Reimplemented from pappso::MsRunReader.

Definition at line 152 of file mzcbormsrunreader.cpp.

153{
154 if(m_nativeId2SpectrumIndexMap.size() > 0)
155 {
156 if(m_nativeId2SpectrumIndexMap.begin()->first.contains("scan="))
157 return true;
158 }
159 return false;
160}
std::map< QString, std::size_t > m_nativeId2SpectrumIndexMap

References m_nativeId2SpectrumIndexMap.

◆ initialize()

void pappso::MzcborMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 61 of file mzcbormsrunreader.cpp.

62{
63 qDebug();
64 m_cborFileInfo.setFile(mcsp_msRunId->getFileName());
65
66 if(!m_cborFileInfo.exists())
67 throw ExceptionNotFound(m_cborFileInfo.absoluteFilePath());
68
69
70 // build the index
72
73 QString str_index_file = m_cborFileInfo.absoluteFilePath();
74 QFileInfo mzcbor_index_fileinfo(str_index_file.append(".idx"));
75 if(mzcbor_index_fileinfo.exists())
76 {
77 qDebug() << "mzcbor_index_fileinfo.exists()";
78 QFile mzcbor_index_file(mzcbor_index_fileinfo.absoluteFilePath());
79 mzcbor_index_file.open(QIODevice::ReadOnly);
80
81 pappso::cbor::mzcbor::MzcborIndexReader index_reader;
82 index_reader.readCbor(&mzcbor_index_file);
83 index_reader.close();
84 mzcbor_index_file.close();
85
86 qDebug();
87 std::vector<QString> run_id_list = index_reader.getRunIdList();
88 if(run_id_list.size() > 0)
89 {
90 std::size_t run_position = 0;
91 if(run_id_list.size() > 1)
92 {
93 std::size_t i_run = 0;
94 for(const QString &run_id : run_id_list)
95 {
96 if(run_id == getMsRunId().get()->getRunId())
97 {
98 run_position = i_run;
99 }
100 i_run++;
101 }
102 }
103
105 index_reader.getRunAndSpectrumOffsetList().at(run_position);
106
107
108 if(index_reader.getRunAndSpectrumTotalIonCountList().size() > run_position)
109 {
111 index_reader.getRunAndSpectrumTotalIonCountList().at(run_position);
112 }
113 if(index_reader.getRunAndSpectrumMsLevelList().size() > run_position)
114 {
115 m_spectrumMsLevelList = index_reader.getRunAndSpectrumMsLevelList().at(run_position);
116 }
117
118 if(index_reader.getRunAndSpectrumRtList().size() > run_position)
119 {
120 m_spectrumRtList = index_reader.getRunAndSpectrumRtList().at(run_position);
121 }
122 // qFatal() << m_spectrumTotalIonCountList.size();
123
124 std::size_t i = 0;
125 for(const QString &native_id : index_reader.getRunAndSpectrumIdList().at(run_position))
126 {
127 m_nativeId2SpectrumIndexMap.insert({native_id, i});
128 i++;
129 }
130 }
131 }
132
133 if(m_spectrumIndexPositionInFile.size() == 0)
134 {
135
136 pappso::UiMonitorVoid monitor;
137 pappso::cbor::mzcbor::MzcborBuildIndexReader mzcbor_build_index_reader(getMsRunId());
138 mzcbor_build_index_reader.readCbor(mpa_mzcborFileDevice, monitor);
139
140
141 qDebug();
142 mzcbor_build_index_reader.close();
143 // releaseDevice();
144 qDebug();
145
146 m_spectrumIndexPositionInFile = mzcbor_build_index_reader.getSpectrumIndexPositionInFile();
147 m_nativeId2SpectrumIndexMap = mzcbor_build_index_reader.getNativeId2SpectrumIndexMap();
148 }
149}
MsRunIdCstSPtr mcsp_msRunId
const MsRunIdCstSPtr & getMsRunId() const
virtual bool acquireDevice() override
acquire data back end device
const std::vector< std::vector< qint64 > > & getRunAndSpectrumTotalIonCountList() const
virtual void close()
convenient function to clean pointer before leaving
const std::vector< std::vector< std::uint8_t > > & getRunAndSpectrumMsLevelList() const
const std::vector< std::vector< qint64 > > & getRunAndSpectrumOffsetList() const
const std::vector< std::vector< QString > > & getRunAndSpectrumIdList() const
const std::vector< QString > & getRunIdList() const
const std::vector< std::vector< double > > & getRunAndSpectrumRtList() const

References acquireDevice(), pappso::cbor::mzcbor::MzcborIndexReader::close(), pappso::cbor::mzcbor::MzcborReaderBase::close(), pappso::MsRunReader::getMsRunId(), pappso::cbor::mzcbor::MzcborBuildIndexReader::getNativeId2SpectrumIndexMap(), pappso::cbor::mzcbor::MzcborIndexReader::getRunAndSpectrumIdList(), pappso::cbor::mzcbor::MzcborIndexReader::getRunAndSpectrumMsLevelList(), pappso::cbor::mzcbor::MzcborIndexReader::getRunAndSpectrumOffsetList(), pappso::cbor::mzcbor::MzcborIndexReader::getRunAndSpectrumRtList(), pappso::cbor::mzcbor::MzcborIndexReader::getRunAndSpectrumTotalIonCountList(), pappso::cbor::mzcbor::MzcborIndexReader::getRunIdList(), pappso::cbor::mzcbor::MzcborBuildIndexReader::getSpectrumIndexPositionInFile(), m_cborFileInfo, m_nativeId2SpectrumIndexMap, m_spectrumIndexPositionInFile, m_spectrumMsLevelList, m_spectrumRtList, m_spectrumTotalIonCountList, pappso::MsRunReader::mcsp_msRunId, mpa_mzcborFileDevice, pappso::cbor::mzcbor::MzcborBuildIndexReader::readCbor(), and pappso::cbor::mzcbor::MzcborIndexReader::readCbor().

Referenced by MzcborMsRunReader().

◆ massSpectrumCstSPtr()

MassSpectrumCstSPtr pappso::MzcborMsRunReader::massSpectrumCstSPtr ( std::size_t spectrum_index)
overridevirtual

Implements pappso::MsRunReader.

Definition at line 287 of file mzcbormsrunreader.cpp.

288{
289 return massSpectrumSPtr(spectrum_index);
290}
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index

References massSpectrumSPtr().

◆ massSpectrumSPtr()

MassSpectrumSPtr pappso::MzcborMsRunReader::massSpectrumSPtr ( std::size_t spectrum_index)
overridevirtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 293 of file mzcbormsrunreader.cpp.

294{
295 MassSpectrumSPtr mass_spectrum_sp;
296 try
297 {
299 pappso::cbor::mzcbor::Spectrum cbor_spectrum;
300
301 fillMzcborSpectrum(spectrum_index, cbor_spectrum, true);
302 if(cbor_spectrum.binaryDataArrayList.size() == 2)
303 {
304 mass_spectrum_sp = std::make_shared<MassSpectrum>();
305 cbor_spectrum.decodeTrace(*(mass_spectrum_sp.get()));
306 }
307 else
308 {
309 throw pappso::PappsoException(
310 QObject::tr("cbor_spectrum.binaryDataArrayList.size() != 2"));
311 }
312 }
313 catch(const pappso::PappsoException &pappso_error)
314 {
315 qDebug() << "Going to throw";
316
317 throw pappso::PappsoException(QObject::tr("Error reading data (massSpectrumSPtr) using the "
318 "mzcbor reader: %1")
319 .arg(pappso_error.what()));
320 }
321 return mass_spectrum_sp;
322}
const char * what() const noexcept override
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
void decodeTrace(pappso::Trace &trace) const
Definition spectrum.cpp:353
std::vector< BinaryDataArray > binaryDataArrayList
Definition spectrum.h:82

References acquireDevice(), pappso::cbor::mzcbor::Spectrum::binaryDataArrayList, pappso::cbor::mzcbor::Spectrum::decodeTrace(), fillMzcborSpectrum(), and pappso::PappsoException::what().

Referenced by massSpectrumCstSPtr().

◆ newXicCoordSPtrFromQualifiedMassSpectrum()

pappso::XicCoordSPtr pappso::MzcborMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum ( const pappso::QualifiedMassSpectrum & mass_spectrum,
pappso::PrecisionPtr precision ) const
overridevirtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 235 of file mzcbormsrunreader.cpp.

237{
238
239 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
240
241 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
242 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
243 return xic_coord;
244}
pappso_double getPrecursorMz(bool *ok=nullptr) const
get precursor mz
pappso_double getRtInSeconds() const
Get the retention time in seconds.
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44

References pappso::QualifiedMassSpectrum::getPrecursorMz(), pappso::QualifiedMassSpectrum::getRtInSeconds(), pappso::XicCoord::mzRange, and pappso::XicCoord::rtTarget.

◆ newXicCoordSPtrFromSpectrumIndex()

pappso::XicCoordSPtr pappso::MzcborMsRunReader::newXicCoordSPtrFromSpectrumIndex ( std::size_t spectrum_index,
pappso::PrecisionPtr precision ) const
overridevirtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 247 of file mzcbormsrunreader.cpp.

249{
250
251 pappso::cbor::mzcbor::Spectrum cbor_spectrum;
252
253 fillMzcborSpectrum(spectrum_index, cbor_spectrum, false);
254
255 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
256
257 xic_coord.get()->rtTarget = cbor_spectrum.getRtInSeconds();
258
259 bool get_mz = false;
260 if(cbor_spectrum.precursorList.size() > 0)
261 {
262
263 for(auto &precursor : cbor_spectrum.precursorList)
264 {
265 for(auto &ion : precursor.selectedIonList)
266 {
267 xic_coord.get()->mzRange = MzRange(ion.getMz(), precision);
268 get_mz = true;
269 }
270 }
271 if(!get_mz)
272 {
273 throw pappso::ExceptionNotFound(
274 QObject::tr("precursor m/z not found for this spectrum index %1").arg(spectrum_index));
275 }
276 }
277 else
278 {
279 throw pappso::ExceptionNotFound(
280 QObject::tr("no precursor found for this spectrum index %1").arg(spectrum_index));
281 }
282
283 return xic_coord;
284}
std::vector< Precursor > precursorList
Definition spectrum.h:81

References fillMzcborSpectrum(), pappso::cbor::mzcbor::Spectrum::getRtInSeconds(), pappso::XicCoord::mzRange, pappso::cbor::mzcbor::Spectrum::precursorList, and pappso::XicCoord::rtTarget.

◆ qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::MzcborMsRunReader::qualifiedMassSpectrum ( std::size_t spectrum_index,
bool want_binary_data = true ) const
overridevirtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 325 of file mzcbormsrunreader.cpp.

327{
328 qDebug();
329 try
330 {
331 pappso::cbor::mzcbor::Spectrum cbor_spectrum;
332
333 fillMzcborSpectrum(spectrum_index, cbor_spectrum, want_binary_data);
334 qDebug() << cbor_spectrum.index;
335 QualifiedMassSpectrum qualified_mass_spectrum;
336
337 MassSpectrumId spectrum_id(mcsp_msRunId, spectrum_index);
338 spectrum_id.setNativeId(cbor_spectrum.id);
339
340 spectrum_id.setSpectrumIndex(cbor_spectrum.index);
341
342 qualified_mass_spectrum.setMassSpectrumId(spectrum_id);
343 qualified_mass_spectrum.setRtInSeconds(cbor_spectrum.getRtInSeconds());
344 if(cbor_spectrum.precursorList.size() > 0)
345 {
346 qualified_mass_spectrum.setPrecursorNativeId(
347 cbor_spectrum.precursorList.at(0).spectrumRef);
348 qualified_mass_spectrum.setPrecursorSpectrumIndex(
349 m_nativeId2SpectrumIndexMap.at(cbor_spectrum.precursorList.at(0).spectrumRef));
350
351 for(auto &precursor : cbor_spectrum.precursorList)
352 {
353 for(auto &ion : precursor.selectedIonList)
354 {
355 PrecursorIonData precursor_ion_data;
356 precursor_ion_data.charge = ion.getChargeState();
357 precursor_ion_data.intensity = ion.getIntensity();
358 precursor_ion_data.mz = ion.getMz();
359 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
360 }
361 }
362 }
363
364
365 qualified_mass_spectrum.setMsLevel(cbor_spectrum.getMsLevel());
366 qualified_mass_spectrum.setEmptyMassSpectrum(!cbor_spectrum.defaultArrayLength);
367 if(cbor_spectrum.binaryDataArrayList.size() == 2)
368 {
369 MassSpectrumSPtr mass_spectrum_sp = std::make_shared<MassSpectrum>();
370 cbor_spectrum.decodeTrace(*(mass_spectrum_sp.get()));
371 qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum_sp);
372 }
373
374 qDebug() << "spectrum id=" << cbor_spectrum.id;
375
376 return qualified_mass_spectrum;
377 }
378
379 catch(const pappso::PappsoException &pappso_error)
380 {
381 qDebug() << "Going to throw";
382
383 throw pappso::PappsoException(
384 QObject::tr("Error reading data (qualifiedMassSpectrum) using the "
385 "mzcbor reader: %1")
386 .arg(pappso_error.what()));
387 }
388}

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::cbor::mzcbor::Spectrum::binaryDataArrayList, pappso::PrecursorIonData::charge, pappso::cbor::mzcbor::Spectrum::decodeTrace(), pappso::cbor::mzcbor::Spectrum::defaultArrayLength, fillMzcborSpectrum(), pappso::cbor::mzcbor::Spectrum::getMsLevel(), pappso::cbor::mzcbor::Spectrum::getRtInSeconds(), pappso::cbor::mzcbor::Spectrum::id, pappso::cbor::mzcbor::Spectrum::index, pappso::PrecursorIonData::intensity, m_nativeId2SpectrumIndexMap, pappso::MsRunReader::mcsp_msRunId, pappso::PrecursorIonData::mz, 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(), pappso::MassSpectrumId::setSpectrumIndex(), and pappso::PappsoException::what().

◆ readSpectrumCollection()

void pappso::MzcborMsRunReader::readSpectrumCollection ( SpectrumCollectionHandlerInterface & handler)
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 391 of file mzcbormsrunreader.cpp.

392{
393
394 throw pappso::ExceptionNotImplemented(
395 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
396 MsRunReadConfig config;
397 std::vector<size_t> ms_levels;
398 for(std::size_t i = 1; i < 9; i++)
399 {
400 if(handler.needMsLevelPeakList(i))
401 {
402 ms_levels.push_back(i);
403 }
404 }
405 config.setMsLevels(ms_levels);
406 config.setNeedPeakList(handler.needPeakList());
407 // readSpectrumCollectionByMsLevel(reader_timeline, 1);
408
409 try
410 {
412 }
413 catch(const pappso::PappsoException &pappso_error)
414 {
415 qDebug() << "Going to throw";
416
417 throw pappso::PappsoException(
418 QObject::tr("Error reading data (spectrum collection2) using the "
419 "mzcbor reader: %1")
420 .arg(pappso_error.what()));
421 }
422 catch(std::exception &error)
423 {
424 qDebug() << "Going to throw";
425
426 throw pappso::PappsoException(
427 QObject::tr("Error reading data (spectrum collection) using the "
428 "mzcbor reader: %1")
429 .arg(error.what()));
430 }
431}
void readSpectrumCollectionWithMsrunReadConfig(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)

References pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList(), pappso::SpectrumCollectionHandlerInterface::needPeakList(), readSpectrumCollectionWithMsrunReadConfig(), pappso::MsRunReadConfig::setMsLevels(), pappso::MsRunReadConfig::setNeedPeakList(), and pappso::PappsoException::what().

◆ readSpectrumCollection2()

void pappso::MzcborMsRunReader::readSpectrumCollection2 ( const MsRunReadConfig & config,
SpectrumCollectionHandlerInterface & handler )
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

Implements pappso::MsRunReader.

Definition at line 434 of file mzcbormsrunreader.cpp.

436{
437 qDebug();
438 try
439 {
441 }
442 catch(const pappso::PappsoException &pappso_error)
443 {
444 qDebug() << "Going to throw";
445
446 throw pappso::PappsoException(
447 QObject::tr("Error reading data (spectrum collection2) using the "
448 "mzcbor reader: %1")
449 .arg(pappso_error.what()));
450 }
451 catch(std::exception &error)
452 {
453 qDebug() << "Going to throw";
454
455 throw pappso::PappsoException(
456 QObject::tr("Error reading data (spectrum collection2) using the "
457 "mzcbor reader: %1")
458 .arg(error.what()));
459 }
460}

References readSpectrumCollectionWithMsrunReadConfig(), and pappso::PappsoException::what().

Referenced by readSpectrumCollectionByMsLevel().

◆ readSpectrumCollectionByMsLevel()

void pappso::MzcborMsRunReader::readSpectrumCollectionByMsLevel ( SpectrumCollectionHandlerInterface & handler,
unsigned int ms_level )
overridevirtual

function to visit an MsRunReader and get each Spectrum in a spectrum collection handler by Ms Levels

Implements pappso::MsRunReader.

Definition at line 463 of file mzcbormsrunreader.cpp.

465{
466 MsRunReadConfig config;
467 config.setMsLevels({ms_level});
468 config.setNeedPeakList(handler.needPeakList());
469 // readSpectrumCollectionByMsLevel(reader_timeline, 1);
470 readSpectrumCollection2(config, handler);
471}
virtual void readSpectrumCollection2(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler

References pappso::SpectrumCollectionHandlerInterface::needPeakList(), readSpectrumCollection2(), pappso::MsRunReadConfig::setMsLevels(), and pappso::MsRunReadConfig::setNeedPeakList().

◆ readSpectrumCollectionWithMsrunReadConfig()

void pappso::MzcborMsRunReader::readSpectrumCollectionWithMsrunReadConfig ( const MsRunReadConfig & config,
SpectrumCollectionHandlerInterface & handler )
private

Definition at line 494 of file mzcbormsrunreader.cpp.

496{
497 // acquireDevice();
498 try
499 {
501 pappso::UiMonitorVoid monitor;
502 pappso::cbor::mzcbor::MzcborSpectrumCollectionReader mzcbor_spectrum_collection_reader(
503 config, handler);
504 mzcbor_spectrum_collection_reader.setMsRunId(getMsRunId());
505 mzcbor_spectrum_collection_reader.setNativeId2SpectrumIndexMapPtr(
507 mzcbor_spectrum_collection_reader.readCbor(mpa_mzcborFileDevice, monitor);
508
509
510 qDebug();
511 mzcbor_spectrum_collection_reader.close();
512 qDebug();
513 }
514 catch(const pappso::PappsoException &pappso_err)
515 {
516 throw pappso::PappsoException(
517 QObject::tr("ERROR in MzcborMsRunReader::readSpectrumCollectionWithMsrunReadConfig:\n%1")
518 .arg(pappso_err.qwhat()));
519 }
520 // End of
521 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
522
523 // Now let the loading handler know that the loading of the data has ended.
524 // The handler might need this "signal" to perform additional tasks or to
525 // cleanup cruft.
526}

References acquireDevice(), pappso::cbor::mzcbor::MzcborReaderBase::close(), pappso::MsRunReader::getMsRunId(), m_nativeId2SpectrumIndexMap, mpa_mzcborFileDevice, pappso::PappsoException::qwhat(), pappso::cbor::mzcbor::MzcborReaderBase::readCbor(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::setMsRunId(), and pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::setNativeId2SpectrumIndexMapPtr().

Referenced by readSpectrumCollection(), and readSpectrumCollection2().

◆ releaseDevice()

bool pappso::MzcborMsRunReader::releaseDevice ( )
overridevirtual

release data back end device if a the data back end is released, the developper has to use acquireDevice before using the msrunreader object

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 222 of file mzcbormsrunreader.cpp.

223{
224 if(mpa_mzcborFileDevice != nullptr)
225 {
226 mpa_mzcborFileDevice->close();
228 mpa_mzcborFileDevice = nullptr;
229 }
230 return true;
231}

References mpa_mzcborFileDevice.

Referenced by ~MzcborMsRunReader().

◆ scanNumber2SpectrumIndex()

std::size_t pappso::MzcborMsRunReader::scanNumber2SpectrumIndex ( std::size_t scan_number)
overridevirtual

if possible, converts a scan number into a spectrum index This is a convenient function to help transition from the old scan number (not implemented by all vendors) to more secure spectrum index (not vendor dependant). It is better to not rely on this function.

Reimplemented from pappso::MsRunReader.

Definition at line 163 of file mzcbormsrunreader.cpp.

164{
165 if(m_scan2SpectrumIndexMap.size() == 0)
166 {
167 for(auto &index_pair : m_nativeId2SpectrumIndexMap)
168 {
169 QStringList native_id_list = index_pair.first.split("=");
170 if(native_id_list.size() < 2)
171 {
172 }
173 else
174 {
175 std::size_t scan_number = native_id_list.back().toULong();
177 std::pair<std::size_t, std::size_t>(scan_number, index_pair.second));
178 }
179 }
180 }
181
182 auto it = m_scan2SpectrumIndexMap.find(scan_number);
183
184 if(it == m_scan2SpectrumIndexMap.end())
185 {
186 throw ExceptionNotFound(QObject::tr("error reading file %1 : scan %2 not found")
187 .arg(mcsp_msRunId.get()->getFileName())
188 .arg(scan_number));
189 }
190 return it->second;
191}
std::map< std::size_t, std::size_t > m_scan2SpectrumIndexMap

References m_nativeId2SpectrumIndexMap, m_scan2SpectrumIndexMap, and pappso::MsRunReader::mcsp_msRunId.

◆ spectrumListSize()

std::size_t pappso::MzcborMsRunReader::spectrumListSize ( ) const
overridevirtual

get the totat number of spectrum conained in the MSrun data file

Implements pappso::MsRunReader.

Definition at line 474 of file mzcbormsrunreader.cpp.

475{
476 return m_spectrumIndexPositionInFile.size();
477}

References m_spectrumIndexPositionInFile.

◆ spectrumStringIdentifier2SpectrumIndex()

std::size_t pappso::MzcborMsRunReader::spectrumStringIdentifier2SpectrumIndex ( const QString & spectrum_identifier)
overridevirtual

if possible, get the spectrum index given a string identifier throw a not found exception if spectrum identifier is not found

Parameters
spectrum_identifierstring identifier of a specific spectrum
Returns
the spectrum index

Implements pappso::MsRunReader.

Definition at line 480 of file mzcbormsrunreader.cpp.

482{
483 auto it = m_nativeId2SpectrumIndexMap.find(spectrum_identifier);
484 if(it == m_nativeId2SpectrumIndexMap.end())
485 {
486 throw pappso::ExceptionNotFound(
487 QObject::tr("spectrum identifier %1 not found").arg(spectrum_identifier));
488 }
489 return it->second;
490}

References m_nativeId2SpectrumIndexMap.

Member Data Documentation

◆ m_cborFileInfo

QFileInfo pappso::MzcborMsRunReader::m_cborFileInfo
protected

Definition at line 132 of file mzcbormsrunreader.h.

Referenced by acquireDevice(), and initialize().

◆ m_nativeId2SpectrumIndexMap

std::map<QString, std::size_t> pappso::MzcborMsRunReader::m_nativeId2SpectrumIndexMap
protected

◆ m_scan2SpectrumIndexMap

std::map<std::size_t, std::size_t> pappso::MzcborMsRunReader::m_scan2SpectrumIndexMap
protected

Definition at line 138 of file mzcbormsrunreader.h.

Referenced by scanNumber2SpectrumIndex().

◆ m_spectrumIndexPositionInFile

std::vector<qint64> pappso::MzcborMsRunReader::m_spectrumIndexPositionInFile
protected

◆ m_spectrumMsLevelList

std::vector<std::uint8_t> pappso::MzcborMsRunReader::m_spectrumMsLevelList
protected

Definition at line 135 of file mzcbormsrunreader.h.

Referenced by getRetentionTimeLine(), getTicChromatogram(), and initialize().

◆ m_spectrumRtList

std::vector<double> pappso::MzcborMsRunReader::m_spectrumRtList
protected

Definition at line 136 of file mzcbormsrunreader.h.

Referenced by getRetentionTimeLine(), getTicChromatogram(), and initialize().

◆ m_spectrumTotalIonCountList

std::vector<qint64> pappso::MzcborMsRunReader::m_spectrumTotalIonCountList
protected

Definition at line 134 of file mzcbormsrunreader.h.

Referenced by getTicChromatogram(), and initialize().

◆ mpa_mzcborFileDevice

QFile* pappso::MzcborMsRunReader::mpa_mzcborFileDevice = nullptr
protected

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