35 #ifndef OPENMS_FORMAT_DTAFILE_H
36 #define OPENMS_FORMAT_DTAFILE_H
81 template <
typename SpectrumType>
82 void load(
const String & filename, SpectrumType & spectrum)
84 std::ifstream is(filename.c_str());
95 std::vector<String> strings(2);
100 Size line_number = 1;
103 getline(is, line,
'\n');
116 line.
split(delimiter, strings);
117 if (strings.size() != 2)
119 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\" (got " +
String(strings.size()) +
", expected 2 entries)", filename);
127 mh_mass = strings[0].toDouble();
128 charge = strings[1].toInt();
132 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
140 precursor.
setMZ(mh_mass);
143 spectrum.getPrecursors().push_back(precursor);
144 spectrum.setMSLevel(default_ms_level_);
146 while (getline(is, line,
'\n'))
150 if (line.empty())
continue;
162 line.
split(delimiter, strings);
163 if (strings.size() != 2)
165 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\" (got " +
String(strings.size()) +
", expected 2 entries)", filename);
170 p.setPosition((
typename SpectrumType::PeakType::PositionType)strings[0].toDouble());
171 p.setIntensity((
typename SpectrumType::PeakType::IntensityType)strings[1].toDouble());
175 throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
177 spectrum.push_back(p);
192 template <
typename SpectrumType>
193 void store(
const String & filename,
const SpectrumType & spectrum)
const
195 std::ofstream os(filename.c_str());
204 if (spectrum.getPrecursors().size() > 0)
206 precursor = spectrum.getPrecursors()[0];
208 if (spectrum.getPrecursors().size() > 1)
210 std::cerr <<
"Warning: The spectrum written to the DTA file '" << filename <<
"' has more than one precursor. The first precursor is used!" <<
"\n";
215 os << precursor.
getMZ();
223 os <<
" " << precursor.
getCharge() <<
"\n";
227 typename SpectrumType::ConstIterator it(spectrum.begin());
228 for (; it != spectrum.end(); ++it)
231 os << it->getPosition() <<
" " << it->getIntensity() <<
"\n";
246 #endif // OPENMS_FORMAT_DTAFILE_H
A more convenient string class.
Definition: String.h:57
Precursor meta information.
Definition: Precursor.h:56
Size default_ms_level_
Default MS level used when reading the file.
Definition: DTAFile.h:241
Peak2D PeakType
Definition: MassTrace.h:48
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:114
File adapter for DTA files.
Definition: DTAFile.h:61
Int getCharge() const
Non-mutable access to the charge.
File not found exception.
Definition: Exception.h:524
bool has(Byte byte) const
true if String contains the byte, false otherwise
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:120
const double PROTON_MASS_U
void load(const String &filename, SpectrumType &spectrum)
Loads a DTA file to a spectrum.
Definition: DTAFile.h:82
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
Exception base class.
Definition: Exception.h:90
static String basename(const String &file)
Returns the basename of the file (without the path).
void store(const String &filename, const SpectrumType &spectrum) const
Stores a spectrum in a DTA file.
Definition: DTAFile.h:193
Unable to create file exception.
Definition: Exception.h:622
Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:213
void setCharge(Int charge)
Mutable access to the charge.
int Int
Signed integer type.
Definition: Types.h:96
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
Parse Error exception.
Definition: Exception.h:608