Loading...
Searching...
No Matches
pappso::cbor::mzcbor::Spectrum Struct Reference

`#include <spectrum.h>`

## Public Member Functions

void | fromCbor (CborStreamReader &reader, bool want_binary_data)
| fill the structure reading data from a CBOR stream
QJsonObject | toJsonObject () const
| write the structure to a JSON object This is a simplified representation for easy JSON data handling binary arrays are decoded in simple traces
void | toMgf (QTextStream &output, MsRunIdCstSPtr msrun_id_csptr) const
| write spectrum in MGF text format
void | decodeTrace (pappso::Trace &trace) const
uint | getMsLevel () const
double | getRtInSeconds () const
qint64 | getTotalIonCount () const

## Static Public Member Functions

static std::map< QString, pappso::cbor::mzcbor::CvParam > | readScanCvParams (CborStreamReader &reader)

## Public Attributes

QString | id
std::size_t | index
std::size_t | defaultArrayLength
CvParamMap | cvParamMap
CvParamMap | scanListCvParamMap
CvParamMap | precursorListCvParamMap
std::vector< Scan > | scanList
std::vector< Precursor > | precursorList
std::vector< BinaryDataArray > | binaryDataArrayList

## Detailed Description

Todo
  write docs

Definition at line 50 of file spectrum.h.

## Member Function Documentation

## decodeTrace()

void pappso::cbor::mzcbor::Spectrum::decodeTrace | ( | pappso::Trace & | trace | ) | const

Definition at line 356 of file spectrum.cpp.

{
qDebug();
std::vector<pappso_double> xVector;
std::vector<pappso_double> yVector;
for(auto &binary_array : binaryDataArrayList)
{
qDebug();
if(binary_array.isIntensity())
{
qDebug();
binary_array.decodeVector(defaultArrayLength, yVector);
}
else if(binary_array.isMz())
{
qDebug();
binary_array.decodeVector(defaultArrayLength, xVector);
}
else
{
throw pappso::ExceptionNotFound(QObject::tr(
"error in pappso::cbor::mzcbor::Spectrum::decodeTrace: binary vector type not found"));
}
qDebug();
}
qDebug();
trace.initialize(xVector, yVector);
qDebug();
}
pappso::Trace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition trace.cpp:597
pappso::cbor::mzcbor::Spectrum::binaryDataArrayList
std::vector< BinaryDataArray > binaryDataArrayList
Definition spectrum.h:90
pappso::cbor::mzcbor::Spectrum::defaultArrayLength
std::size_t defaultArrayLength
Definition spectrum.h:82

References binaryDataArrayList, defaultArrayLength, and pappso::Trace::initialize().

Referenced by pappso::MzcborMsRunReader::massSpectrumSPtr(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum(), toJsonObject(), and toMgf().

## fromCbor()

void pappso::cbor::mzcbor::Spectrum::fromCbor | ( | CborStreamReader & | reader,
|  | bool | want_binary_data )

fill the structure reading data from a CBOR stream

Parameters

  reader | CBOR stream
  want_binary_data | if true, stores also binary data array list

Definition at line 43 of file spectrum.cpp.

{
QString txt_value;
// cborBinaryDataArray.clear();
precursorList.clear();
defaultArrayLength = 0;
index = 0;
cvParamMap.clear();
scanListCvParamMap.clear();
scanList.clear();
id.clear();
qDebug();
if(reader.isInvalid())
{
throw pappso::PappsoException(
QObject::tr("ERROR in Spectrum::fromCbor :\ncbor is not valid"));
}
if(reader.enterContainer())
{
while(reader.hasNext() && (!reader.isInvalid()))
{
if(reader.isString())
{
reader.decodeString(txt_value);
qDebug() << txt_value;
if(txt_value == "id")
{
reader.decodeString(txt_value);
qDebug() << txt_value;
id = txt_value;
}
else if(txt_value == "index")
{
index = reader.toUnsignedInteger();
reader.next();
}
else if(txt_value == "defaultArrayLength")
{
defaultArrayLength = reader.toUnsignedInteger();
reader.next();
}
else if(txt_value == "cvParam")
{
cvParamMap.fromCbor(reader);
}
else if(txt_value == "scanList")
{
// mpa_cborReader->next();
reader.enterContainer();
while(reader.hasNext() && (!reader.isInvalid()))
{
if(reader.isString())
{
if(reader.decodeString(txt_value))
{
qDebug() << txt_value;
if(txt_value == "cvParam")
{
scanListCvParamMap.fromCbor(reader);
}
else if(txt_value == "scan")
{
// scan array
reader.enterContainer();
while(reader.hasNext() && (!reader.isInvalid()))
{
// scan array
Scan scan;
scan.fromCbor(reader);
scanList.emplace_back(scan);
}
reader.leaveContainer();
}
}
else
{
reader.next();
}
}
else
{
reader.next();
}
}
reader.leaveContainer();
}
else if(txt_value == "precursorList")
{
reader.enterContainer();
while(reader.hasNext() && (!reader.isInvalid()))
{
if(reader.isString())
{
if(reader.decodeString(txt_value))
{
qDebug() << txt_value;
if(txt_value == "cvParam")
{
precursorListCvParamMap.fromCbor(reader);
}
else if(txt_value == "precursor")
{
reader
.enterContainer(); // array
while(reader.hasNext() && (!reader.isInvalid()))
{
// scan array
Precursor precursor;
precursor.fromCbor(reader);
precursorList.emplace_back(precursor);
}
reader
.leaveContainer(); // array
// reader.next();
}
else
{
reader.next();
}
}
else
{
reader.next();
}
}
else
{
reader.next();
}
}
reader.leaveContainer();
}
else if(txt_value == "binaryDataArray")
{
if(want_binary_data)
{
reader.enterContainer(); // start array
while(reader.hasNext())
{
BinaryDataArray data_array;
data_array.fromCbor(reader);
binaryDataArrayList.emplace_back(data_array);
}
reader.leaveContainer(); // end array
}
else
{
reader.next();
}
}
else
{
reader.next();
}
}
// reader.next();
}
reader.leaveContainer();
}
else
{
throw pappso::PappsoException(QObject::tr("ERROR in Spectrum::fromCbor : no container"));
}
if(reader.lastError() != QCborError::NoError)
{
throw pappso::PappsoException(
QObject::tr("ERROR in Spectrum::fromCbor :\n%1").arg(reader.lastError().toString()));
}
}
pappso::cbor::mzcbor::Spectrum::cvParamMap
CvParamMap cvParamMap
Definition spectrum.h:84
pappso::cbor::mzcbor::Spectrum::precursorList
std::vector< Precursor > precursorList
Definition spectrum.h:89
pappso::cbor::mzcbor::Spectrum::scanList
std::vector< Scan > scanList
Definition spectrum.h:88
pappso::cbor::mzcbor::Spectrum::index
std::size_t index
Definition spectrum.h:81
pappso::cbor::mzcbor::Spectrum::precursorListCvParamMap
CvParamMap precursorListCvParamMap
Definition spectrum.h:86
pappso::cbor::mzcbor::Spectrum::scanListCvParamMap
CvParamMap scanListCvParamMap
Definition spectrum.h:85

References binaryDataArrayList, cvParamMap, pappso::cbor::CborStreamReader::decodeString(), defaultArrayLength, pappso::cbor::mzcbor::BinaryDataArray::fromCbor(), pappso::cbor::mzcbor::Precursor::fromCbor(), pappso::cbor::mzcbor::Scan::fromCbor(), index, precursorList, precursorListCvParamMap, scanList, and scanListCvParamMap.

Referenced by pappso::MzcborMsRunReader::fillMzcborSpectrum(), and pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum().

## getMsLevel()

uint pappso::cbor::mzcbor::Spectrum::getMsLevel | ( |  | ) | const

Definition at line 328 of file spectrum.cpp.

{
// <cvParam cvRef="MS" accession="MS:1000511" value="1" name="ms level" />
auto it = cvParamMap.find("MS:1000511");
if(it == cvParamMap.end())
{
throw pappso::ExceptionNotFound(QObject::tr("MS level not found in cvParam map"));
}
qDebug() << it->first << " " << it->second.valueInt;
return it->second.valueInt;
}

References cvParamMap.

Referenced by pappso::MzcborMsRunReader::qualifiedMassSpectrum(), and pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum().

## getRtInSeconds()

double pappso::cbor::mzcbor::Spectrum::getRtInSeconds | ( |  | ) | const

Definition at line 342 of file spectrum.cpp.

{
if(scanList.size() == 0)
{
throw pappso::ExceptionNotFound(QObject::tr("scan list is empty in spectrum"));
}
if(scanList.size() > 1)
{
throw pappso::ExceptionNotFound(QObject::tr("too many scans in spectrum"));
}
return scanList.front().getRtInSeconds();
}

References scanList.

Referenced by pappso::MzcborMsRunReader::newXicCoordSPtrFromSpectrumIndex(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), and pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum().

## getTotalIonCount()

qint64 pappso::cbor::mzcbor::Spectrum::getTotalIonCount | ( |  | ) | const

Definition at line 313 of file spectrum.cpp.

{
// <cvParam cvRef="MS" accession="MS:1000285" value="17377980" name="total ion current" />
auto it = cvParamMap.find("MS:1000285");
if(it == cvParamMap.end())
{
throw pappso::ExceptionNotFound(QObject::tr("total ion count not found in cvParam map"));
}
qDebug() << it->first << " " << it->second.valueInt;
return it->second.valueInt;
}

References cvParamMap.

## readScanCvParams()

std::map< QString, pappso::cbor::mzcbor::CvParam > pappso::cbor::mzcbor::Spectrum::readScanCvParams | ( | CborStreamReader & | reader | ) |

static

Definition at line 278 of file spectrum.cpp.

{
CvParamMap cv_params;
reader.enterContainer();
QString txt_value;
while(reader.hasNext() && (!reader.isInvalid()))
{
if(reader.isString())
{
if(reader.decodeString(txt_value))
{
qDebug() << txt_value;
if(txt_value == "cvParam")
{
cv_params.fromCbor(reader);
}
else
{
reader.next();
}
}
}
else
{
reader.next();
}
}
reader.leaveContainer();
return cv_params;
}

References pappso::cbor::CborStreamReader::decodeString(), and pappso::cbor::mzcbor::CvParamMap::fromCbor().

## toJsonObject()

QJsonObject pappso::cbor::mzcbor::Spectrum::toJsonObject | ( |  | ) | const

write the structure to a JSON object This is a simplified representation for easy JSON data handling binary arrays are decoded in simple traces

Returns
  QJsonObject

Definition at line 231 of file spectrum.cpp.

{
QJsonObject spectrum_json;
spectrum_json.insert("id", id);
spectrum_json.insert("index", (qint64)index);
spectrum_json.insert("defaultArrayLength", (qint64)defaultArrayLength);
spectrum_json.insert("cvParam", cvParamMap.toJsonArray());
QJsonObject scan_list;
// QJsonObject scan_list_cvparam;
scan_list.insert("cvParam", scanListCvParamMap.toJsonArray());
QJsonArray scan_array;
for(auto &scan : scanList)
{
scan_array.append(scan.toJsonObject());
}
scan_list.insert("scan", scan_array);
spectrum_json.insert("scanList", scan_list);
if(!precursorList.empty())
{
QJsonObject precursor_list;
// QJsonObject scan_list_cvparam;
precursor_list.insert("cvParam", precursorListCvParamMap.toJsonArray());
QJsonArray precursor_array;
for(auto &precursor : precursorList)
{
precursor_array.append(precursor.toJsonObject());
}
precursor_list.insert("precursor", precursor_array);
spectrum_json.insert("precursorList", precursor_list);
}
if(!binaryDataArrayList.empty())
{
Trace trace;
decodeTrace(trace);
spectrum_json.insert("spectrum", trace.toJsonObject());
}
return spectrum_json;
}
pappso::cbor::mzcbor::Spectrum::decodeTrace
void decodeTrace(pappso::Trace &trace) const
Definition spectrum.cpp:356

References binaryDataArrayList, cvParamMap, decodeTrace(), defaultArrayLength, index, precursorList, precursorListCvParamMap, scanList, scanListCvParamMap, and pappso::Trace::toJsonObject().

## toMgf()

void pappso::cbor::mzcbor::Spectrum::toMgf | ( | QTextStream & | output,
|  | MsRunIdCstSPtr | msrun_id_csptr ) const

write spectrum in MGF text format

Definition at line 389 of file spectrum.cpp.

{
// BEGIN IONS
// TITLE=20120906_balliau_extract_1_A01_urnb-1.2016.2016.3
// RTINSECONDS=679.467
// PEPMASS=417.210251631473 92010.6328125
// CHARGE=3+
// 88.03964233 1132.5438232422
// 91.05783844 1945.9479980469
// 93.03697968 6423.5581054688
// 93.8877182 949.33984375
output << "BEGIN IONS" << Qt::endl;
QString title;
if(msrun_id_csptr.get() != nullptr)
{
title = msrun_id_csptr.get()->getSampleName();
}
output << "TITLE=" << title << "." << index << Qt::endl;
output << "RTINSECONDS=" << QString::number(scanList.front().getRtInSeconds(), 'f', 4)
<< Qt::endl;
bool is_ok;
double intensity = precursorList.front().selectedIonList.front().getIntensity(&is_ok);
if(is_ok)
{
output << "PEPMASS="
<< QString::number(precursorList.front().selectedIonList.front().getMz(), 'f', 8)
<< " " << QString::number(intensity, 'g', 10) << Qt::endl;
}
else
{
output << "PEPMASS="
<< QString::number(precursorList.front().selectedIonList.front().getMz(), 'f', 8)
<< Qt::endl;
}
output << "CHARGE=" << precursorList.front().selectedIonList.front().getChargeState() << "+"
<< Qt::endl;
Trace trace;
decodeTrace(trace);
for(const pappso::DataPoint &one_point : trace)
{
output << QString::number(one_point.x, 'f', 8) << " " << QString::number(one_point.y, 'f', 8)
<< Qt::endl;
}
output << "END IONS" << Qt::endl;
}

References decodeTrace(), index, precursorList, and scanList.

## Member Data Documentation

## binaryDataArrayList

std::vector<BinaryDataArray> pappso::cbor::mzcbor::Spectrum::binaryDataArrayList

Definition at line 90 of file spectrum.h.

Referenced by decodeTrace(), fromCbor(), pappso::MzcborMsRunReader::massSpectrumSPtr(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum(), and toJsonObject().

## cvParamMap

CvParamMap pappso::cbor::mzcbor::Spectrum::cvParamMap

Definition at line 84 of file spectrum.h.

Referenced by fromCbor(), getMsLevel(), getTotalIonCount(), and toJsonObject().

## defaultArrayLength

std::size_t pappso::cbor::mzcbor::Spectrum::defaultArrayLength

Definition at line 82 of file spectrum.h.

Referenced by decodeTrace(), fromCbor(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum(), and toJsonObject().

## id

QString pappso::cbor::mzcbor::Spectrum::id

Definition at line 80 of file spectrum.h.

Referenced by pappso::MzcborMsRunReader::fillMzcborSpectrum(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), and pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum().

## index

std::size_t pappso::cbor::mzcbor::Spectrum::index

Definition at line 81 of file spectrum.h.

Referenced by fromCbor(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum(), toJsonObject(), and toMgf().

## precursorList

std::vector<Precursor> pappso::cbor::mzcbor::Spectrum::precursorList

Definition at line 89 of file spectrum.h.

Referenced by fromCbor(), pappso::MzcborMsRunReader::newXicCoordSPtrFromSpectrumIndex(), pappso::MzcborMsRunReader::qualifiedMassSpectrum(), pappso::cbor::mzcbor::MzcborSpectrumCollectionReader::readSpectrum(), toJsonObject(), and toMgf().

## precursorListCvParamMap

CvParamMap pappso::cbor::mzcbor::Spectrum::precursorListCvParamMap

Definition at line 86 of file spectrum.h.

Referenced by fromCbor(), and toJsonObject().

## scanList

std::vector<Scan> pappso::cbor::mzcbor::Spectrum::scanList

Definition at line 88 of file spectrum.h.

Referenced by fromCbor(), getRtInSeconds(), toJsonObject(), and toMgf().

## scanListCvParamMap

CvParamMap pappso::cbor::mzcbor::Spectrum::scanListCvParamMap

Definition at line 85 of file spectrum.h.

Referenced by fromCbor(), and toJsonObject().

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

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