54 template <
typename SpectrumType>
57 std::ifstream is(filename.c_str());
68 std::vector<String> strings(2);
76 getline(is, line,
'\n');
89 line.
split(delimiter, strings);
90 if (strings.size() != 2)
92 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);
100 mh_mass = strings[0].toDouble();
101 charge = strings[1].toInt();
105 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
113 precursor.
setMZ(mh_mass);
119 while (getline(is, line,
'\n'))
123 if (line.empty())
continue;
135 line.
split(delimiter, strings);
136 if (strings.size() != 2)
138 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);
148 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
150 spectrum.push_back(p);
165 template <
typename SpectrumType>
168 std::ofstream os(filename.c_str());
183 std::cerr <<
"Warning: The spectrum written to the DTA file '" << filename <<
"' has more than one precursor. The first precursor is used!" <<
"\n";
188 os << precursor.
getMZ();
196 os <<
" " << precursor.
getCharge() <<
"\n";
201 for (; it != spectrum.end(); ++it)
204 os << it->getPosition() <<
" " << it->getIntensity() <<
"\n";
File adapter for DTA files.
Definition: DTAFile.h:35
void store(const String &filename, const SpectrumType &spectrum) const
Stores a spectrum in a DTA file.
Definition: DTAFile.h:166
void load(const String &filename, SpectrumType &spectrum)
Loads a DTA file to a spectrum.
Definition: DTAFile.h:55
DTAFile()
Default constructor.
virtual ~DTAFile()
Destructor.
UInt default_ms_level_
Default MS level used when reading the file.
Definition: DTAFile.h:214
Exception base class.
Definition: Exception.h:63
File not found exception.
Definition: Exception.h:474
Parse Error exception.
Definition: Exception.h:592
Unable to create file exception.
Definition: Exception.h:605
static String basename(const String &file)
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void setMSLevel(UInt ms_level)
Sets the MS level.
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:110
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:28
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:87
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:84
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:93
void setPosition(PositionType const &position)
Mutable access to the position.
Definition: Peak1D.h:123
DPosition< 1 > PositionType
Position type.
Definition: Peak1D.h:38
float IntensityType
Intensity type.
Definition: Peak1D.h:36
Precursor meta information.
Definition: Precursor.h:35
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:34
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:72
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
const double PROTON_MASS_U
Definition: Constants.h:90
static double toDouble(const String &this_s)
Definition: StringUtils.h:216
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
constexpr Int writtenDigits< double >(const double &)
Number of digits commonly used for writing a double (a.k.a. precision).
Definition: Types.h:189