11#include <pwiz/data/msdata/DefaultReaderList.hpp>
45 QString(
"Failed to initialize reading of file %1 "
46 "in BafAsciiMsRunReader, for MS run %2:\n")
64 QString regexp_pattern = QString(
"^(%1)").arg(
68 regexp_pattern += QString(
",([+-])");
71 regexp_pattern += QString(
",(ESI|MALDI)");
74 regexp_pattern += QString(
",ms(\\d)");
77 regexp_pattern += QString(
",(-)");
80 regexp_pattern += QString(
",(profile|line)");
89 regexp_pattern += QString(
",(\\d+)");
93 regexp_pattern += QString(
"(.*$)");
97 return regexp_pattern;
103 QRegularExpression regexp = QRegularExpression(pattern);
105 if(!regexp.isValid())
107 qDebug() <<
"The regular expression is not valid:"
108 << regexp.errorString();
109 return QRegularExpression();
112 return QRegularExpression(pattern);
119 QRegularExpression &line_regexp)
const
130 QRegularExpressionMatch regexp_match = line_regexp.match(
line);
133 if(regexp_match.hasMatch())
137 double retention_time = regexp_match.captured(1).toDouble(&ok);
141 <<
"Failed to extract the retention time of the mass spectrum.";
150 int ms_level = regexp_match.captured(4).toInt(&ok);
153 qDebug() <<
"Failed to extract the MS level of the mass spectrum.";
156 ms_line_data.
msLevel = ms_level;
158 QString dash = regexp_match.captured(5);
159 ms_line_data.
dash = dash;
163 QString mz_range = regexp_match.captured(7);
165 double mz_range_start =
166 mz_range.left(mz_range.indexOf(
"-")).toDouble(&ok);
169 qDebug() <<
"Failed to extract the start of the m/z range.";
172 double mz_range_end =
173 mz_range.right(mz_range.indexOf(
"-") + 1).toDouble(&ok);
176 qDebug() <<
"Failed to extract the end of the m/z range.";
180 std::pair<double, double>(mz_range_start, mz_range_end);
186 std::size_t peak_count = regexp_match.captured(8).toULongLong(&ok);
189 qDebug() <<
"Failed to extract the number of peaks in the mass "
195 QString peaks = regexp_match.captured(9);
196 ms_line_data.
peakList = peaks.split(
",", Qt::SkipEmptyParts);
201 if(
static_cast<std::size_t
>(ms_line_data.
peakList.size()) !=
204 qDebug() <<
"The number of peaks in the mass spectrum does not "
205 "match the advertised one.";
221 qDebug() <<
"The match failed.";
245 if(!line_regexp.isValid())
247 qDebug() <<
"Failed to craft the regular expresssion";
252 QFile file(file_name);
254 if(!file.open(QFile::ReadOnly | QFile::Text))
256 qDebug() <<
"Failed to open file" << file_name;
265 QString
line = file.readLine().trimmed();
269 qDebug() <<
"Failed to parse a line.";
282 qDebug() <<
"The file seems indeed to be BafAscii.";
286 qDebug() <<
"The file does not seem to be BafAscii.";
307 std::size_t spectrum_index,
bool want_binary_data)
const
316 QFile file(file_name);
318 if(!file.open(QFile::ReadOnly | QFile::Text))
321 "BafAsciiMsRunReader, for MS run %4:\n")
336 if(!line_regexp.isValid())
339 QString(
"%1-%2 Failed to craft the regular expresssion while reading "
340 "file %3 in BafAsciiMsRunReader, for MS run %4:")
349 std::size_t mass_spectrum_index = 0;
353 if(mass_spectrum_index < spectrum_index)
357 QString
line = file.readLine().trimmed();
364 QString(
"%1-%2 Failed to parse line while reading file %3 "
365 "in BafAsciiMsRunReader, for MS run %4:\n")
391 for(
int iter = 0; iter < ms_line_data.
peakList.size(); ++iter)
393 QString pair_string = ms_line_data.
peakList.at(iter);
397 QStringList mz_and_intensity_list =
398 pair_string.split(
" ", Qt::SkipEmptyParts);
400 double mz = mz_and_intensity_list.first().toDouble(&ok);
406 QString(
"%1-%2 Failed to parse line while reading file %3 "
407 "in BafAsciiMsRunReader, for MS run %4:\n")
416 double intensity = mz_and_intensity_list.last().toDouble(&ok);
422 QString(
"%1-%2 Failed to parse line while reading file %3 "
423 "in BafAsciiMsRunReader, for MS run %4:\n")
435 mass_spectrum.emplace_back(
mz, intensity);
454 return qualified_mass_spectrum;
460 bool want_binary_data)
const
471 return qualified_mass_spectrum;
499 QFile file(file_name);
501 if(!file.open(QFile::ReadOnly | QFile::Text))
504 "BafAsciiMsRunReader, for MS run %4:\n")
519 if(!line_regexp.isValid())
523 "%1-%2 Failed to craft the regular expresssion while reading file %3 "
524 "in BafAsciiMsRunReader, for MS run %4:\n")
532 std::size_t mass_spectrum_index = 0;
542 qDebug() <<
"The operation was cancelled. Breaking the loop.";
546 QString
line = file.readLine().trimmed();
553 QString(
"%1-%2 Failed to parse line whilereading file %3 "
554 "in BafAsciiMsRunReader, for MS run %4:\n")
584 for(
int iter = 0; iter < ms_line_data.
peakList.size(); ++iter)
586 QString pair_string = ms_line_data.
peakList.at(iter);
590 QStringList mz_and_intensity_list =
591 pair_string.split(
" ", Qt::SkipEmptyParts);
593 double mz = mz_and_intensity_list.first().toDouble(&ok);
599 QString(
"%1-%2 Failed to parse line while reading file %3 "
600 "in BafAsciiMsRunReader, for MS run %4:\n")
609 double intensity = mz_and_intensity_list.last().toDouble(&ok);
615 QString(
"%1-%2 Failed to parse line while reading file %3 "
616 "in BafAsciiMsRunReader, for MS run %4:\n")
628 mass_spectrum.emplace_back(
mz, intensity);
647 if(ms_level == 0 || qualified_mass_spectrum.
getMsLevel() == ms_level)
654 ++mass_spectrum_index;
661 qDebug() <<
"Loading ended";
693 std::size_t spectrum_index [[maybe_unused]],
QualifiedMassSpectrum qualifiedMassSpectrumFromBafAsciiMSDataFile(std::size_t spectrum_index, bool want_binary_data) const
QRegularExpression craftLineParserRegExp(QString &pattern) const
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
BafAsciiMsRunReader(MsRunIdCstSPtr &msrun_id_csp)
virtual bool acquireDevice() override
acquire data back end device
virtual pappso::XicCoordSPtr newXicCoordSPtrFromQualifiedMassSpectrum(const pappso::QualifiedMassSpectrum &mass_spectrum, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum
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,...
virtual void readSpectrumCollection2(const MsRunReadConfig &config, SpectrumCollectionHandlerInterface &handler) 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 pappso::XicCoordSPtr newXicCoordSPtrFromSpectrumIndex(std::size_t spectrum_index, pappso::PrecisionPtr precision) const override
get a xic coordinate object from a given spectrum index
virtual MassSpectrumSPtr massSpectrumSPtr(std::size_t spectrum_index) override
get a MassSpectrumSPtr class given its spectrum index
virtual bool releaseDevice() override
release data back end device if a the data back end is released, the developper has to use acquireDev...
virtual ~BafAsciiMsRunReader()
virtual MassSpectrumCstSPtr massSpectrumCstSPtr(std::size_t spectrum_index) override
virtual void initialize() override
virtual std::size_t spectrumListSize() const override
get the totat number of spectrum conained in the MSrun data file
bool parseMassSpectrumLine(QString &line, MassSpectrumLineData &ms_line_data, QRegularExpression &line_regexp) const
QString craftLineParserRegExpPattern() const
std::size_t m_spectrumCount
excetion to use when an item type is not recognized
Class to represent a mass spectrum.
MassSpectrumSPtr makeMassSpectrumSPtr() const
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
MsRunIdCstSPtr mcsp_msRunId
Class representing a fully specified mass spectrum.
uint getMsLevel() const
Get the mass spectrum level.
MassSpectrumCstSPtr getMassSpectrumCstSPtr() const
Get the MassSpectrumCstSPtr.
void setMassSpectrumId(const MassSpectrumId &iD)
Set the MassSpectrumId.
void setMsLevel(uint ms_level)
Set the mass spectrum level.
MassSpectrumSPtr getMassSpectrumSPtr() const
Get the MassSpectrumSPtr.
void setMassSpectrumSPtr(MassSpectrumSPtr massSpectrum)
Set the MassSpectrumSPtr.
void setRtInSeconds(pappso_double rt)
Set the retention time in seconds.
interface to collect spectrums from the MsRunReader class
virtual bool shouldStop()
virtual bool needPeakList() const =0
tells if we need the peak list (if we want the binary data) for each spectrum
virtual void loadingEnded()
virtual void setQualifiedMassSpectrum(const QualifiedMassSpectrum &spectrum)=0
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
excetion to use when an item type is not recognized (file format, object type...)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
std::pair< double, double > mz_range