35 #ifndef OPENMS_FORMAT_MASCOTGENERICFILE_H 36 #define OPENMS_FORMAT_MASCOTGENERICFILE_H 75 virtual void updateMembers_();
79 bool compact =
false);
82 void store(std::ostream& os,
const String& filename,
83 const PeakMap& experiment,
bool compact =
false);
92 template <
typename MapType>
102 std::ifstream is(filename.c_str());
104 is.seekg(0, std::ios::end);
105 startProgress(0, is.tellg(),
"loading MGF");
106 is.seekg(0, std::ios::beg);
108 UInt spectrum_number(0);
114 while (getNextSpectrum_(is, spectrum, line_number, spectrum_number))
117 setProgress(is.tellg());
132 std::pair<String, String> getHTTPPeakListEnclosure(
const String& filename)
const;
143 void writeParameterHeader_(
const String& name, std::ostream& os);
146 void writeModifications_(
const std::vector<String>& mods, std::ostream& os,
147 bool variable_mods =
false);
150 void writeHeader_(std::ostream& os);
153 void writeSpectrum_(std::ostream& os,
const PeakSpectrum& spec,
const String& filename);
156 void writeMSExperiment_(std::ostream& os,
const String& filename,
const PeakMap& experiment);
159 template <
typename SpectrumType>
173 while (getline(is, line,
'\n'))
180 if (line ==
"BEGIN IONS")
182 while (getline(is, line,
'\n'))
187 if (line.empty())
continue;
189 if (isdigit(line[0]))
191 std::vector<String> split;
201 if (line.
split(
' ', split,
false))
210 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).",
"");
212 spectrum.push_back(p);
216 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)!",
"");
219 while (getline(is, line,
'\n') && ++line_number && line.
trim() !=
"END IONS");
221 if (line ==
"END IONS")
227 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"Reached end of file. Found \"BEGIN IONS\" but not the corresponding \"END IONS\"!",
"");
234 std::vector<String> split;
235 tmp.
split(
' ', split);
236 if (split.size() == 1)
238 spectrum.
getPrecursors()[0].setMZ(split[0].trim().toDouble());
240 else if (split.size() == 2)
242 spectrum.
getPrecursors()[0].setMZ(split[0].trim().toDouble());
243 spectrum.
getPrecursors()[0].setIntensity(split[1].trim().toDouble());
247 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)!",
"");
268 std::vector<String> split;
269 line.
split(
',', split);
272 for (
Size i = 0; i != split.size(); ++i)
274 if (split[i].hasSubstring(
"min"))
276 std::vector<String> split2;
277 split[i].trim().split(
' ', split2);
280 spectrum.
setRT(split2[0].trim().toDouble() * 60.0);
289 std::vector<String> split;
290 if (line.
split(
'=', split))
292 if (split[1] !=
"") spectrum.
setMetaValue(
"TITLE", split[1]);
298 std::vector<String> split;
299 line.
split(
'=', split);
300 if (split.size() == 2)
302 if (split[1] !=
"") spectrum.
setMetaValue(
"TITLE", split[1]);
318 #endif // OPENMS_FORMAT_MASCOTGENERICFILE_H String & simplify()
merges subsequent whitespaces to one blank character
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:160
A more convenient string class.
Definition: String.h:57
void reset()
Resets all internal values.
Definition: MSExperiment.h:709
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
Definition: MSExperiment.h:831
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
File not found exception.
Definition: Exception.h:524
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:111
Read/write Mascot generic files (MGF).
Definition: MascotGenericFile.h:62
String & remove(char what)
Remove all occurrences of the character what.
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...
std::map< String, String > mod_group_map_
mapping of modifications with specificity groups, that have to be treated specially (e...
Definition: MascotGenericFile.h:140
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
static bool exists(const String &file)
Method used to test if a file exists.
Int toInt() const
Conversion to int.
double toDouble() const
Conversion to double.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:150
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
void setMSLevel(UInt ms_level)
Sets the MS level.
Exception base class.
Definition: Exception.h:90
Invalid conversion exception.
Definition: Exception.h:363
void setRT(double rt)
Sets the absolute retention time (in seconds)
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
void setNativeID(const String &native_id)
sets the native identifier for the spectrum, used by the acquisition software.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
void load(const String &filename, MapType &exp)
loads a Mascot Generic File into a PeakMap
Definition: MascotGenericFile.h:93
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
bool store_compact_
use a compact format for storing (no zero-intensity peaks, limited number of decimal places)...
Definition: MascotGenericFile.h:137
Parse Error exception.
Definition: Exception.h:623