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 double retention_time = 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 int ms_level = 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 double mz_range_start =
163 mz_range.left(mz_range.indexOf(
"-")).toDouble(&ok);
166 qDebug() <<
"Failed to extract the start of the m/z range.";
168 file_reading_failed =
true;
173 double mz_range_end =
174 mz_range.right(mz_range.indexOf(
"-") + 1).toDouble(&ok);
177 qDebug() <<
"Failed to extract the end of the m/z range.";
179 file_reading_failed =
true;
188 int peak_count = regexp_match.captured(8).toInt(&ok);
191 qDebug() <<
"Failed to extract the number of peaks in the mass "
194 file_reading_failed =
true;
199 QString peaks = regexp_match.captured(9);
200 QStringList peaks_stringlist = peaks.split(
",", Qt::SkipEmptyParts);
205 if(peaks_stringlist.size() != peak_count)
211 file_reading_failed =
true;
235 qDebug() <<
"The match failed.";
236 file_reading_failed =
true;
246 if(!file_reading_failed && line_count >= 1)