Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

MascotInfile.h (Maintainer: Nico Pfeifer)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Nico Pfeifer $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_FORMAT_MASCOTINFILE_H
00028 #define OPENMS_FORMAT_MASCOTINFILE_H
00029 
00030 #include <OpenMS/KERNEL/DPeakArray.h>
00031 #include <OpenMS/KERNEL/MSExperiment.h>
00032 #include <OpenMS/DATASTRUCTURES/String.h>
00033 #include <OpenMS/SYSTEM/File.h>
00034 #include <OpenMS/CONCEPT/ProgressLogger.h>
00035 
00036 #include <vector>
00037 #include <fstream>
00038 
00039 namespace OpenMS
00040 {
00048   class MascotInfile
00049     : public ProgressLogger
00050   {
00051     public:
00052 
00054       MascotInfile();
00055 
00057       virtual ~MascotInfile();
00058 
00060       void store(const String& filename, const DPeakArray<Peak1D>& spec, DoubleReal mz , DoubleReal retention_time, String search_title);   
00061 
00063       void store(const String& filename, const MSExperiment< Peak1D >& experiment, String search_title);
00064                             
00066       template <typename MapType> void load(const String& filename, MapType& map) throw (Exception::FileNotFound, Exception::ParseError)
00067       {
00068         map.reset();
00069         if (!File::exists(filename))
00070         {
00071           throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
00072         }
00073 
00074         std::ifstream is(filename.c_str());
00075         std::vector<std::pair<double, double> > spec;
00076         UInt charge(0);
00077         double pre_mz(0), pre_int(0), rt(-1);
00078         String title;
00079         while (getNextSpectrum_(is, spec, charge, pre_mz, pre_int, rt, title))
00080         {
00081           typename MapType::SpectrumType spectrum;
00082           for (std::vector<std::pair<double, double> >::const_iterator it = spec.begin(); it != spec.end(); ++it)
00083           {
00084             typename MapType::PeakType p;
00085             p.setPosition(it->first);
00086             p.setIntensity(it->second);
00087             spectrum.push_back(p);
00088           }
00089           spectrum.setMSLevel(2);
00090           spectrum.getPrecursorPeak().setPosition(pre_mz);
00091           spectrum.getPrecursorPeak().setIntensity(pre_int);
00092           spectrum.getPrecursorPeak().setCharge(charge);
00093           spectrum.setRT(rt);
00094           if (title != "")
00095           {
00096             spectrum.setMetaValue("TITLE", title);
00097             title = "";
00098           }
00099 
00100           map.push_back(spectrum);
00101           
00102           // clean up
00103           spec.clear();
00104           charge = 0;
00105           pre_mz = 0;
00106           pre_int = 0;
00107         }
00108       }
00109 
00110       
00112       const String& getBoundary();
00114       void setBoundary(const String& boundary);
00115 
00117       const String& getDB();
00119       void setDB(const String& db);
00120 
00122       const String& getSearchType();
00124       void setSearchType(const String& search_type);
00125 
00127       const String& getHits();
00129       void setHits(const String& hits);
00130 
00132       const String& getCleavage();
00134       void setCleavage(const String& cleavage);
00135 
00137       const String& getMassType();
00139       void setMassType(const String& mass_type);
00140 
00142       const std::vector<String>& getModifications();
00144       void setModifications(const std::vector<String>& mods);
00145 
00147       const std::vector<String>& getVariableModifications();
00149       void setVariableModifications(const std::vector<String>& mods);
00150 
00152       const String& getInstrument();
00154       void setInstrument(const String& instrument);
00155 
00157       UInt getMissedCleavages();
00159       void setMissedCleavages(UInt missed_cleavages);
00160 
00162       Real getPrecursorMassTolerance();
00164       void setPrecursorMassTolerance(Real precursor_mass_tolerance);
00165 
00167       Real getPeakMassTolerance();
00169       void setPeakMassTolerance(Real ion_mass_tolerance);
00170 
00172       const String& getTaxonomy();
00174       void setTaxonomy(const String& taxonomy);
00175 
00177       const String& getFormVersion();
00179       void setFormVersion(const String& form_version);
00180 
00182       const String& getCharges();
00184       void setCharges(std::vector<Int>& charges);
00185 
00186     protected:
00188       DoubleReal mz_;
00189 
00191       String charges_;
00192 
00194       String search_title_;
00195 
00197       String db_;
00198 
00200       String search_type_;
00201 
00203       String hits_;
00204 
00206       String cleavage_;
00207 
00209       String mass_type_;
00210 
00212       std::vector<String> mods_;
00213 
00215       std::vector<String> variable_mods_;
00216 
00218       String instrument_;
00219 
00221       UInt missed_cleavages_;
00222 
00224       Real precursor_mass_tolerance_;
00225 
00227       Real ion_mass_tolerance_;
00228 
00230       String taxonomy_;
00231 
00233       String form_version_;
00234 
00236       String boundary_;
00237 
00239       DoubleReal retention_time_;
00240 
00242       void writeParameterHeader_(const String& name, FILE* fp, bool line_break = true);
00243 
00245       void writeHeader_(FILE* fp);
00246       
00248       void writeSpectrum_(FILE* fp,
00249                           const String& filename,
00250                           const DPeakArray<Peak1D>& peaks);
00251             
00253       void writeMSExperiment_(FILE* fp, 
00254                               const String& filename, 
00255                               const MSExperiment< Peak1D >& experiment);
00256 
00257       bool getNextSpectrum_(std::istream& is, std::vector<std::pair<double, double> >& spectrum, UInt& charge, double& precursor_mz, double& precursor_int, double& rt, String& title);
00258   };
00259 
00260 } // namespace OpenMS
00261 
00262 #endif // OPENMS_FORMAT_MASCOTINFILE_H

Generated Tue Apr 1 15:36:35 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1