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::Spectrum > getMzcborSpectrumSp (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 MsRunIdCstSPtr & getMsRunId () 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
 
MsRunReaderScanNumberMultiMap * mpa_multiMapScanNumber = nullptr
 

Private Member Functions

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

Detailed Description

Todo:
write docs

Definition at line 41 of file mzcbormsrunreader.h.

Constructor & Destructor Documentation

◆ MzcborMsRunReader()

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

Default constructor

Definition at line 41 of file mzcbormsrunreader.cpp.

42 : pappso::MsRunReader(msrun_id_csp)
43{
44 initialize();
45 qDebug();
46}
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition msrunreader.h:64
virtual void initialize() override

References initialize().

◆ ~MzcborMsRunReader()

pappso::MzcborMsRunReader::~MzcborMsRunReader ( )
virtual

Destructor

Definition at line 48 of file mzcbormsrunreader.cpp.

49{
51}
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 195 of file mzcbormsrunreader.cpp.

196{
197
199 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
200}

◆ acquireDevice()

bool pappso::MzcborMsRunReader::acquireDevice ( )
overridevirtual

acquire data back end device

Returns
bool true if done

Implements pappso::MsRunReader.

Definition at line 211 of file mzcbormsrunreader.cpp.

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

Referenced by initialize(), 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 582 of file mzcbormsrunreader.cpp.

585{
586
587 if(spectrum_index >= m_spectrumIndexPositionInFile.size())
588 {
590 QObject::tr("spectrum index %1 not found").arg(spectrum_index));
591 }
592 if(mpa_mzcborFileDevice == nullptr)
593 {
594
596 QObject::tr("mzCBOR file device is not ready, use acquireDevice() before access"));
597 }
598 qDebug() << spectrum_index << " " << m_spectrumIndexPositionInFile[spectrum_index];
599
600
601 // qDebug() << spectrum_index << " " << m_spectrumIndexPositionInFile[spectrum_index-1];
602
603
604 if(mpa_mzcborFileDevice->seek(m_spectrumIndexPositionInFile[spectrum_index]))
605 {
607 cbor_stream_reader.setDevice(mpa_mzcborFileDevice);
608
609
610 try
611 {
612 spectrum.fromCbor(cbor_stream_reader, want_binary_data);
613 }
614 catch(const pappso::PappsoException &error)
615 {
616
617 throw pappso::PappsoException(QObject::tr("ERROR reading spectrum %1 cbor:\n%2")
618 .arg(spectrum_index)
619 .arg(error.qwhat()));
620 }
621 // cbor_stream_reader.leaveContainer();
622
623 if(spectrum.id.isEmpty())
624 {
626 QObject::tr("ERROR reading spectrum %1 cbor:\nspectrum not found").arg(spectrum_index));
627 }
628 }
629 else
630 {
632 QObject::tr("ERROR reading spectrum %1 cbor:\nseek failed").arg(spectrum_index));
633 }
634 // mzcbor_file.close();
635}
std::vector< qint64 > m_spectrumIndexPositionInFile
virtual const QString & qwhat() const
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...
void fromCbor(CborStreamReader &reader, bool want_binary_data)
fill the structure reading data from a CBOR stream
Definition spectrum.cpp:43

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

Referenced by getMzcborSpectrumSp().

◆ 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 684 of file mzcbormsrunreader.cpp.

685{
686 std::shared_ptr<pappso::cbor::mzcbor::Spectrum> cbor_spectrum_sp =
687 std::make_shared<pappso::cbor::mzcbor::Spectrum>();
688
689 fillMzcborSpectrum(spectrum_index, *cbor_spectrum_sp, want_binary_data);
690
691 return cbor_spectrum_sp;
692}
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 204 of file mzcbormsrunreader.cpp.

205{
207 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
208}

◆ 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 662 of file mzcbormsrunreader.cpp.

663{
664 qDebug();
665 std::vector<double> time_line;
666 if((m_spectrumRtList.size() > 0) && (m_spectrumMsLevelList.size() == m_spectrumRtList.size()))
667 {
668 for(std::size_t i = 0; i < m_spectrumRtList.size(); i++)
669 {
670 if(m_spectrumMsLevelList.at(i) == 1)
671 {
672 time_line.push_back(m_spectrumRtList.at(i));
673 }
674 }
675 }
676 else
677 {
679 }
680 return time_line;
681}
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 55 of file mzcbormsrunreader.cpp.

56{
57
59}

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 639 of file mzcbormsrunreader.cpp.

640{
641 qDebug() << m_spectrumMsLevelList.size() << " " << m_spectrumTotalIonCountList.size();
642 Trace chromatogram;
643 if((m_spectrumTotalIonCountList.size() > 0) &&
645 {
646 for(std::size_t i = 0; i < m_spectrumTotalIonCountList.size(); i++)
647 {
648 if(m_spectrumMsLevelList.at(i) == 1)
649 {
650 chromatogram.push_back(
651 {m_spectrumRtList.at(i), (double)m_spectrumTotalIonCountList.at(i)});
652 }
653 }
654 }
655 else
656 {
658 }
659 return chromatogram;
660}
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 153 of file mzcbormsrunreader.cpp.

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

References m_nativeId2SpectrumIndexMap.

◆ initialize()

void pappso::MzcborMsRunReader::initialize ( )
overrideprotectedvirtual

Implements pappso::MsRunReader.

Definition at line 62 of file mzcbormsrunreader.cpp.

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

Referenced by MzcborMsRunReader().

◆ massSpectrumCstSPtr()

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

Implements pappso::MsRunReader.

Definition at line 288 of file mzcbormsrunreader.cpp.

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

◆ 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 294 of file mzcbormsrunreader.cpp.

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

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

◆ 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 236 of file mzcbormsrunreader.cpp.

238{
239
240 XicCoordSPtr xic_coord = std::make_shared<XicCoord>();
241
242 xic_coord.get()->rtTarget = mass_spectrum.getRtInSeconds();
243 xic_coord.get()->mzRange = MzRange(mass_spectrum.getPrecursorMz(), precision);
244 return xic_coord;
245}
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(), and pappso::QualifiedMassSpectrum::getRtInSeconds().

◆ 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 248 of file mzcbormsrunreader.cpp.

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

References pappso::cbor::mzcbor::Spectrum::getRtInSeconds(), and pappso::cbor::mzcbor::Spectrum::precursorList.

◆ 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 326 of file mzcbormsrunreader.cpp.

328{
329 qDebug();
330 try
331 {
332 pappso::cbor::mzcbor::Spectrum cbor_spectrum;
333
334 fillMzcborSpectrum(spectrum_index, cbor_spectrum, want_binary_data);
335 qDebug() << cbor_spectrum.index;
336 QualifiedMassSpectrum qualified_mass_spectrum;
337
338 MassSpectrumId spectrum_id(mcsp_msRunId, spectrum_index);
339 spectrum_id.setNativeId(cbor_spectrum.id);
340
341 spectrum_id.setSpectrumIndex(cbor_spectrum.index);
342
343 qualified_mass_spectrum.setMassSpectrumId(spectrum_id);
344 qualified_mass_spectrum.setRtInSeconds(cbor_spectrum.getRtInSeconds());
345 if(cbor_spectrum.precursorList.size() > 0)
346 {
347 qualified_mass_spectrum.setPrecursorNativeId(
348 cbor_spectrum.precursorList.at(0).spectrumRef);
349 qualified_mass_spectrum.setPrecursorSpectrumIndex(
350 m_nativeId2SpectrumIndexMap.at(cbor_spectrum.precursorList.at(0).spectrumRef));
351 // qWarning() << "pappso::MzcborMsRunReader::qualifiedMassSpectrum";
352
353 for(auto &precursor : cbor_spectrum.precursorList)
354 {
355
356 // *****************************************************
357 // get isolation window (very simplified)
358 // *****************************************************
359
360 try
361 {
362 // qWarning() << "pappso::MzcborMsRunReader::qualifiedMassSpectrum";
363 qualified_mass_spectrum.setParameterValue(
365 precursor.isolationWindow.getTargetMz());
366
367
368 auto it = precursor.isolationWindow.cvParamMap.find("MS:1000828");
369
370 if(it == precursor.isolationWindow.cvParamMap.end())
371 {
372 throw pappso::ExceptionNotFound(QObject::tr(
373 "isolation window lower offset MS:1000828 not found in cvParam map"));
374 }
375 qualified_mass_spectrum.setParameterValue(
377 it->second.valueDouble);
378
379
380 it = precursor.isolationWindow.cvParamMap.find("MS:1000829");
381
382 if(it == precursor.isolationWindow.cvParamMap.end())
383 {
384 throw pappso::ExceptionNotFound(QObject::tr(
385 "isolation window upper offset MS:1000829 not found in cvParam map"));
386 }
387
388 qualified_mass_spectrum.setParameterValue(
390 it->second.valueDouble);
391 }
392 catch(const pappso::ExceptionNotFound &not_found)
393 {
394 // isolation window not available
395 // throw not_found;
396 }
397 // *****************************************************
398 // end get isolation window (very simplified)
399 // *****************************************************
400
401 for(auto &ion : precursor.selectedIonList)
402 {
403 PrecursorIonData precursor_ion_data;
404 precursor_ion_data.charge = ion.getChargeState();
405 bool is_ok;
406 precursor_ion_data.intensity = ion.getIntensity(&is_ok);
407 precursor_ion_data.mz = ion.getMz();
408 qualified_mass_spectrum.appendPrecursorIonData(precursor_ion_data);
409 }
410 }
411 }
412
413
414 qDebug();
415 qualified_mass_spectrum.setMsLevel(cbor_spectrum.getMsLevel());
416
417 qDebug();
418 qualified_mass_spectrum.setEmptyMassSpectrum(!cbor_spectrum.defaultArrayLength);
419 if(cbor_spectrum.binaryDataArrayList.size() == 2)
420 {
421 MassSpectrumSPtr mass_spectrum_sp = std::make_shared<MassSpectrum>();
422 cbor_spectrum.decodeTrace(*(mass_spectrum_sp.get()));
423 qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum_sp);
424 }
425
426 qDebug() << "spectrum id=" << cbor_spectrum.id;
427
428 return qualified_mass_spectrum;
429 }
430
431 catch(const pappso::PappsoException &pappso_error)
432 {
433 qDebug() << "Going to throw";
434
436 QObject::tr("Error reading data (qualifiedMassSpectrum) using the "
437 "mzcbor reader: %1")
438 .arg(pappso_error.what()));
439 }
440}
@ IsolationWindowTargetMz
Isolation m/z value isolation window target m/z (thomson)
@ IsolationWindowUpperOffset
isolation window upper offset (thomson)
@ IsolationWindowLowerOffset
isolation window lower offset (thomson)

References pappso::QualifiedMassSpectrum::appendPrecursorIonData(), pappso::cbor::mzcbor::Spectrum::binaryDataArrayList, pappso::PrecursorIonData::charge, pappso::cbor::mzcbor::Spectrum::decodeTrace(), pappso::cbor::mzcbor::Spectrum::defaultArrayLength, pappso::cbor::mzcbor::Spectrum::getMsLevel(), pappso::cbor::mzcbor::Spectrum::getRtInSeconds(), pappso::cbor::mzcbor::Spectrum::id, pappso::cbor::mzcbor::Spectrum::index, pappso::PrecursorIonData::intensity, pappso::IsolationWindowLowerOffset, pappso::IsolationWindowTargetMz, pappso::IsolationWindowUpperOffset, 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::setParameterValue(), 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 443 of file mzcbormsrunreader.cpp.

444{
445
447 QObject::tr("%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
448 MsRunReadConfig config;
449 std::vector<size_t> ms_levels;
450 for(std::size_t i = 1; i < 9; i++)
451 {
452 if(handler.needMsLevelPeakList(i))
453 {
454 ms_levels.push_back(i);
455 }
456 }
457 config.setMsLevels(ms_levels);
458 config.setNeedPeakList(handler.needPeakList());
459 // readSpectrumCollectionByMsLevel(reader_timeline, 1);
460
461 try
462 {
464 }
465 catch(const pappso::PappsoException &pappso_error)
466 {
467 qDebug() << "Going to throw";
468
470 QObject::tr("Error reading data (spectrum collection2) using the "
471 "mzcbor reader: %1")
472 .arg(pappso_error.what()));
473 }
474 catch(std::exception &error)
475 {
476 qDebug() << "Going to throw";
477
479 QObject::tr("Error reading data (spectrum collection) using the "
480 "mzcbor reader: %1")
481 .arg(error.what()));
482 }
483}
void readSpectrumCollectionWithMsrunReadConfig(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler)

References pappso::SpectrumCollectionHandlerInterface::needMsLevelPeakList(), pappso::SpectrumCollectionHandlerInterface::needPeakList(), 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 486 of file mzcbormsrunreader.cpp.

488{
489 qDebug();
490 try
491 {
493 }
494 catch(const pappso::PappsoException &pappso_error)
495 {
496 qDebug() << "Going to throw";
497
499 QObject::tr("Error reading data (spectrum collection2) using the "
500 "mzcbor reader: %1")
501 .arg(pappso_error.what()));
502 }
503 catch(std::exception &error)
504 {
505 qDebug() << "Going to throw";
506
508 QObject::tr("Error reading data (spectrum collection2) using the "
509 "mzcbor reader: %1")
510 .arg(error.what()));
511 }
512}

References pappso::PappsoException::what().

◆ 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 515 of file mzcbormsrunreader.cpp.

517{
518 MsRunReadConfig config;
519 config.setMsLevels({ms_level});
520 config.setNeedPeakList(handler.needPeakList());
521 // readSpectrumCollectionByMsLevel(reader_timeline, 1);
522 readSpectrumCollection2(config, handler);
523}
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(), pappso::MsRunReadConfig::setMsLevels(), and pappso::MsRunReadConfig::setNeedPeakList().

◆ readSpectrumCollectionWithMsrunReadConfig()

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

Definition at line 546 of file mzcbormsrunreader.cpp.

548{
549 // acquireDevice();
550 try
551 {
553 pappso::UiMonitorVoid monitor;
554 pappso::cbor::mzcbor::MzcborSpectrumCollectionReader mzcbor_spectrum_collection_reader(
555 config, handler);
556 mzcbor_spectrum_collection_reader.setMsRunId(getMsRunId());
557 mzcbor_spectrum_collection_reader.setNativeId2SpectrumIndexMapPtr(
559 mzcbor_spectrum_collection_reader.readCbor(mpa_mzcborFileDevice, monitor);
560
561
562 qDebug();
563 mzcbor_spectrum_collection_reader.close();
564 qDebug();
565 }
566 catch(const pappso::PappsoException &pappso_err)
567 {
569 QObject::tr("ERROR in MzcborMsRunReader::readSpectrumCollectionWithMsrunReadConfig:\n%1")
570 .arg(pappso_err.qwhat()));
571 }
572 // End of
573 // for(std::size_t iter = 0; iter < spectrum_list_size; iter++)
574
575 // Now let the loading handler know that the loading of the data has ended.
576 // The handler might need this "signal" to perform additional tasks or to
577 // cleanup cruft.
578}

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().

◆ 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 223 of file mzcbormsrunreader.cpp.

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

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 164 of file mzcbormsrunreader.cpp.

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

527{
528 return m_spectrumIndexPositionInFile.size();
529}

◆ 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 532 of file mzcbormsrunreader.cpp.

534{
535 auto it = m_nativeId2SpectrumIndexMap.find(spectrum_identifier);
536 if(it == m_nativeId2SpectrumIndexMap.end())
537 {
539 QObject::tr("spectrum identifier %1 not found").arg(spectrum_identifier));
540 }
541 return it->second;
542}

Member Data Documentation

◆ m_cborFileInfo

QFileInfo pappso::MzcborMsRunReader::m_cborFileInfo
protected

Definition at line 133 of file mzcbormsrunreader.h.

Referenced by 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 139 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 136 of file mzcbormsrunreader.h.

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

◆ m_spectrumRtList

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

Definition at line 137 of file mzcbormsrunreader.h.

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

◆ m_spectrumTotalIonCountList

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

Definition at line 135 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: