54 bool compact =
false);
58 const PeakMap& experiment,
bool compact =
false);
67 template <
typename MapType>
70 if (!File::exists(filename))
77 std::ifstream is(filename.c_str());
79 is.seekg(0, std::ios::end);
80 startProgress(0, is.tellg(),
"loading MGF");
81 is.seekg(0, std::ios::beg);
83 UInt spectrum_number(0);
89 spectrum.
setType(SpectrumSettings::SpectrumType::CENTROID);
90 while (getNextSpectrum_(is, spectrum, line_number, spectrum_number))
93 setProgress(is.tellg());
125 bool variable_mods =
false);
134 template <
typename SpectrumType>
148 while (getline(is, line,
'\n'))
155 if (line ==
"BEGIN IONS")
157 while (getline(is, line,
'\n'))
162 if (line.empty())
continue;
164 if (isdigit(line[0]))
166 std::vector<String> split;
176 if (line.
split(
' ', split,
false))
185 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"The content '" + line +
"' at line #" +
String(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).",
"");
187 spectrum.push_back(p);
191 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"The content '" + line +
"' at line #" +
String(line_number) +
" does not contain m/z and intensity values separated by whitespace (space or tab)!",
"");
194 while (getline(is, line,
'\n') && ++line_number && line.
trim() !=
"END IONS");
196 if (line ==
"END IONS")
202 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, R
"(Reached end of file. Found "BEGIN IONS" but not the corresponding "END IONS"!)", "");
209 std::vector<String> split;
210 tmp.
split(
' ', split);
211 if (split.size() == 1)
213 spectrum.
getPrecursors()[0].setMZ(split[0].trim().toDouble());
215 else if (split.size() == 2)
217 spectrum.
getPrecursors()[0].setMZ(split[0].trim().toDouble());
218 spectrum.
getPrecursors()[0].setIntensity(split[1].trim().toDouble());
222 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Cannot parse PEPMASS in '" + line +
"' at line #" +
String(line_number) +
" (expected 1 or 2 entries, but " +
String(split.size()) +
" were present)!",
"");
243 std::vector<String> split;
244 line.
split(
',', split);
247 for (
Size i = 0; i != split.size(); ++i)
249 if (split[i].hasSubstring(
"min"))
251 std::vector<String> split2;
252 split[i].trim().split(
' ', split2);
255 spectrum.
setRT(split2[0].trim().toDouble() * 60.0);
264 std::vector<String> split;
265 if (line.
split(
'=', split))
267 if (!split[1].empty()) spectrum.
setMetaValue(
"TITLE", split[1]);
273 Size firstEqual = line.find(
'=', 4);
274 if (firstEqual != std::string::npos)
290 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
292 else if (line.
hasPrefix(
"COMPOUND_NAME"))
295 spectrum.
setMetaValue(Constants::UserParam::MSM_METABOLITE_NAME, tmp);
300 spectrum.
setMetaValue(Constants::UserParam::MSM_INCHI_STRING, tmp);
305 spectrum.
setMetaValue(Constants::UserParam::MSM_SMILES_STRING, tmp);
317 int ms_level = std::stoi(tmp);
320 catch (
const std::invalid_argument& )
326 catch (
const std::out_of_range& )
331 else if (line.
hasPrefix(
"SOURCE_INSTRUMENT"))
346 else if (line.
hasPrefix(
"DATACOLLECTOR"))
351 else if (line.
hasPrefix(
"LIBRARYQUALITY"))
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
Exception base class.
Definition Exception.h:63
Invalid conversion exception.
Definition Exception.h:331
File not found exception.
Definition Exception.h:475
Parse Error exception.
Definition Exception.h:593
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
void reset()
Clear all internal data (spectra, ranges, metadata)
void updateRanges()
Updates the m/z, intensity, mobility, and retention time ranges of all spectra and chromatograms.
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
void setMSLevel(UInt ms_level)
Sets the MS level.
void setRT(double rt)
Sets the absolute retention time (in seconds)
Read/write Mascot generic files (MGF).
Definition MascotGenericFile.h:40
bool store_compact_
use a compact format for storing (no zero-intensity peaks, limited number of decimal places)?
Definition MascotGenericFile.h:115
void store(const String &filename, const PeakMap &experiment, bool compact=false)
stores the experiment data in a MascotGenericFile that can be used as input for MASCOT shell executio...
void writeHeader_(std::ostream &os)
writes the full header
void writeModifications_(const std::vector< String > &mods, std::ostream &os, bool variable_mods=false)
write a list of (fixed or variable) modifications
void writeParameterHeader_(const String &name, std::ostream &os)
writes a parameter header
void writeMSExperiment_(std::ostream &os, const String &filename, const PeakMap &experiment)
writes the MSExperiment
void load(const String &filename, MapType &exp)
loads a Mascot Generic File into a PeakMap
Definition MascotGenericFile.h:68
std::pair< String, String > getHTTPPeakListEnclosure(const String &filename) const
enclosing Strings of the peak list body for HTTP submission
~MascotGenericFile() override
destructor
void writeSpectrum(std::ostream &os, const PeakSpectrum &spec, const String &filename, const String &native_id_type_accession)
writes a spectrum in MGF format to an ostream
bool getNextSpectrum_(std::ifstream &is, SpectrumType &spectrum, Size &line_number, const Size &spectrum_number)
reads a spectrum block, the section between 'BEGIN IONS' and 'END IONS' of a MGF file
Definition MascotGenericFile.h:135
void store(std::ostream &os, const String &filename, const PeakMap &experiment, bool compact=false)
store the experiment data in a MascotGenericFile; the output is written to the given stream,...
void updateMembers_() override
docu in base class
MascotGenericFile()
constructor
std::map< String, String > mod_group_map_
mapping of modifications with specificity groups, that have to be treated specially (e....
Definition MascotGenericFile.h:118
A 1-dimensional raw data point or peak.
Definition Peak1D.h:30
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition Peak1D.h:86
void setPosition(PositionType const &position)
Mutable access to the position.
Definition Peak1D.h:125
Base class for all classes that want to report their progress.
Definition ProgressLogger.h:27
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software.
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
void setType(SpectrumType type)
sets the spectrum type
void setNativeID(const String &native_id)
sets the native identifier for the spectrum, used by the acquisition software.
A more convenient string class.
Definition String.h:34
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
Int toInt() const
Conversion to Int.
double toDouble() const
Conversion to double.
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
String & remove(char what)
Remove all occurrences of the character what.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
String & simplify()
merges subsequent whitespaces to one blank character
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19