Loading...
Searching...
No Matches
pappso::BafAsciiMsRunReader Class Reference

`#include <bafasciimsrunreader.h>`

Inheritance diagram for pappso::BafAsciiMsRunReader:

## Public Member Functions

| BafAsciiMsRunReader (MsRunIdCstSPtr &msrun_id_csp)
virtual | ~BafAsciiMsRunReader ()
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
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
Public Member Functions inherited from pappso::MsRunReader
| MsRunReader (const MsRunIdCstSPtr &ms_run_id)
| MsRunReader (const MsRunReader &other)
virtual | ~MsRunReader ()
const MsRunIdCstSPtr & | getMsRunId () const
virtual std::size_t | scanNumber2SpectrumIndex (std::size_t scan_number)
| 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.
virtual bool | hasScanNumbers () const
| 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
virtual std::vector< double > | getRetentionTimeLine ()
| retention timeline get retention times along the MSrun in seconds
virtual Trace | getTicChromatogram ()
| get a TIC chromatogram
void | setMonoThread (bool is_mono_thread)
| set only one is_mono_thread to true
bool | isMonoThread () const

## Protected Member Functions

QString | craftLineParserRegExpPattern () const
QRegularExpression | craftLineParserRegExp (QString &pattern) const
bool | parseMassSpectrumLine (QString &line, MassSpectrumLineData &ms_line_data, QRegularExpression &line_regexp) const
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
QualifiedMassSpectrum | qualifiedMassSpectrumFromBafAsciiMSDataFile (std::size_t spectrum_index, bool want_binary_data) const

## Protected Attributes

QString | m_fileName
std::size_t | m_spectrumCount = 0
Protected Attributes inherited from pappso::MsRunReader
MsRunIdCstSPtr | mcsp_msRunId
MsRunReaderScanNumberMultiMap * | mpa_multiMapScanNumber = nullptr

## Friends

class | MsFileAccessor

## Detailed Description

Definition at line 23 of file bafasciimsrunreader.h.

## Constructor & Destructor Documentation

## BafAsciiMsRunReader()

pappso::BafAsciiMsRunReader::BafAsciiMsRunReader | ( | MsRunIdCstSPtr & | msrun_id_csp | ) |

Definition at line 27 of file bafasciimsrunreader.cpp.

: pappso::MsRunReader(msrun_id_csp)
{
// Run the initialization function that checks that the file exists!
initialize();
}
pappso::BafAsciiMsRunReader::initialize
virtual void initialize() override
Definition bafasciimsrunreader.cpp:37
pappso::MsRunReader
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition msrunreader.h:63

References initialize().

## ~BafAsciiMsRunReader()

pappso::BafAsciiMsRunReader::~BafAsciiMsRunReader | ( |  | ) |

virtual

Definition at line 53 of file bafasciimsrunreader.cpp.

{
}

## Member Function Documentation

## accept()

bool pappso::BafAsciiMsRunReader::accept | ( | const QString & | file_name | ) | const

override protected virtual

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 229 of file bafasciimsrunreader.cpp.

{
qDebug();
// Here we just test all the lines of the file to check that they comply with
// the BafAscii format (ascii export from Baf file using the Bruker
// DataAnalysis/Compass software)..
// The format of the file, for MS1 data only is the following:
// <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
// end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
// value.
QString line_regexp_pattern = craftLineParserRegExpPattern();
QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
if(!line_regexp.isValid())
{
qDebug() << "Failed to craft the regular expresssion";
return false;
}
QFile file(file_name);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "Failed to open file" << file_name;
return false;
}
MassSpectrumLineData ms_line_data;
while(!file.atEnd())
{
QString line = file.readLine().trimmed();
if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
{
qDebug() << "Failed to parse a line.";
file.close();
return false;
}
++m_spectrumCount;
}
file.close();
if(m_spectrumCount >= 1)
{
qDebug() << "The file seems indeed to be BafAscii.";
return true;
}
qDebug() << "The file does not seem to be BafAscii.";
return false;
}
CardanoResultCase::line
@ line
pappso::BafAsciiMsRunReader::craftLineParserRegExp
QRegularExpression craftLineParserRegExp(QString &pattern) const
Definition bafasciimsrunreader.cpp:101
pappso::BafAsciiMsRunReader::parseMassSpectrumLine
bool parseMassSpectrumLine(QString &line, MassSpectrumLineData &ms_line_data, QRegularExpression &line_regexp) const
Definition bafasciimsrunreader.cpp:116
pappso::BafAsciiMsRunReader::craftLineParserRegExpPattern
QString craftLineParserRegExpPattern() const
Definition bafasciimsrunreader.cpp:58
pappso::BafAsciiMsRunReader::m_spectrumCount
std::size_t m_spectrumCount
Definition bafasciimsrunreader.h:70

References craftLineParserRegExp(), craftLineParserRegExpPattern(), line, m_spectrumCount, and parseMassSpectrumLine().

Referenced by initialize().

## acquireDevice()

bool pappso::BafAsciiMsRunReader::acquireDevice | ( |  | ) |

override virtual

acquire data back end device

Returns
  bool true if done

Implements pappso::MsRunReader.

Definition at line 686 of file bafasciimsrunreader.cpp.

{
return true;
}

## craftLineParserRegExp()

QRegularExpression pappso::BafAsciiMsRunReader::craftLineParserRegExp | ( | QString & | pattern | ) | const

protected

Definition at line 101 of file bafasciimsrunreader.cpp.

{
QRegularExpression regexp = QRegularExpression(pattern);
if(!regexp.isValid())
{
qDebug() << "The regular expression is not valid:"
<< regexp.errorString();
return QRegularExpression();
}
return QRegularExpression(pattern);
}

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

## craftLineParserRegExpPattern()

QString pappso::BafAsciiMsRunReader::craftLineParserRegExpPattern | ( |  | ) | const

protected

Definition at line 58 of file bafasciimsrunreader.cpp.

{
// Construct the regular expression pattern, piecemeal...
// The retention time as the very first value in the line.
QString regexp_pattern = QString("^(%1)").arg(
Utils::unsignedDoubleNumberNoExponentialRegExp.pattern());
// The ionization mode (positive or negative)
regexp_pattern += QString(",([+-])");
// The ion source type.
regexp_pattern += QString(",(ESI|MALDI)");
// The MS level (ms1 for full scan mass spectrum)
regexp_pattern += QString(",ms(\\d)");
// Do no know what this is for.
regexp_pattern += QString(",(-)");
// The type of peak (profile or centroid).
regexp_pattern += QString(",(profile|line)");
// The m/z range of the mass spectrum.
regexp_pattern +=
QString(",(%1-%2)")
.arg(Utils::unsignedDoubleNumberNoExponentialRegExp.pattern())
.arg(Utils::unsignedDoubleNumberNoExponentialRegExp.pattern());
// The count of peaks following this element in the remaining of the line.
regexp_pattern += QString(",(\\d+)");
// Finally the whole set of ,<mz><space><intensity> pairs to
// then end of the line.
regexp_pattern += QString("(.*$)");
// qDebug() << "The full regexp_pattern:" << regexp_pattern;
return regexp_pattern;
}
pappso::Utils::unsignedDoubleNumberNoExponentialRegExp
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
Definition utils.h:53

References pappso::Utils::unsignedDoubleNumberNoExponentialRegExp.

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

## initialize()

void pappso::BafAsciiMsRunReader::initialize | ( |  | ) |

override protected virtual

Implements pappso::MsRunReader.

Definition at line 37 of file bafasciimsrunreader.cpp.

{
// Use the accept function to parse the whole file, check its
// contents validity and also count the number of spectra (that is,
// of lines).
if(!accept(mcsp_msRunId->getFileName()))
{
throw(pappso::ExceptionNotRecognized(
QString("Failed to initialize reading of file %1 "
"in BafAsciiMsRunReader, for MS run %2:\n")
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
}
pappso::BafAsciiMsRunReader::accept
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,...
Definition bafasciimsrunreader.cpp:229
pappso::ExceptionNotRecognized
excetion to use when an item type is not recognized
Definition exceptionnotrecognized.h:42
pappso::MsRunReader::mcsp_msRunId
MsRunIdCstSPtr mcsp_msRunId
Definition msrunreader.h:175

References accept(), and pappso::MsRunReader::mcsp_msRunId.

Referenced by BafAsciiMsRunReader().

## massSpectrumCstSPtr()

pappso::MassSpectrumCstSPtr pappso::BafAsciiMsRunReader::massSpectrumCstSPtr | ( | std::size_t | spectrum_index | ) |

override virtual

Implements pappso::MsRunReader.

Definition at line 299 of file bafasciimsrunreader.cpp.

{
return qualifiedMassSpectrum(spectrum_index).getMassSpectrumCstSPtr();
}
pappso::BafAsciiMsRunReader::qualifiedMassSpectrum
virtual QualifiedMassSpectrum qualifiedMassSpectrum(std::size_t spectrum_index, bool want_binary_data=true) const override
get a QualifiedMassSpectrum class given its scan number
Definition bafasciimsrunreader.cpp:459
pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
Definition qualifiedmassspectrum.cpp:141

References pappso::QualifiedMassSpectrum::getMassSpectrumCstSPtr(), and qualifiedMassSpectrum().

## massSpectrumSPtr()

pappso::MassSpectrumSPtr pappso::BafAsciiMsRunReader::massSpectrumSPtr | ( | std::size_t | spectrum_index | ) |

override virtual

get a MassSpectrumSPtr class given its spectrum index

Implements pappso::MsRunReader.

Definition at line 292 of file bafasciimsrunreader.cpp.

{
return qualifiedMassSpectrum(spectrum_index).getMassSpectrumSPtr();
}
pappso::QualifiedMassSpectrum::getMassSpectrumSPtr
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
Definition qualifiedmassspectrum.cpp:133

References pappso::QualifiedMassSpectrum::getMassSpectrumSPtr(), and qualifiedMassSpectrum().

## newXicCoordSPtrFromQualifiedMassSpectrum()

XicCoordSPtr pappso::BafAsciiMsRunReader::newXicCoordSPtrFromQualifiedMassSpectrum | ( | const pappso::QualifiedMassSpectrum & | mass_spectrum,
|  | pappso::PrecisionPtr | precision
| ) |  | const

override virtual

get a xic coordinate object from a given spectrum

Implements pappso::MsRunReader.

Definition at line 703 of file bafasciimsrunreader.cpp.

{
throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
.arg(__FILE__)
.arg(__FUNCTION__)
.arg(__LINE__));
}

## newXicCoordSPtrFromSpectrumIndex()

XicCoordSPtr pappso::BafAsciiMsRunReader::newXicCoordSPtrFromSpectrumIndex | ( | std::size_t | spectrum_index,
|  | pappso::PrecisionPtr | precision
| ) |  | const

override virtual

get a xic coordinate object from a given spectrum index

Implements pappso::MsRunReader.

Definition at line 692 of file bafasciimsrunreader.cpp.

{
throw ExceptionNotImplemented(QObject::tr("Not implemented %1 %2 %3")
.arg(__FILE__)
.arg(__FUNCTION__)
.arg(__LINE__));
}

## parseMassSpectrumLine()

bool pappso::BafAsciiMsRunReader::parseMassSpectrumLine | ( | QString & | line,
|  | MassSpectrumLineData & | ms_line_data,
|  | QRegularExpression & | line_regexp
| ) |  | const

protected

Definition at line 116 of file bafasciimsrunreader.cpp.

{
// We get a line from the file, exactly as is and we have to
// parse it using regexp to extract all the data out of it,
// which are then set to ms_line_data.
line = line.trimmed();
// qDebug() << "Current brukerBafAscii format line " << line_count << ": "
// << line.left(30) << " ... " << line.right(30);
QRegularExpressionMatch regexp_match = line_regexp.match(line);
bool ok = false;
if(regexp_match.hasMatch())
{
// qDebug() << "The match succeeded.";
double retention_time = regexp_match.captured(1).toDouble(&ok);
if(!ok)
{
qDebug()
<< "Failed to extract the retention time of the mass spectrum.";
return false;
}
ms_line_data.retentionTime = retention_time;
ms_line_data.ionizationMode = regexp_match.captured(2);
ms_line_data.ionSourceType = regexp_match.captured(3);
int ms_level = regexp_match.captured(4).toInt(&ok);
if(!ok)
{
qDebug() << "Failed to extract the MS level of the mass spectrum.";
return false;
}
ms_line_data.msLevel = ms_level;
QString dash = regexp_match.captured(5);
ms_line_data.dash = dash;
ms_line_data.peakShapeType = regexp_match.captured(6);
QString mz_range = regexp_match.captured(7);
double mz_range_start =
mz_range.left(mz_range.indexOf("-")).toDouble(&ok);
if(!ok)
{
qDebug() << "Failed to extract the start of the m/z range.";
return false;
}
double mz_range_end =
mz_range.right(mz_range.indexOf("-") + 1).toDouble(&ok);
if(!ok)
{
qDebug() << "Failed to extract the end of the m/z range.";
return false;
}
ms_line_data.mz_range =
std::pair<double, double>(mz_range_start, mz_range_end);
// qDebug() << qSetRealNumberPrecision(10)
// << "mz_range_start: " << mz_range_start
// << "mz_range_end: " << mz_range_end;
std::size_t peak_count = regexp_match.captured(8).toULongLong(&ok);
if(!ok)
{
qDebug() << "Failed to extract the number of peaks in the mass "
"spectrum.";
return false;
}
ms_line_data.peakCount = peak_count;
QString peaks = regexp_match.captured(9);
ms_line_data.peakList = peaks.split(",", Qt::SkipEmptyParts);
// qDebug() << "The number of peaks:" << ms_line_data.peakList.size();
// Sanity check:
if(static_cast<std::size_t>(ms_line_data.peakList.size()) !=
ms_line_data.peakCount)
{
qDebug() << "The number of peaks in the mass spectrum does not "
"match the advertised one.";
return false;
}
// qDebug() << "The retention time:" << retention_time
// << "the ionization mode: " << ionization_mode
// << "the source type: " << source_type
// << "MS level is:" << ms_level
// << "peak shape type: " << peak_shape_type
// << "m/z range: " << mz_range << "peak count: " <<
// peak_count
// << "and peaks: " << peaks.left(100) << " ... "
// << peaks.right(100) << "";
}
else
{
qDebug() << "The match failed.";
return false;
}
return true;
}

References pappso::MassSpectrumLineData::dash, pappso::MassSpectrumLineData::ionizationMode, pappso::MassSpectrumLineData::ionSourceType, line, pappso::MassSpectrumLineData::msLevel, pappso::MassSpectrumLineData::mz_range, pappso::MassSpectrumLineData::peakCount, pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::peakShapeType, and pappso::MassSpectrumLineData::retentionTime.

Referenced by accept(), qualifiedMassSpectrumFromBafAsciiMSDataFile(), and readSpectrumCollectionByMsLevel().

## qualifiedMassSpectrum()

QualifiedMassSpectrum pappso::BafAsciiMsRunReader::qualifiedMassSpectrum | ( | std::size_t | spectrum_index,
|  | bool | want_binary_data = `true`
| ) |  | const

override virtual

get a QualifiedMassSpectrum class given its scan number

Implements pappso::MsRunReader.

Definition at line 459 of file bafasciimsrunreader.cpp.

{
// qDebug();
QualifiedMassSpectrum qualified_mass_spectrum =
qualifiedMassSpectrumFromBafAsciiMSDataFile(spectrum_index,
want_binary_data);
// qDebug() << "qualified mass spectrum has size:"
// << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
return qualified_mass_spectrum;
}
pappso::BafAsciiMsRunReader::qualifiedMassSpectrumFromBafAsciiMSDataFile
QualifiedMassSpectrum qualifiedMassSpectrumFromBafAsciiMSDataFile(std::size_t spectrum_index, bool want_binary_data) const
Definition bafasciimsrunreader.cpp:306

References qualifiedMassSpectrumFromBafAsciiMSDataFile().

Referenced by massSpectrumCstSPtr(), and massSpectrumSPtr().

## qualifiedMassSpectrumFromBafAsciiMSDataFile()

QualifiedMassSpectrum pappso::BafAsciiMsRunReader::qualifiedMassSpectrumFromBafAsciiMSDataFile | ( | std::size_t | spectrum_index,
|  | bool | want_binary_data
| ) |  | const

protected

Definition at line 306 of file bafasciimsrunreader.cpp.

{
// qDebug();
// Each line holds the data of one mass spectrum. There are other
// metadata at the beginning of the line.
QString file_name = mcsp_msRunId->getFileName();
QFile file(file_name);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
throw(PappsoException(QString("%1-%2 Error reading file %3 in "
"BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// The format of the file, for MS1 data only is the following:
// <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
// end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
// value.
QString line_regexp_pattern = craftLineParserRegExpPattern();
QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
if(!line_regexp.isValid())
{
throw(PappsoException(
QString("%1-%2 Failed to craft the regular expresssion while reading "
"file %3 in BafAsciiMsRunReader, for MS run %4:")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
QualifiedMassSpectrum qualified_mass_spectrum;
MassSpectrumLineData ms_line_data;
std::size_t mass_spectrum_index = 0;
while(!file.atEnd())
{
if(mass_spectrum_index < spectrum_index)
continue;
QString line = file.readLine().trimmed();
if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// At this point we have all the data inside the ms_line_data structure.
// If the user wants the binary data, that is, the mass spectrometric
// data, we need to prepare these.
MassSpectrumId mass_spectrum_id(mcsp_msRunId, mass_spectrum_index);
qualified_mass_spectrum.setMassSpectrumId(mass_spectrum_id);
qualified_mass_spectrum.setMsLevel(ms_line_data.msLevel);
qualified_mass_spectrum.setRtInSeconds(ms_line_data.retentionTime * 60);
// Should we create the peak list?
if(want_binary_data)
{
// qDebug() << "The binary data are wanted.";
MassSpectrum mass_spectrum;
bool ok = false;
for(int iter = 0; iter < ms_line_data.peakList.size(); ++iter)
{
QString pair_string = ms_line_data.peakList.at(iter);
// qDebug() << "The pair string:" << pair_string;
QStringList mz_and_intensity_list =
pair_string.split(" ", Qt::SkipEmptyParts);
double mz = mz_and_intensity_list.first().toDouble(&ok);
if(!ok)
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// qDebug() << qSetRealNumberPrecision(10) << "m/z:" << mz;
double intensity = mz_and_intensity_list.last().toDouble(&ok);
if(!ok)
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// qDebug() << qSetRealNumberPrecision(10)
// << "intensity:" << intensity;
// qDebug() << "Emplacing back with:" << mz << "-" << intensity;
mass_spectrum.emplace_back(mz, intensity);
}
MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
}
else
qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
// qDebug() << "qualified mass spectrum has size:"
// << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
break;
}
// End of
// while(!file.atEnd())
file.close();
return qualified_mass_spectrum;
}
pappso::PrecisionUnit::mz
@ mz
pappso::MassSpectrumSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
Definition massspectrum.h:56

References craftLineParserRegExp(), craftLineParserRegExpPattern(), line, pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, pappso::mz, parseMassSpectrumLine(), pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::retentionTime, pappso::QualifiedMassSpectrum::setMassSpectrumId(), pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), and pappso::QualifiedMassSpectrum::setRtInSeconds().

Referenced by qualifiedMassSpectrum().

## readSpectrumCollection()

void pappso::BafAsciiMsRunReader::readSpectrumCollection | ( | SpectrumCollectionHandlerInterface & | handler | ) |

override virtual

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

Implements pappso::MsRunReader.

Definition at line 476 of file bafasciimsrunreader.cpp.

{
readSpectrumCollectionByMsLevel(handler, 0);
}
pappso::BafAsciiMsRunReader::readSpectrumCollectionByMsLevel
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
Definition bafasciimsrunreader.cpp:484

References readSpectrumCollectionByMsLevel().

Referenced by readSpectrumCollection2().

## readSpectrumCollection2()

void pappso::BafAsciiMsRunReader::readSpectrumCollection2 | ( | const MsRunReadConfig & | config,
|  | SpectrumCollectionHandlerInterface & | handler
| ) |  |

override virtual

Implements pappso::MsRunReader.

Definition at line 666 of file bafasciimsrunreader.cpp.

{
return readSpectrumCollection(handler);
}
pappso::BafAsciiMsRunReader::readSpectrumCollection
virtual void readSpectrumCollection(SpectrumCollectionHandlerInterface &handler) override
function to visit an MsRunReader and get each Spectrum in a spectrum collection handler
Definition bafasciimsrunreader.cpp:476

References readSpectrumCollection().

## readSpectrumCollectionByMsLevel()

void pappso::BafAsciiMsRunReader::readSpectrumCollectionByMsLevel | ( | SpectrumCollectionHandlerInterface & | handler,
|  | unsigned int | ms_level
| ) |  |

override virtual

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

Implements pappso::MsRunReader.

Definition at line 484 of file bafasciimsrunreader.cpp.

{
qDebug();
// Each line holds the data of one mass spectrum. There are other
// metadata at the beginning of the line.
// Does the handler 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 = handler.needPeakList();
QString file_name = mcsp_msRunId->getFileName();
QFile file(file_name);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
throw(PappsoException(QString("%1-%2 Error reading file %3 in "
"BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// The format of the file, for MS1 data only is the following:
// <rt time in min>,+,ESI,ms1,-,profile,<m/z range start>-<m/z range
// end>,512704,<m/z> <int>,<m/z> <int>,.. One such line per retention time
// value.
QString line_regexp_pattern = craftLineParserRegExpPattern();
QRegularExpression line_regexp = craftLineParserRegExp(line_regexp_pattern);
if(!line_regexp.isValid())
{
throw(PappsoException(
QString(
"%1-%2 Failed to craft the regular expresssion while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
MassSpectrumLineData ms_line_data;
std::size_t mass_spectrum_index = 0;
while(!file.atEnd())
{
// qDebug() << "Iterating at line index:" << mass_spectrum_index;
// If the user of this reader instance wants to stop reading the
// spectra, then break this loop.
if(handler.shouldStop())
{
qDebug() << "The operation was cancelled. Breaking the loop.";
break;
}
QString line = file.readLine().trimmed();
if(!parseMassSpectrumLine(line, ms_line_data, line_regexp))
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line whilereading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// qDebug() << "The size of the peaks string list:"
// << ms_line_data.peakList.size();
// At this point we have all the data inside the ms_line_data structure.
// If the user wants the binary data, that is, the mass spectrometric
// data, we need to prepare these.
MassSpectrumId mass_spectrum_id(mcsp_msRunId, mass_spectrum_index);
QualifiedMassSpectrum qualified_mass_spectrum(mass_spectrum_id);
qualified_mass_spectrum.setMsLevel(ms_line_data.msLevel);
qualified_mass_spectrum.setRtInSeconds(ms_line_data.retentionTime * 60);
// Should we create the peak list?
if(want_binary_data)
{
// qDebug() << "The binary data are wanted.";
MassSpectrum mass_spectrum;
bool ok = false;
for(int iter = 0; iter < ms_line_data.peakList.size(); ++iter)
{
QString pair_string = ms_line_data.peakList.at(iter);
// qDebug() << "The pair string:" << pair_string;
QStringList mz_and_intensity_list =
pair_string.split(" ", Qt::SkipEmptyParts);
double mz = mz_and_intensity_list.first().toDouble(&ok);
if(!ok)
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// qDebug() << qSetRealNumberPrecision(10) << "m/z:" << mz;
double intensity = mz_and_intensity_list.last().toDouble(&ok);
if(!ok)
{
file.close();
throw(PappsoException(
QString("%1-%2 Failed to parse line while reading file %3 "
"in BafAsciiMsRunReader, for MS run %4:\n")
.arg(__FILE__)
.arg(__LINE__)
.arg(mcsp_msRunId->getFileName())
.arg(mcsp_msRunId.get()->toString())));
}
// qDebug() << qSetRealNumberPrecision(10)
// << "intensity:" << intensity;
// qDebug() << "Emplacing back with:" << mz << "-" << intensity;
mass_spectrum.emplace_back(mz, intensity);
}
MassSpectrumSPtr spectrum_sp = mass_spectrum.makeMassSpectrumSPtr();
qualified_mass_spectrum.setMassSpectrumSPtr(spectrum_sp);
}
else
qualified_mass_spectrum.setMassSpectrumSPtr(nullptr);
// qDebug() << "qualified mass spectrum has size:"
// << qualified_mass_spectrum.getMassSpectrumSPtr()->size();
// The handler will receive the index of the mass spectrum in the
// current run via the mass spectrum id member datum.
// Only hand over the mass spectrum to the handler if the
// requested ms_level matches: if ms_level is 0, then any
// mass spectrum of any msLevel will be ok. If ms_level is not 0,
// then we only hand over the mass spectrum if its msLevel is
// exactly equal to ms_level.
if(ms_level == 0 || qualified_mass_spectrum.getMsLevel() == ms_level)
{
handler.setQualifiedMassSpectrum(qualified_mass_spectrum);
}
// This is and index of the spectrum in the file, not a count
// of the mass spectra actually handed over to the handler.
++mass_spectrum_index;
}
// End of
// while(!file.atEnd())
file.close();
qDebug() << "Loading ended";
handler.loadingEnded();
}

References craftLineParserRegExp(), craftLineParserRegExpPattern(), pappso::QualifiedMassSpectrum::getMsLevel(), line, pappso::SpectrumCollectionHandlerInterface::loadingEnded(), pappso::MassSpectrum::makeMassSpectrumSPtr(), pappso::MsRunReader::mcsp_msRunId, pappso::MassSpectrumLineData::msLevel, pappso::mz, pappso::SpectrumCollectionHandlerInterface::needPeakList(), parseMassSpectrumLine(), pappso::MassSpectrumLineData::peakList, pappso::MassSpectrumLineData::retentionTime, pappso::QualifiedMassSpectrum::setMassSpectrumSPtr(), pappso::QualifiedMassSpectrum::setMsLevel(), pappso::SpectrumCollectionHandlerInterface::setQualifiedMassSpectrum(), pappso::QualifiedMassSpectrum::setRtInSeconds(), and pappso::SpectrumCollectionHandlerInterface::shouldStop().

Referenced by readSpectrumCollection().

## releaseDevice()

bool pappso::BafAsciiMsRunReader::releaseDevice | ( |  | ) |

override virtual

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 680 of file bafasciimsrunreader.cpp.

{
return true;
}

## spectrumListSize()

std::size_t pappso::BafAsciiMsRunReader::spectrumListSize | ( |  | ) | const

override virtual

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

Implements pappso::MsRunReader.

Definition at line 674 of file bafasciimsrunreader.cpp.

{
return m_spectrumCount;
}

References m_spectrumCount.

## Friends And Related Symbol Documentation

## MsFileAccessor

friend class MsFileAccessor

friend

Definition at line 25 of file bafasciimsrunreader.h.

## Member Data Documentation

## m_fileName

QString pappso::BafAsciiMsRunReader::m_fileName

protected

Definition at line 67 of file bafasciimsrunreader.h.

## m_spectrumCount

std::size_t pappso::BafAsciiMsRunReader::m_spectrumCount = 0

mutable protected

Definition at line 70 of file bafasciimsrunreader.h.

Referenced by accept(), and spectrumListSize().

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

- pappsomspp/msrun/bafasciimsrunreader.h
- pappsomspp/msrun/bafasciimsrunreader.cpp