35 #ifndef OPENMS_FORMAT_DTA2DFILE_H 
   36 #define OPENMS_FORMAT_DTA2DFILE_H 
   94     template <
typename MapType>
 
   97       startProgress(0, 0, 
"loading DTA2D file");
 
  100       std::ifstream is(filename.c_str());
 
  109       map.setLoadedFileType(filename);
 
  110       map.setLoadedFilePath(filename);
 
  113       std::vector<String> strings(3);
 
  114       typename MapType::SpectrumType spec;
 
  126       bool time_in_minutes = 
false;
 
  135       Size line_number = 0;
 
  137       while (getline(is, line, 
'\n'))
 
  142         if (line.empty()) 
continue;
 
  158           line.
split(delimiter, strings);
 
  163           bool int_set = 
false;
 
  166           for (
Size i = 0; i < 3; ++i)
 
  168             if (strings[i] == 
"RT" || strings[i] == 
"RETENTION_TIME" || strings[i] == 
"MASS-TO-CHARGE" || strings[i] == 
"IT" || strings[i] == 
"INTENSITY")
 
  170               std::cerr << 
"Warning: This file contains the deprecated keyword '" << strings[i] << 
"'." << 
"\n";
 
  171               std::cerr << 
"         Please use only the new keywords SEC/MIN, MZ, INT." << 
"\n";
 
  173             if ((strings[i] == 
"SEC" || strings[i] == 
"RT" || strings[i] == 
"RETENTION_TIME") && rt_set == 
false)
 
  178             else if ((strings[i] == 
"MIN") && rt_set == 
false)
 
  182               time_in_minutes = 
true;
 
  184             else if ((strings[i] == 
"MZ" || strings[i] == 
"MASS-TO-CHARGE") && mz_set == 
false)
 
  189             else if ((strings[i] == 
"INT" || strings[i] == 
"IT" || strings[i] == 
"INTENSITY") && int_set == 
false)
 
  196               throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, 
"Misformatted header line!", filename);
 
  204           line.
split(delimiter, strings);
 
  205           if (strings.size() != 3)
 
  207             throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" + 
String(line_number) + 
"): \"") + line + 
"\" (got  " + 
String(strings.size()) + 
", expected 3 entries)", filename);
 
  209           p.setIntensity(strings[int_dim].toFloat());
 
  210           p.setMZ(strings[mz_dim].toDouble());
 
  211           rt = (strings[rt_dim].toDouble()) * (time_in_minutes ? 60.0 : 1.0);
 
  216           throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, std::string(
"Bad data line (" + 
String(line_number) + 
"): \"") + line + 
"\"", filename);
 
  220         if (fabs(rt - spec.getRT()) > 0.0001)
 
  224               (!options_.hasRTRange() || options_.getRTRange().encloses(
DPosition<1>(spec.getRT()))))                
 
  226             map.addSpectrum(spec);
 
  231           spec.setNativeID(
String(
"index=") + native_id);
 
  237           (!options_.hasMZRange() || options_.getMZRange().encloses(
DPosition<1>(p.getMZ())))
 
  239           (!options_.hasIntensityRange() || options_.getIntensityRange().encloses(
DPosition<1>(p.getIntensity())))
 
  250         (!options_.hasRTRange() || options_.getRTRange().encloses(
DPosition<1>(spec.getRT())))             
 
  253         map.addSpectrum(spec);
 
  267     template <
typename MapType>
 
  270       startProgress(0, map.size(), 
"storing DTA2D file");
 
  272       std::ofstream os(filename.c_str());
 
  279       os << 
"#SEC\tMZ\tINT\n";
 
  284       for (
typename MapType::const_iterator spec = map.begin(); spec != map.end(); ++spec)
 
  286         setProgress(count++);
 
  287         for (
typename MapType::SpectrumType::ConstIterator it = spec->begin(); it != spec->end(); ++it)
 
  305     template <
typename MapType>
 
  308       startProgress(0, map.size(), 
"storing DTA2D file");
 
  310       std::ofstream os(filename.c_str());
 
  317       os << 
"#SEC\tMZ\tINT\n";
 
  319       typename MapType::ChromatogramType TIC = map.getTIC();
 
  320       for (
typename MapType::ChromatogramType::ConstIterator it = TIC.begin(); it != TIC.end(); ++it)
 
  334 #endif // OPENMS_FORMAT_DTA2DFILE_H 
DTA2D File adapter. 
Definition: DTA2DFile.h:64
A more convenient string class. 
Definition: String.h:56
Peak2D PeakType
Definition: MassTrace.h:49
PeakFileOptions options_
Definition: DTA2DFile.h:68
File not found exception. 
Definition: Exception.h:524
bool has(Byte byte) const 
true if String contains the byte, false otherwise 
void storeTIC(const String &filename, const MapType &map) const 
Stores the TIC of a map in a DTA2D file. 
Definition: DTA2DFile.h:306
const PrecisionWrapper< FloatingPointType > precisionWrapper(const FloatingPointType rhs)
Wrapper function that sets the appropriate precision for output temporarily. The original precision i...
Definition: Types.h:358
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
void store(const String &filename, const MapType &map) const 
Stores a map in a DTA2D file. 
Definition: DTA2DFile.h:268
Exception base class. 
Definition: Exception.h:90
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
Base class for all classes that want to report their progess. 
Definition: ProgressLogger.h:56
Unable to create file exception. 
Definition: Exception.h:622
String substr(size_t pos=0, size_t n=npos) const 
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
Options for loading files containing peak data. 
Definition: PeakFileOptions.h:47
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const 
Splits a string into substrings using splitter as delimiter. 
void load(const String &filename, MapType &map)
Loads a map from a DTA2D file. 
Definition: DTA2DFile.h:95
bool hasPrefix(const String &string) const 
true if String begins with string, false otherwise 
Parse Error exception. 
Definition: Exception.h:608