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

MascotInfile.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Nico Pfeifer $
00032 // $Authors: $
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         // clean up
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 } // namespace OpenMS
00278 
00279 #endif // OPENMS_FORMAT_MASCOTINFILE_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:41 using doxygen 1.7.1