11#include <pwiz/data/msdata/DefaultReaderList.hpp>
45 "in BafAsciiMsRunReader, for MS run %2:\n")
63 QString regexp_pattern =
67 regexp_pattern += QString(
",([+-])");
70 regexp_pattern += QString(
",(ESI|MALDI)");
73 regexp_pattern += QString(
",ms(\\d)");
76 regexp_pattern += QString(
",(-)");
79 regexp_pattern += QString(
",(profile|line)");
82 regexp_pattern += QString(
",(%1-%2)")
87 regexp_pattern += QString(
",(\\d+)");
91 regexp_pattern += QString(
"(.*$)");
95 return regexp_pattern;
101 QRegularExpression regexp = QRegularExpression(pattern);
103 if(!regexp.isValid())
105 qDebug() <<
"The regular expression is not valid:" << regexp.errorString();
106 return QRegularExpression();
109 return QRegularExpression(pattern);
115 QRegularExpression &line_regexp)
const
126 QRegularExpressionMatch regexp_match = line_regexp.match(
line);
129 if(regexp_match.hasMatch())
133 double retention_time = regexp_match.captured(1).toDouble(&ok);
136 qDebug() <<
"Failed to extract the retention time of the mass spectrum.";
145 int ms_level = regexp_match.captured(4).toInt(&ok);
148 qDebug() <<
"Failed to extract the MS level of the mass spectrum.";
151 ms_line_data.
msLevel = ms_level;
153 QString dash = regexp_match.captured(5);
154 ms_line_data.
dash = dash;
158 QString mz_range = regexp_match.captured(7);
160 double mz_range_start = mz_range.left(mz_range.indexOf(
"-")).toDouble(&ok);
163 qDebug() <<
"Failed to extract the start of the m/z range.";
166 double mz_range_end = mz_range.right(mz_range.indexOf(
"-") + 1).toDouble(&ok);
169 qDebug() <<
"Failed to extract the end of the m/z range.";
172 ms_line_data.
mz_range = std::pair<double, double>(mz_range_start, mz_range_end);
178 std::size_t peak_count = regexp_match.captured(8).toULongLong(&ok);
181 qDebug() <<
"Failed to extract the number of peaks in the mass "
187 QString peaks = regexp_match.captured(9);
188 ms_line_data.
peakList = peaks.split(
",", Qt::SkipEmptyParts);
193 if(
static_cast<std::size_t
>(ms_line_data.
peakList.size()) != ms_line_data.
peakCount)
195 qDebug() <<
"The number of peaks in the mass spectrum does not "
196 "match the advertised one.";
212 qDebug() <<
"The match failed.";
236 if(!line_regexp.isValid())
238 qDebug() <<
"Failed to craft the regular expresssion";
243 QFile file(file_name);
245 if(!file.open(QFile::ReadOnly | QFile::Text))
247 qDebug() <<
"Failed to open file" << file_name;
256 QString
line = file.readLine().trimmed();
260 qDebug() <<
"Failed to parse a line.";
273 qDebug() <<
"The file seems indeed to be BafAscii.";
277 qDebug() <<
"The file does not seem to be BafAscii.";
298 bool want_binary_data)
const
307 QFile file(file_name);
309 if(!file.open(QFile::ReadOnly | QFile::Text))
312 "BafAsciiMsRunReader, for MS run %4:\n")
327 if(!line_regexp.isValid())
329 throw(
PappsoException(QString(
"%1-%2 Failed to craft the regular expresssion while reading "
330 "file %3 in BafAsciiMsRunReader, for MS run %4:")
339 std::size_t mass_spectrum_index = 0;
343 if(mass_spectrum_index < spectrum_index)
347 QString
line = file.readLine().trimmed();
353 throw(
PappsoException(QString(
"%1-%2 Failed to parse line while reading file %3 "
354 "in BafAsciiMsRunReader, for MS run %4:\n")
380 for(
int iter = 0; iter < ms_line_data.
peakList.size(); ++iter)
382 QString pair_string = ms_line_data.
peakList.at(iter);
386 QStringList mz_and_intensity_list = pair_string.split(
" ", Qt::SkipEmptyParts);
388 double mz = mz_and_intensity_list.first().toDouble(&ok);
393 throw(
PappsoException(QString(
"%1-%2 Failed to parse line while reading file %3 "
394 "in BafAsciiMsRunReader, for MS run %4:\n")
403 double intensity = mz_and_intensity_list.last().toDouble(&ok);
408 throw(
PappsoException(QString(
"%1-%2 Failed to parse line while reading file %3 "
409 "in BafAsciiMsRunReader, for MS run %4:\n")
421 mass_spectrum.emplace_back(mz, intensity);
440 return qualified_mass_spectrum;
455 return qualified_mass_spectrum;
468 unsigned int ms_level)
482 QFile file(file_name);
484 if(!file.open(QFile::ReadOnly | QFile::Text))
487 "BafAsciiMsRunReader, for MS run %4:\n")
502 if(!line_regexp.isValid())
505 QString(
"%1-%2 Failed to craft the regular expresssion while reading file %3 "
506 "in BafAsciiMsRunReader, for MS run %4:\n")
514 std::size_t mass_spectrum_index = 0;
524 qDebug() <<
"The operation was cancelled. Breaking the loop.";
528 QString
line = file.readLine().trimmed();
534 throw(
PappsoException(QString(
"%1-%2 Failed to parse line whilereading file %3 "
535 "in BafAsciiMsRunReader, for MS run %4:\n")
565 for(
int iter = 0; iter < ms_line_data.
peakList.size(); ++iter)
567 QString pair_string = ms_line_data.
peakList.at(iter);
571 QStringList mz_and_intensity_list = pair_string.split(
" ", Qt::SkipEmptyParts);
573 double mz = mz_and_intensity_list.first().toDouble(&ok);
578 throw(
PappsoException(QString(
"%1-%2 Failed to parse line while reading file %3 "
579 "in BafAsciiMsRunReader, for MS run %4:\n")
588 double intensity = mz_and_intensity_list.last().toDouble(&ok);
593 throw(
PappsoException(QString(
"%1-%2 Failed to parse line while reading file %3 "
594 "in BafAsciiMsRunReader, for MS run %4:\n")
606 mass_spectrum.emplace_back(mz, intensity);
625 if(ms_level == 0 || qualified_mass_spectrum.
getMsLevel() == ms_level)
632 ++mass_spectrum_index;
639 qDebug() <<
"Loading ended";
671 [[maybe_unused]])
const
674 QObject::tr(
"Not implemented %1 %2 %3").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
683 QObject::tr(
"Not implemented %1 %2 %3").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
691 QObject::tr(
"%1 %2 %3 not implemented").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__));
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 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...
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
MsRunIdCstSPtr mcsp_msRunId
MsRunReader(const MsRunIdCstSPtr &ms_run_id)
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
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
const PrecisionBase * PrecisionPtr
std::shared_ptr< MassSpectrum > MassSpectrumSPtr
std::shared_ptr< XicCoord > XicCoordSPtr
std::pair< double, double > mz_range