35 #ifndef OPENMS_FORMAT_MASCOTGENERICFILE_H
36 #define OPENMS_FORMAT_MASCOTGENERICFILE_H
77 virtual void updateMembers_();
81 bool compact =
false);
84 void store(std::ostream& os,
const String& filename,
85 const PeakMap& experiment,
bool compact =
false);
94 template <
typename MapType>
104 std::ifstream is(filename.c_str());
106 is.seekg(0, std::ios::end);
107 startProgress(0, is.tellg(),
"loading MGF");
108 is.seekg(0, std::ios::beg);
110 UInt spectrum_number(0);
116 while (getNextSpectrum_(is, spectrum, line_number, spectrum_number))
119 setProgress(is.tellg());
134 std::pair<String, String> getHTTPPeakListEnclosure(
const String& filename)
const;
145 void writeParameterHeader_(
const String& name, std::ostream& os);
148 void writeModifications_(
const std::vector<String>& mods, std::ostream& os,
149 bool variable_mods =
false);
152 void writeHeader_(std::ostream& os);
155 void writeSpectrum_(std::ostream& os,
const PeakSpectrum& spec,
const String& filename);
158 void writeMSExperiment_(std::ostream& os,
const String& filename,
const PeakMap& experiment);
161 template <
typename SpectrumType>
166 spectrum.setNativeID(
String(
"index=") + (spectrum_number));
167 if (spectrum.metaValueExists(
"TITLE"))
169 spectrum.removeMetaValue(
"TITLE");
175 while (getline(is, line,
'\n'))
182 if (line ==
"BEGIN IONS")
184 while (getline(is, line,
'\n'))
189 if (line.empty())
continue;
191 if (isdigit(line[0]))
193 std::vector<String> split;
202 line.
split(
' ', split);
203 if (split.size() >= 2)
205 p.setPosition(split[0].toDouble());
206 p.setIntensity(split[1].toDouble());
207 spectrum.push_back(p);
211 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"the line (" + line +
") should contain m/z and intensity value separated by whitespace!",
"");
214 while (getline(is, line,
'\n') && ++line_number && line.
trim() !=
"END IONS");
216 if (line ==
"END IONS")
222 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"Reached end of file. Found \"BEGIN IONS\" but not the corresponding \"END IONS\"!",
"");
229 std::vector<String> split;
230 tmp.
split(
' ', split);
231 if (split.size() == 1)
233 spectrum.getPrecursors()[0].setMZ(split[0].trim().toDouble());
235 else if (split.size() == 2)
237 spectrum.getPrecursors()[0].setMZ(split[0].trim().toDouble());
238 spectrum.getPrecursors()[0].setIntensity(split[1].trim().toDouble());
242 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"Cannot parse PEPMASS: '" + line +
"' in line " +
String(line_number) +
" (expected 1 or 2 entries, but " +
String(split.size()) +
" were present!",
"");
249 spectrum.getPrecursors()[0].setCharge(tmp.
toInt());
263 std::vector<String> split;
264 line.
split(
',', split);
267 for (
Size i = 0; i != split.size(); ++i)
269 if (split[i].hasSubstring(
"min"))
271 std::vector<String> split2;
272 split[i].trim().split(
' ', split2);
275 spectrum.setRT(split2[0].trim().toDouble() * 60.0);
284 std::vector<String> split;
285 line.
split(
'=', split);
286 if (split.size() >= 2)
288 if (split[1] !=
"") spectrum.setMetaValue(
"TITLE", split[1]);
294 std::vector<String> split;
295 line.
split(
'=', split);
296 if (split.size() == 2)
298 if (split[1] !=
"") spectrum.setMetaValue(
"TITLE", split[1]);
314 #endif // OPENMS_FORMAT_MASCOTGENERICFILE_H
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:162
A more convenient string class.
Definition: String.h:57
void reset()
Resets all internal values.
Definition: MSExperiment.h:660
Peak2D PeakType
Definition: MassTrace.h:49
File not found exception.
Definition: Exception.h:524
Mascot input file adapter.
Definition: MascotGenericFile.h:64
String & remove(char what)
Remove all occurrences of the character what.
double toDouble() const
Conversion to double.
std::map< String, String > mod_group_map_
mapping of modifications with specificity groups, that have to be treated specially (e...
Definition: MascotGenericFile.h:142
Int toInt() const
Conversion to int.
static bool exists(const String &file)
Method used to test if a file exists.
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
void setMSLevel(UInt ms_level)
Sets the MS level.
Definition: MSSpectrum.h:265
Exception base class.
Definition: Exception.h:90
void addSpectrum(const MSSpectrum< PeakT > &spectrum)
adds a spectra to the list
Definition: MSExperiment.h:758
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
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...
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
void load(const String &filename, MapType &exp)
loads a Mascot Generic File into a PeakMap
Definition: MascotGenericFile.h:95
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:139
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
Parse Error exception.
Definition: Exception.h:608