80 template <
typename SpectrumType>
83 std::ifstream is(filename.c_str());
94 std::vector<String> strings(2);
102 getline(is, line,
'\n');
115 line.
split(delimiter, strings);
116 if (strings.size() != 2)
118 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\" (got " +
String(strings.size()) +
", expected 2 entries)", filename);
126 mh_mass = strings[0].toDouble();
127 charge = strings[1].toInt();
131 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
139 precursor.
setMZ(mh_mass);
145 while (getline(is, line,
'\n'))
149 if (line.empty())
continue;
161 line.
split(delimiter, strings);
162 if (strings.size() != 2)
164 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\" (got " +
String(strings.size()) +
", expected 2 entries)", filename);
174 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
176 spectrum.push_back(p);
191 template <
typename SpectrumType>
194 std::ofstream os(filename.c_str());
209 std::cerr <<
"Warning: The spectrum written to the DTA file '" << filename <<
"' has more than one precursor. The first precursor is used!" <<
"\n";
214 os << precursor.
getMZ();
222 os <<
" " << precursor.
getCharge() <<
"\n";
227 for (; it != spectrum.end(); ++it)
230 os << it->getPosition() <<
" " << it->getIntensity() <<
"\n";
bool has(Byte byte) const
true if String contains the byte, false otherwise
A more convenient string class.
Definition: String.h:57
Precursor meta information.
Definition: Precursor.h:57
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:113
UInt default_ms_level_
Default MS level used when reading the file.
Definition: DTAFile.h:240
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:103
File adapter for DTA files.
Definition: DTAFile.h:60
void setName(const String &name)
Sets the name.
File not found exception.
Definition: Exception.h:523
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:119
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
const double PROTON_MASS_U
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
void load(const String &filename, SpectrumType &spectrum)
Loads a DTA file to a spectrum.
Definition: DTAFile.h:81
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:149
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
void setMSLevel(UInt ms_level)
Sets the MS level.
Exception base class.
Definition: Exception.h:89
void clear(bool clear_meta_data)
Clears all data and meta data.
static String basename(const String &file)
Returns the basename of the file (without the path).
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Unable to create file exception.
Definition: Exception.h:636
float IntensityType
Intensity type.
Definition: Peak1D.h:63
void store(const String &filename, const SpectrumType &spectrum) const
Stores a spectrum in a DTA file.
Definition: DTAFile.h:192
Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:219
void setCharge(Int charge)
Mutable access to the charge.
Int getCharge() const
Non-mutable access to the charge.
int Int
Signed integer type.
Definition: Types.h:102
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:622