159 spectrum.
clear(
true);
162 spectrum.
setType(SpectrumSettings::SpectrumType::CENTROID);
163 spectrum.
setNativeID(std::string(
"index=") + (spectrum_number));
169 while (getline(is, line,
'\n'))
173 StringUtils::trim(line);
176 if (line ==
"BEGIN IONS")
178 while (getline(is, line,
'\n'))
181 StringUtils::trim(line);
183 if (line.empty())
continue;
185 if (line ==
"END IONS")
192 if (isdigit(line[0]))
194 std::vector<std::string> split;
202 StringUtils::simplify(line);
203 StringUtils::substitute(line,
'\t',
' ');
204 if (StringUtils::split(line,
' ', split,
false))
213 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"The content '" + line +
"' at line #" + StringUtils::toStr(line_number) +
" could not be converted to a number! Expected two (m/z int) or three (m/z int charge) numbers separated by whitespace (space or tab).",
"");
215 spectrum.push_back(p);
219 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"The content '" + line +
"' at line #" + StringUtils::toStr(line_number) +
" does not contain m/z and intensity values separated by whitespace (space or tab)!",
"");
222 while (getline(is, line,
'\n') && ++line_number && StringUtils::trim(line) !=
"END IONS");
224 if (line ==
"END IONS")
230 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, R
"(Reached end of file. Found "BEGIN IONS" but not the corresponding "END IONS"!)", "");
233 else if (StringUtils::hasPrefix(line,
"PEPMASS"))
235 std::string tmp = StringUtils::substr(line, 8);
236 StringUtils::substitute(tmp,
'\t',
' ');
237 std::vector<std::string> split;
238 StringUtils::split(tmp,
' ', split);
239 if (split.size() == 1)
241 spectrum.
getPrecursors()[0].setMZ(StringUtils::toDouble(StringUtils::trim(split[0])));
243 else if (split.size() == 2)
245 spectrum.
getPrecursors()[0].setMZ(StringUtils::toDouble(StringUtils::trim(split[0])));
246 spectrum.
getPrecursors()[0].setIntensity(StringUtils::toDouble(StringUtils::trim(split[1])));
250 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Cannot parse PEPMASS in '" + line +
"' at line #" + StringUtils::toStr(line_number) +
" (expected 1 or 2 entries, but " + StringUtils::toStr(split.size()) +
" were present)!",
"");
253 else if (StringUtils::hasPrefix(line,
"CHARGE"))
255 std::string tmp = StringUtils::substr(line, 7);
256 StringUtils::remove(tmp,
'+');
257 spectrum.
getPrecursors()[0].setCharge(StringUtils::toInt32(tmp));
259 else if (StringUtils::hasPrefix(line,
"RTINSECONDS"))
261 std::string tmp = StringUtils::substr(line, 12);
262 spectrum.
setRT(StringUtils::toDouble(tmp));
264 else if (StringUtils::hasPrefix(line,
"TITLE"))
267 if (StringUtils::hasSubstring(line,
"min"))
271 std::vector<std::string> split;
272 StringUtils::split(line,
',', split);
275 for (
Size i = 0; i != split.size(); ++i)
277 if (StringUtils::hasSubstring(split[i],
"min"))
279 std::vector<std::string> split2;
280 StringUtils::trim(split[i]);
281 StringUtils::split(split[i],
' ', split2);
284 StringUtils::trim(split2[0]);
285 spectrum.
setRT(StringUtils::toDouble(split2[0]) * 60.0);
294 std::vector<std::string> split;
295 if (StringUtils::split(line,
'=', split))
297 if (!split[1].empty()) spectrum.
setMetaValue(
"TITLE", split[1]);
303 Size firstEqual = line.find(
'=', 4);
304 if (firstEqual != std::string::npos)
308 spectrum.
setMetaValue(
"TITLE", StringUtils::substr(line, firstEqual + 1));
317 else if (StringUtils::hasPrefix(line,
"NAME"))
319 std::string tmp = StringUtils::substr(line, 5);
320 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
322 else if (StringUtils::hasPrefix(line,
"COMPOUND_NAME"))
324 std::string tmp = StringUtils::substr(line, 14);
325 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
327 else if (StringUtils::hasPrefix(line,
"INCHI="))
329 std::string tmp = StringUtils::substr(line, 6);
330 spectrum.
setMetaValue(Constants::UserParam::MSM_INCHI_STRING, tmp);
332 else if (StringUtils::hasPrefix(line,
"SMILES"))
334 std::string tmp = StringUtils::substr(line, 7);
335 spectrum.
setMetaValue(Constants::UserParam::MSM_SMILES_STRING, tmp);
337 else if (StringUtils::hasPrefix(line,
"IONMODE"))
339 std::string tmp = StringUtils::substr(line, 8);
342 else if (StringUtils::hasPrefix(line,
"MSLEVEL"))
344 std::string tmp = StringUtils::substr(line, 8);
347 int ms_level = std::stoi(tmp);
350 catch (
const std::invalid_argument& )
356 catch (
const std::out_of_range& )
361 else if (StringUtils::hasPrefix(line,
"SOURCE_INSTRUMENT"))
363 std::string tmp = StringUtils::substr(line, 18);
366 else if (StringUtils::hasPrefix(line,
"ORGANISM"))
368 std::string tmp = StringUtils::substr(line, 9);
371 else if (StringUtils::hasPrefix(line,
"PI"))
373 std::string tmp = StringUtils::substr(line, 3);
376 else if (StringUtils::hasPrefix(line,
"DATACOLLECTOR"))
378 std::string tmp = StringUtils::substr(line, 14);
381 else if (StringUtils::hasPrefix(line,
"LIBRARYQUALITY"))
383 std::string tmp = StringUtils::substr(line, 15);
386 else if (StringUtils::hasPrefix(line,
"SPECTRUMID"))
388 std::string tmp = StringUtils::substr(line, 11);
391 else if (StringUtils::hasPrefix(line,
"SCANS="))
393 std::string tmp = StringUtils::substr(line, 6);
396 else if (StringUtils::hasPrefix(line,
"SEQ="))
403 std::string sequence = StringUtils::substr(line, 4);
409 sequences.push_back(sequence);