13#include <pwiz/data/msdata/DefaultReaderList.hpp>
18#include "../exception/exceptionnotfound.h"
21#include "../msrun/msrunid.h"
52 if(!file.open(QFile::ReadOnly | QFile::Text))
54 qDebug() <<
"Failed to open file" <<
m_fileName;
63 QString regexp_pattern = QString(
"^(%1)").arg(
67 regexp_pattern += QString(
",([+-])");
69 regexp_pattern += QString(
",(ESI|MALDI)");
72 regexp_pattern += QString(
",ms(\\d)");
75 regexp_pattern += QString(
",(-)");
78 regexp_pattern += QString(
",(profile|line)");
89 regexp_pattern += QString(
",(\\d+)");
91 regexp_pattern += QString(
"(.*$)");
95 QRegularExpression line_regexp(regexp_pattern);
97 QRegularExpressionMatch regexp_match;
100 bool file_reading_failed =
false;
109 std::size_t iter = 0;
113 line = file.readLine().trimmed();
120 if(
line.startsWith(
'#') ||
line.isEmpty() ||
127 regexp_match = line_regexp.match(
line);
129 if(regexp_match.hasMatch())
133 regexp_match.captured(1).toDouble(&ok);
137 <<
"Failed to extract the retention time of the mass spectrum.";
139 file_reading_failed =
true;
144 QString ionization_mode = regexp_match.captured(2);
145 QString source_type = regexp_match.captured(3);
147 regexp_match.captured(4).toInt(&ok);
151 <<
"Failed to extract the MS level of the mass spectrum.";
153 file_reading_failed =
true;
158 QString peak_shape_type = regexp_match.captured(6);
160 QString mz_range = regexp_match.captured(7);
162 mz_range.left(mz_range.indexOf(
"-")).toDouble(&ok);
165 qDebug() <<
"Failed to extract the start of the m/z range.";
167 file_reading_failed =
true;
172 mz_range.right(mz_range.indexOf(
"-") + 1).toDouble(&ok);
175 qDebug() <<
"Failed to extract the end of the m/z range.";
177 file_reading_failed =
true;
186 int peak_count = regexp_match.captured(8).toInt(&ok);
189 qDebug() <<
"Failed to extract the number of peaks in the mass "
192 file_reading_failed =
true;
197 QString peaks = regexp_match.captured(9);
198 QStringList peaks_stringlist = peaks.split(
",", Qt::SkipEmptyParts);
203 if(peaks_stringlist.size() != peak_count)
209 file_reading_failed =
true;
233 qDebug() <<
"The match failed.";
234 file_reading_failed =
true;
244 if(!file_reading_failed && line_count >= 1)
269std::vector<MsRunIdCstSPtr>
272 std::vector<MsRunIdCstSPtr> ms_run_ids;
274 std::size_t ms_data_line_count = 0;
298 QString sample_name = file_info.fileName();
312 ms_run_ids.push_back(std::make_shared<MsRunId>(ms_run_id));
virtual ~BafAsciiFileReader()
virtual MsDataFormat getFileFormat() override
virtual bool initialize(std::size_t &line_count)
virtual std::vector< MsRunIdCstSPtr > getMsRunIds(const QString &run_prefix) override
BafAsciiFileReader(const QString &file_name)
MsDataFormat m_fileFormat
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
const QString & getRunId() const
void setRunId(const QString &run_id)
void setXmlId(const QString &xml_id)
set an XML unique identifier for this MsRunId
void setMsDataFormat(MsDataFormat format)
void setSampleName(const QString &name)
set a sample name for this MsRunId
static QRegularExpression unsignedDoubleNumberNoExponentialRegExp
static const QString getLexicalOrderedString(unsigned int num)
static QRegularExpression endOfLineRegExp
Regular expression that tracks the end of line in text files.
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
static const std::size_t CHECKED_LINES_COUNT