144 spectrum.
setNativeID(std::string(
"index=") + (spectrum_number));
159 while (getline(is, line,
'\n'))
163 StringUtils::trim(line);
166 if (line ==
"BEGIN IONS")
168 while (getline(is, line,
'\n'))
171 StringUtils::trim(line);
173 if (line.empty())
continue;
175 if (isdigit(line[0]))
177 std::vector<std::string> split;
185 StringUtils::simplify(line);
186 StringUtils::substitute(line,
'\t',
' ');
187 if (StringUtils::split(line,
' ', split,
false))
196 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).",
"");
198 spectrum.push_back(p);
202 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)!",
"");
205 while (getline(is, line,
'\n') && ++line_number && StringUtils::trim(line) !=
"END IONS");
207 if (line ==
"END IONS")
213 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, R
"(Reached end of file. Found "BEGIN IONS" but not the corresponding "END IONS"!)", "");
216 else if (StringUtils::hasPrefix(line,
"PEPMASS"))
218 std::string tmp = StringUtils::substr(line, 8);
219 StringUtils::substitute(tmp,
'\t',
' ');
220 std::vector<std::string> split;
221 StringUtils::split(tmp,
' ', split);
222 if (split.size() == 1)
224 spectrum.
getPrecursors()[0].setMZ(StringUtils::toDouble(StringUtils::trim(split[0])));
226 else if (split.size() == 2)
228 spectrum.
getPrecursors()[0].setMZ(StringUtils::toDouble(StringUtils::trim(split[0])));
229 spectrum.
getPrecursors()[0].setIntensity(StringUtils::toDouble(StringUtils::trim(split[1])));
233 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)!",
"");
236 else if (StringUtils::hasPrefix(line,
"CHARGE"))
238 std::string tmp = StringUtils::substr(line, 7);
239 StringUtils::remove(tmp,
'+');
240 spectrum.
getPrecursors()[0].setCharge(StringUtils::toInt32(tmp));
242 else if (StringUtils::hasPrefix(line,
"RTINSECONDS"))
244 std::string tmp = StringUtils::substr(line, 12);
245 spectrum.
setRT(StringUtils::toDouble(tmp));
247 else if (StringUtils::hasPrefix(line,
"TITLE"))
250 if (StringUtils::hasSubstring(line,
"min"))
254 std::vector<std::string> split;
255 StringUtils::split(line,
',', split);
258 for (
Size i = 0; i != split.size(); ++i)
260 if (StringUtils::hasSubstring(split[i],
"min"))
262 std::vector<std::string> split2;
263 StringUtils::trim(split[i]);
264 StringUtils::split(split[i],
' ', split2);
267 StringUtils::trim(split2[0]);
268 spectrum.
setRT(StringUtils::toDouble(split2[0]) * 60.0);
277 std::vector<std::string> split;
278 if (StringUtils::split(line,
'=', split))
280 if (!split[1].empty()) spectrum.
setMetaValue(
"TITLE", split[1]);
286 Size firstEqual = line.find(
'=', 4);
287 if (firstEqual != std::string::npos)
291 spectrum.
setMetaValue(
"TITLE", StringUtils::substr(line, firstEqual + 1));
300 else if (StringUtils::hasPrefix(line,
"NAME"))
302 std::string tmp = StringUtils::substr(line, 5);
303 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
305 else if (StringUtils::hasPrefix(line,
"COMPOUND_NAME"))
307 std::string tmp = StringUtils::substr(line, 14);
308 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
310 else if (StringUtils::hasPrefix(line,
"INCHI="))
312 std::string tmp = StringUtils::substr(line, 6);
313 spectrum.
setMetaValue(Constants::UserParam::MSM_INCHI_STRING, tmp);
315 else if (StringUtils::hasPrefix(line,
"SMILES"))
317 std::string tmp = StringUtils::substr(line, 7);
318 spectrum.
setMetaValue(Constants::UserParam::MSM_SMILES_STRING, tmp);
320 else if (StringUtils::hasPrefix(line,
"IONMODE"))
322 std::string tmp = StringUtils::substr(line, 8);
325 else if (StringUtils::hasPrefix(line,
"MSLEVEL"))
327 std::string tmp = StringUtils::substr(line, 8);
330 int ms_level = std::stoi(tmp);
333 catch (
const std::invalid_argument& )
339 catch (
const std::out_of_range& )
344 else if (StringUtils::hasPrefix(line,
"SOURCE_INSTRUMENT"))
346 std::string tmp = StringUtils::substr(line, 18);
349 else if (StringUtils::hasPrefix(line,
"ORGANISM"))
351 std::string tmp = StringUtils::substr(line, 9);
354 else if (StringUtils::hasPrefix(line,
"PI"))
356 std::string tmp = StringUtils::substr(line, 3);
359 else if (StringUtils::hasPrefix(line,
"DATACOLLECTOR"))
361 std::string tmp = StringUtils::substr(line, 14);
364 else if (StringUtils::hasPrefix(line,
"LIBRARYQUALITY"))
366 std::string tmp = StringUtils::substr(line, 15);
369 else if (StringUtils::hasPrefix(line,
"SPECTRUMID"))
371 std::string tmp = StringUtils::substr(line, 11);
374 else if (StringUtils::hasPrefix(line,
"SCANS="))
376 std::string tmp = StringUtils::substr(line, 6);
379 else if (StringUtils::hasPrefix(line,
"SEQ="))
386 std::string sequence = StringUtils::substr(line, 4);
392 sequences.push_back(sequence);