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";
File adapter for DTA files.
Definition: DTAFile.h:61
void store(const String &filename, const SpectrumType &spectrum) const
Stores a spectrum in a DTA file.
Definition: DTAFile.h:192
void load(const String &filename, SpectrumType &spectrum)
Loads a DTA file to a spectrum.
Definition: DTAFile.h:81
DTAFile()
Default constructor.
virtual ~DTAFile()
Destructor.
UInt default_ms_level_
Default MS level used when reading the file.
Definition: DTAFile.h:240
Exception base class.
Definition: Exception.h:91
File not found exception.
Definition: Exception.h:511
Parse Error exception.
Definition: Exception.h:624
Unable to create file exception.
Definition: Exception.h:638
static String basename(const String &file)
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
void setMSLevel(UInt ms_level)
Sets the MS level.
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:136
void setName(const String &name)
Sets the name.
void clear(bool clear_meta_data)
Clears all data and meta data.
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:113
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:110
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:119
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:149
DPosition< 1 > PositionType
Position type.
Definition: Peak1D.h:64
float IntensityType
Intensity type.
Definition: Peak1D.h:62
Precursor meta information.
Definition: Precursor.h:61
Int getCharge() const
Non-mutable access to the charge.
void setCharge(Int charge)
Mutable access to the charge.
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
A more convenient string class.
Definition: String.h:60
bool has(Byte byte) const
true if String contains the byte, false otherwise
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
int Int
Signed integer type.
Definition: Types.h:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
const double PROTON_MASS_U
Definition: Constants.h:116
static double toDouble(const String &this_s)
Definition: StringUtils.h:242
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
constexpr Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:219