Loading...
Searching...
No Matches
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader Class Reference

`#include <mzcborspectrumcollectionreader.h>`

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

## 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, CvParam > | readScan ()
Protected Member Functions inherited from pappso::cbor::mzcbor::MzcborReaderBase
void | readRoot (pappso::UiMonitorInterface &monitor)
virtual void | readReferenceableParamGroupList ()
std::map< QString, CvParam > | getCvParamsMap ()
| 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 MsRunReadConfig & | m_msRunReadConfig
SpectrumCollectionHandlerInterface & | m_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
CborStreamReader * | mpa_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 )

Default constructor

Definition at line 36 of file mzcborspectrumcollectionreader.cpp.

: m_msRunReadConfig(m_msRunReadConfig),
m_SpectrumCollectionHandlerInterface(m_SpectrumCollectionHandlerInterface)
{
}
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_SpectrumCollectionHandlerInterface
SpectrumCollectionHandlerInterface & m_SpectrumCollectionHandlerInterface
Definition mzcborspectrumcollectionreader.h:82
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_msRunReadConfig
const MsRunReadConfig & m_msRunReadConfig
Definition mzcborspectrumcollectionreader.h:81

References m_msRunReadConfig, and m_SpectrumCollectionHandlerInterface.

## ~MzcborSpectrumCollectionReader()

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

virtual

Destructor

Definition at line 44 of file mzcborspectrumcollectionreader.cpp.

{
}

## Member Function Documentation

## readMsrun()

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

override protected virtual

read only the targeted msrun

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

Definition at line 64 of file mzcborspectrumcollectionreader.cpp.

{
// qDebug();
mpa_cborReader->enterContainer();
bool ms_run_to_read = false;
while(getExpectedString())
{
if(m_expectedString == "id")
{
getExpectedString();
if((m_expectedString == m_xmlMzMlRunId) || (m_xmlMzMlRunId.isEmpty()))
{
ms_run_to_read = true;
}
}
else if(m_expectedString == "spectrumList")
{
if(ms_run_to_read)
{
readSpectrumListAndLeave();
}
else
{
mpa_cborReader->next();
}
}
else
{
mpa_cborReader->next();
}
}
mpa_cborReader->leaveContainer();
}
pappso::cbor::CborStreamReaderInterface::m_expectedString
QString m_expectedString
Definition cborstreamreaderinterface.h:69
pappso::cbor::CborStreamReaderInterface::getExpectedString
bool getExpectedString()
Definition cborstreamreaderinterface.cpp:54
pappso::cbor::CborStreamReaderInterface::mpa_cborReader
CborStreamReader * mpa_cborReader
Definition cborstreamreaderinterface.h:68
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrumListAndLeave
void readSpectrumListAndLeave()
only the spectrum list of targeted msrun, then stop parsing
Definition mzcborspectrumcollectionreader.cpp:103
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::m_xmlMzMlRunId
QString m_xmlMzMlRunId
Definition mzcborspectrumcollectionreader.h:84

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 370 of file mzcborspectrumcollectionreader.cpp.

{
std::map<QString, CvParam> cv_params;
mpa_cborReader->enterContainer();
while(getExpectedString())
{
qDebug() << m_expectedString;
if(m_expectedString == "cvParam")
{
cv_params = getCvParamsMap();
}
else
{
mpa_cborReader->next();
}
}
mpa_cborReader->leaveContainer();
return cv_params;
}
pappso::cbor::mzcbor::MzcborReaderBase::getCvParamsMap
std::map< QString, CvParam > getCvParamsMap()
read the array containing cvParams to give accessions and values
Definition mzcborreaderbase.cpp:190

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 181 of file mzcborspectrumcollectionreader.cpp.

{
qDebug() << index_count << " " << want_binary_data;
try
{
Spectrum cbor_spectrum;
cbor_spectrum.fromCbor(*mpa_cborReader, want_binary_data);
//<spectrum id="controllerType=0 controllerNumber=1 scan=1" index="0"
// defaultArrayLength="1552">
// Now, with or without the peak list, we have to craft a qualified mass
// spectrum that will hold all the metadata about the data potentially
// found in it.
QualifiedMassSpectrum qualified_mass_spectrum;
MassSpectrumId spectrum_id(mcsp_msRunId, cbor_spectrum.index);
spectrum_id.setNativeId(cbor_spectrum.id);
spectrum_id.setSpectrumIndex(cbor_spectrum.index);
qualified_mass_spectrum.setMassSpectrumId(spectrum_id);
qualified_mass_spectrum.setRtInSeconds(cbor_spectrum.getRtInSeconds());
if(cbor_spectrum.precursorList.size() > 0)
{
qualified_mass_spectrum.setPrecursorNativeId(
cbor_spectrum.precursorList.at(0).spectrumRef);
if(mp_nativeId2SpectrumIndexMap != nullptr)
{
auto it =
mp_nativeId2SpectrumIndexMap->find(cbor_spectrum.precursorList.at(0).spectrumRef);
if(it != mp_nativeId2SpectrumIndexMap->end())
{
qualified_mass_spectrum.setPrecursorSpectrumIndex(it->second);
}
}
for(auto &precursor : cbor_spectrum.precursorList)
{
PrecursorIonData ion_data;
ion_data.mz = precursor.isolationWindow.getTargetMz();
for(auto &selected_ion : precursor.selectedIonList)
{
ion_data.charge = selected_ion.getChargeState();
bool is_ok;
ion_data.intensity = selected_ion.getIntensity(&is_ok);
ion_data.mz = selected_ion.getMz();
qualified_mass_spectrum.appendPrecursorIonData(ion_data);
}
}
}
qDebug();
qualified_mass_spectrum.setMsLevel(cbor_spectrum.getMsLevel());
qDebug();
qualified_mass_spectrum.setEmptyMassSpectrum(!cbor_spectrum.defaultArrayLength);
if(cbor_spectrum.binaryDataArrayList.size() == 2)
{
qDebug();
MassSpectrumSPtr mass_spectrum_sp = std::make_shared<MassSpectrum>();
qDebug();
cbor_spectrum.decodeTrace(*(mass_spectrum_sp.get()));
qDebug();
qualified_mass_spectrum.setMassSpectrumSPtr(mass_spectrum_sp);
qDebug();
}
qDebug() << "spectrum_id.getNativeId()=" << spectrum_id.getNativeId();
qDebug() << "rt=" << qualified_mass_spectrum.getRtInSeconds();
qDebug() << "mslevel=" << qualified_mass_spectrum.getMsLevel();
if(m_msRunReadConfig.acceptMsLevel(qualified_mass_spectrum.getMsLevel()))
{
if(m_msRunReadConfig.acceptRetentionTimeInSeconds(
qualified_mass_spectrum.getRtInSeconds()))
{
if(qualified_mass_spectrum.getMassSpectrumId().getSpectrumIndex() ==
std::numeric_limits<std::size_t>::max())
{
throw pappso::PappsoException(
QObject::tr("ERROR in %1 spectrum index not initialised").arg(__FUNCTION__));
}
m_SpectrumCollectionHandlerInterface.setQualifiedMassSpectrum(
qualified_mass_spectrum);
}
}
/*
*
<cvParam cvRef="MS" accession="MS:1000579" value="" name="MS1 spectrum" />
<cvParam cvRef="MS" accession="MS:1000130" value="" name="positive scan" />
<cvParam cvRef="MS" accession="MS:1000285" value="17377980" name="total ion current" />
<cvParam cvRef="MS" accession="MS:1000127" value="" name="centroid spectrum" />
<cvParam cvRef="MS" accession="MS:1000504" value="519.138854980469" name="base peak m/z"
unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
<cvParam cvRef="MS"
accession="MS:1000505" value="1702482.375" name="base peak intensity"
unitAccession="MS:1000131" unitName="number of detector counts" unitCvRef="MS" /> <cvParam
cvRef="MS" accession="MS:1000528" value="400.153411865234" name="lowest observed m/z"
unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" /> <cvParam cvRef="MS"
accession="MS:1000527" value="1013.12335205078" name="highest observed m/z"
unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" /> <scanList count="1"> <cvParam
cvRef="MS" accession="MS:1000795" value="" name="no combination" /> <scan
instrumentConfigurationRef="IC1"> <cvParam cvRef="MS" accession="MS:1000016"
value="0.0048758833" name="scan start time" unitAccession="UO:0000031" unitName="minute"
unitCvRef="UO" /> <cvParam cvRef="MS" accession="MS:1000512" value="FTMS + p NSI Full lock ms
[400.00-1400.00]" name="filter string" /> <cvParam cvRef="MS" accession="MS:1000927"
value="250" name="ion injection time" unitAccession="UO:0000028" unitName="millisecond"
unitCvRef="UO" /> <scanWindowList count="1"> <scanWindow> <cvParam cvRef="MS"
accession="MS:1000501" value="400" name="scan window lower limit" unitAccession="MS:1000040"
unitName="m/z" unitCvRef="MS" /> <cvParam cvRef="MS" accession="MS:1000500" value="1400"
name="scan window upper limit" unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
</scanWindow>
</scanWindowList>
</scan>
</scanList>
<binaryDataArrayList count="2">
*/
// qDebug();
// Get the native pwiz-spectrum from the spectrum list.
// Note that this pointer is a shared pointer from pwiz.
/*
pwiz::msdata::SpectrumPtr native_pwiz_spectrum_sp =
getPwizSpectrumPtr(spectrum_list_p.get(), iter, want_binary_data);
// qDebug();
// Instantiate the mass spectrum id that will hold critical information
// like the the native id string and the spectrum index.
MassSpectrumId massSpectrumId(mcsp_msRunId, iter);
// qDebug();
// Get the spectrum native id as a QString to store it in the mass
// spectrum id class. This is will allow later to refer to the same
// spectrum starting back from the file.
QString native_id = QString::fromStdString(native_pwiz_spectrum_sp->id);
massSpectrumId.setNativeId(native_id);
// Finally, instantiate the qualified mass spectrum with its id. This
// function will continue performing pappso-spectrum detailed
// qualification.
bool ok = false;
QualifiedMassSpectrum qualified_mass_spectrum = qualifiedMassSpectrumFromPwizSpectrumPtr(
massSpectrumId, native_pwiz_spectrum_sp.get(), want_binary_data, ok);
if(!ok)
{
// qDebug() << "Encountered a mass spectrum for which the returned "
//"status is bad.";
continue;
}
// qDebug();
// Before handing the mass spectrum out to the m_SpectrumCollectionHandlerInterface, see if
// the native mass spectrum was empty or not.
// if(!native_pwiz_spectrum_sp->defaultArrayLength)
// qDebug() << "The mass spectrum has not defaultArrayLength";
qualified_mass_spectrum.setEmptyMassSpectrum(!native_pwiz_spectrum_sp->defaultArrayLength);
// The m_SpectrumCollectionHandlerInterface will receive the index of the mass spectrum in
the
// current run via the mass spectrum id member datum.
// qDebug();
*/
}
catch(pappso::PappsoException &error)
{
throw pappso::PappsoException(
QObject::tr("ERROR reading spectrum index %1 :\%2").arg(index_count).arg(error.qwhat()));
}
}
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition pappsoexception.h:66
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition mzcborspectrumcollectionreader.h:83
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::mp_nativeId2SpectrumIndexMap
const std::map< QString, std::size_t > * mp_nativeId2SpectrumIndexMap
Definition mzcborspectrumcollectionreader.h:86
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:53

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::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, pappso::PrecursorIonData::intensity, m_msRunReadConfig, m_SpectrumCollectionHandlerInterface, mcsp_msRunId, mp_nativeId2SpectrumIndexMap, pappso::cbor::CborStreamReaderInterface::mpa_cborReader, pappso::PrecursorIonData::mz, pappso::cbor::mzcbor::Spectrum::precursorList, pappso::PappsoException::qwhat(), 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 103 of file mzcborspectrumcollectionreader.cpp.

{
mpa_cborReader->enterContainer();
// We want to iterate in the pwiz-spectrum-list and for each pwiz-spectrum
// create a pappso-spectrum (QualifiedMassSpectrum). Once the pappso mass
// spectrum has been fully qualified (that is, the member data have been
// set), it is transferred to the m_SpectrumCollectionHandlerInterface passed as parameter to this
// function for the consumer to do what it wants with it.
// Does the m_SpectrumCollectionHandlerInterface consuming the mass spectra read from file want
// these mass spectra to hold the binary data arrays (mz/i vectors)?
const bool want_binary_data = m_msRunReadConfig.needPeakList();
// qDebug();
// We'll need it to perform the looping in the spectrum list.
std::size_t spectrum_list_size = 0;
// qDebug() << "The spectrum list has size:" << spectrum_list_size;
while(getExpectedString())
{
qDebug() << m_expectedString;
if(m_expectedString == "count")
{
if(mpa_cborReader->isUnsignedInteger())
{
spectrum_list_size = mpa_cborReader->toUnsignedInteger();
mpa_cborReader->next();
qDebug() << "spectrum count=" << spectrum_list_size;
}
// Inform the m_SpectrumCollectionHandlerInterface of the spectrum list so that it can
// handle feedback to the user.
m_SpectrumCollectionHandlerInterface.spectrumListHasSize(spectrum_list_size);
}
else if(m_expectedString == "spectrum")
{
mpa_cborReader->enterContainer(); // start array
std::size_t index_count = 0;
while(mpa_cborReader->hasNext())
{
// If the user of this reader instance wants to stop reading the
// spectra, then break this loop.
if(m_SpectrumCollectionHandlerInterface.shouldStop())
{
qDebug() << "The operation was cancelled. Breaking the loop.";
m_stopParsing = true;
return;
}
readSpectrum(index_count, want_binary_data);
index_count++;
}
mpa_cborReader->leaveContainer(); // stop array
}
else
{
mpa_cborReader->next();
}
}
qDebug() << "Loading ended";
m_SpectrumCollectionHandlerInterface.loadingEnded();
mpa_cborReader->leaveContainer();
m_stopParsing = true;
}
pappso::cbor::mzcbor::MzcborReaderBase::m_stopParsing
bool m_stopParsing
Definition mzcborreaderbase.h:90
pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum
void readSpectrum(std::size_t index_count, bool want_binary_data)
read each spectrum in the targeted msrun (msrunId)
Definition mzcborspectrumcollectionreader.cpp:181

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 49 of file mzcborspectrumcollectionreader.cpp.

{
mcsp_msRunId = msrun_id;
m_xmlMzMlRunId = mcsp_msRunId.get()->getRunId();
}

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

Definition at line 56 of file mzcborspectrumcollectionreader.cpp.

{
mp_nativeId2SpectrumIndexMap = nativeId2SpectrumIndexMap;
}

References mp_nativeId2SpectrumIndexMap.

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

## Member Data Documentation

## m_msRunReadConfig

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

private

Definition at line 81 of file mzcborspectrumcollectionreader.h.

Referenced by MzcborSpectrumCollectionReader(), readSpectrum(), and readSpectrumListAndLeave().

## m_SpectrumCollectionHandlerInterface

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

private

Definition at line 82 of file mzcborspectrumcollectionreader.h.

Referenced by MzcborSpectrumCollectionReader(), readSpectrum(), and readSpectrumListAndLeave().

## 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

Definition at line 86 of file mzcborspectrumcollectionreader.h.

Referenced by readSpectrum(), and setNativeId2SpectrumIndexMapPtr().

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

- pappsomspp/core/processing/cbor/mzcbor/mzcborspectrumcollectionreader.h
- pappsomspp/core/processing/cbor/mzcbor/mzcborspectrumcollectionreader.cpp