54 template <
typename SpectrumType>
57 std::ifstream is(filename.c_str());
60 if (!File::exists(filename))
64 else if (!File::readable(filename))
79 std::vector<String> strings(2);
87 getline(is, line,
'\n');
100 line.
split(delimiter, strings);
101 if (strings.size() != 2)
103 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);
111 mh_mass = strings[0].toDouble();
112 charge = strings[1].toInt();
116 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
120 precursor.
setMZ((mh_mass - Constants::PROTON_MASS_U) / charge + Constants::PROTON_MASS_U);
124 precursor.
setMZ(mh_mass);
130 while (getline(is, line,
'\n'))
134 if (line.empty())
continue;
146 line.
split(delimiter, strings);
147 if (strings.size() != 2)
149 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);
154 p.
setPosition((
typename SpectrumType::PeakType::PositionType)strings[0].toDouble());
155 p.
setIntensity((
typename SpectrumType::PeakType::IntensityType)strings[1].toDouble());
159 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, std::string(
"Bad data line (" +
String(line_number) +
"): \"") + line +
"\": not a float number.", filename);
161 spectrum.push_back(p);
164 spectrum.
setName(File::basename(filename));
176 template <
typename SpectrumType>
179 std::ofstream os(filename.c_str());
184 os.precision(writtenDigits<double>(0.0));
194 std::cerr <<
"Warning: The spectrum written to the DTA file '" << filename <<
"' has more than one precursor. The first precursor is used!" <<
"\n";
199 os << precursor.
getMZ();
207 os <<
" " << precursor.
getCharge() <<
"\n";
212 for (; it != spectrum.end(); ++it)
215 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:177
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:225
Exception base class.
Definition Exception.h:63
File not found exception.
Definition Exception.h:475
File not readable exception.
Definition Exception.h:501
General IOException.
Definition Exception.h:541
Parse Error exception.
Definition Exception.h:593
Unable to create file exception.
Definition Exception.h:606
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:120
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:30
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition Peak1D.h:89
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition Peak1D.h:86
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition Peak1D.h:95
void setPosition(PositionType const &position)
Mutable access to the position.
Definition Peak1D.h:125
Precursor meta information.
Definition Precursor.h:37
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
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19