Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_FORMAT_MASCOTINFILE_H
00036 #define OPENMS_FORMAT_MASCOTINFILE_H
00037
00038 #include <OpenMS/KERNEL/MSExperiment.h>
00039 #include <OpenMS/DATASTRUCTURES/String.h>
00040 #include <OpenMS/SYSTEM/File.h>
00041 #include <OpenMS/CONCEPT/ProgressLogger.h>
00042 #include <OpenMS/KERNEL/StandardTypes.h>
00043
00044 #include <vector>
00045 #include <fstream>
00046
00047 namespace OpenMS
00048 {
00059 class OPENMS_DLLAPI MascotInfile :
00060 public ProgressLogger
00061 {
00062 public:
00063
00065 MascotInfile();
00066
00068 virtual ~MascotInfile();
00069
00071 void store(const String & filename, const PeakSpectrum & spec, DoubleReal mz, DoubleReal retention_time, String search_title);
00072
00074 void store(const String & filename, const MSExperiment<> & experiment, String search_title);
00075
00082 template <typename MapType>
00083 void load(const String & filename, MapType & exp)
00084 {
00085 exp.reset();
00086 if (!File::exists(filename))
00087 {
00088 throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
00089 }
00090
00091 std::ifstream is(filename.c_str());
00092 std::vector<std::pair<double, double> > spec;
00093 UInt charge(0);
00094 double pre_mz(0), pre_int(0), rt(-1);
00095 String title;
00096 while (getNextSpectrum_(is, spec, charge, pre_mz, pre_int, rt, title))
00097 {
00098 typename MapType::SpectrumType spectrum;
00099 for (std::vector<std::pair<double, double> >::const_iterator it = spec.begin(); it != spec.end(); ++it)
00100 {
00101 typename MapType::PeakType p;
00102 p.setPosition(it->first);
00103 p.setIntensity(it->second);
00104 spectrum.push_back(p);
00105 }
00106 spectrum.setMSLevel(2);
00107 spectrum.getPrecursors().resize(1);
00108 spectrum.getPrecursors()[0].setMZ(pre_mz);
00109 spectrum.getPrecursors()[0].setIntensity(pre_int);
00110 spectrum.getPrecursors()[0].setCharge(charge);
00111 spectrum.setRT(rt);
00112 if (title != "")
00113 {
00114 spectrum.setMetaValue("TITLE", title);
00115 title = "";
00116 }
00117
00118 exp.push_back(spectrum);
00119
00120
00121 spec.clear();
00122 charge = 0;
00123 pre_mz = 0;
00124 pre_int = 0;
00125 }
00126 }
00127
00129 const String & getBoundary();
00131 void setBoundary(const String & boundary);
00132
00134 const String & getDB();
00136 void setDB(const String & db);
00137
00139 const String & getSearchType();
00141 void setSearchType(const String & search_type);
00142
00144 const String & getHits();
00146 void setHits(const String & hits);
00147
00149 const String & getCleavage();
00151 void setCleavage(const String & cleavage);
00152
00154 const String & getMassType();
00156 void setMassType(const String & mass_type);
00157
00159 const std::vector<String> & getModifications();
00161 void setModifications(const std::vector<String> & mods);
00162
00164 const std::vector<String> & getVariableModifications();
00166 void setVariableModifications(const std::vector<String> & mods);
00167
00169 const String & getInstrument();
00171 void setInstrument(const String & instrument);
00172
00174 UInt getMissedCleavages();
00176 void setMissedCleavages(UInt missed_cleavages);
00177
00179 Real getPrecursorMassTolerance();
00181 void setPrecursorMassTolerance(Real precursor_mass_tolerance);
00182
00184 Real getPeakMassTolerance();
00186 void setPeakMassTolerance(Real ion_mass_tolerance);
00187
00189 const String & getTaxonomy();
00191 void setTaxonomy(const String & taxonomy);
00192
00194 const String & getFormVersion();
00196 void setFormVersion(const String & form_version);
00197
00199 const String & getCharges();
00201 void setCharges(std::vector<Int> & charges);
00202
00203 protected:
00205 DoubleReal mz_;
00206
00208 String charges_;
00209
00211 String search_title_;
00212
00214 String db_;
00215
00217 String search_type_;
00218
00220 String hits_;
00221
00223 String cleavage_;
00224
00226 String mass_type_;
00227
00229 std::vector<String> mods_;
00230
00232 std::vector<String> variable_mods_;
00233
00235 String instrument_;
00236
00238 UInt missed_cleavages_;
00239
00241 Real precursor_mass_tolerance_;
00242
00244 Real ion_mass_tolerance_;
00245
00247 String taxonomy_;
00248
00250 String form_version_;
00251
00253 String boundary_;
00254
00256 DoubleReal retention_time_;
00257
00259 void writeParameterHeader_(const String & name, FILE * fp, bool line_break = true);
00260
00262 void writeHeader_(FILE * fp);
00263
00265 void writeSpectrum_(FILE * fp,
00266 const String & filename,
00267 const PeakSpectrum & peaks);
00268
00270 void writeMSExperiment_(FILE * fp,
00271 const String & filename,
00272 const MSExperiment<> & experiment);
00273
00274 bool getNextSpectrum_(std::istream & is, std::vector<std::pair<double, double> > & spectrum, UInt & charge, double & precursor_mz, double & precursor_int, double & rt, String & title);
00275 };
00276
00277 }
00278
00279 #endif // OPENMS_FORMAT_MASCOTINFILE_H