35 #ifndef OPENMS_FORMAT_DTAFILE_H 36 #define OPENMS_FORMAT_DTAFILE_H 81 template <
typename SpectrumType>
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__, OPENMS_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__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
140 precursor.
setMZ(mh_mass);
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__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\" (got " +
String(strings.size()) +
", expected 2 entries)", filename);
175 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_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>
195 std::ofstream os(filename.c_str());
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";
228 for (; it != spectrum.end(); ++it)
231 os << it->getPosition() <<
" " << it->getIntensity() <<
"\n";
246 #endif // OPENMS_FORMAT_DTAFILE_H 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:58
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:114
UInt default_ms_level_
Default MS level used when reading the file.
Definition: DTAFile.h:241
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
File adapter for DTA files.
Definition: DTAFile.h:61
void setName(const String &name)
Sets the name.
File not found exception.
Definition: Exception.h:524
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:120
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:111
const double PROTON_MASS_U
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
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...
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
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:128
Unable to create file exception.
Definition: Exception.h:637
float IntensityType
Intensity type.
Definition: Peak1D.h:64
void store(const String &filename, const SpectrumType &spectrum) const
Stores a spectrum in a DTA file.
Definition: DTAFile.h:193
Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:220
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:103
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:623