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

SvmTheoreticalSpectrumGenerator.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: Sandro Andreotti $
00032 // $Authors: Sandro Andreotti $
00033 // --------------------------------------------------------------------------
00034 
00035 
00036 #ifndef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
00037 #define OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
00038 
00039 #include <OpenMS/config.h>
00040 #include <OpenMS/CHEMISTRY/TheoreticalSpectrumGenerator.h>
00041 #include <OpenMS/SIMULATION/SimTypes.h>
00042 #include <OpenMS/ANALYSIS/SVM/SVMWrapper.h>
00043 #include <boost/smart_ptr.hpp>
00044 
00045 
00046 
00047 
00048 
00049 namespace OpenMS
00050 {
00069   class OPENMS_DLLAPI SvmTheoreticalSpectrumGenerator :
00070     public DefaultParamHandler
00071   {
00072     friend class SvmTheoreticalSpectrumGeneratorTrainer;
00073 public:
00074 
00079 
00080     struct IonType
00081     {
00082       Residue::ResidueType residue;
00083       EmpiricalFormula loss;
00084       Int charge;
00085 
00088       //Default constructor
00089       IonType() :
00090         residue((Residue::ResidueType) 0),
00091         loss(),
00092         charge(0)
00093       {
00094       }
00095 
00096       //Custom construtor
00097       IonType(Residue::ResidueType residue, EmpiricalFormula loss = EmpiricalFormula(), Int charge = 1) :
00098         residue(residue),
00099         loss(loss),
00100         charge(charge)
00101       {
00102       }
00103 
00104       //Copy constructor
00105       IonType(const IonType & rhs) :
00106         residue(rhs.residue),
00107         loss(rhs.loss),
00108         charge(rhs.charge)
00109       {
00110       }
00111 
00112       //Assignment operator
00113       IonType & operator=(const IonType & rhs)
00114       {
00115         if (this != &rhs)
00116         {
00117           residue = rhs.residue;
00118           loss = rhs.loss;
00119           charge = rhs.charge;
00120         }
00121         return *this;
00122       }
00123 
00124       bool operator<(const IonType & rhs) const
00125       {
00126         if (residue != rhs.residue)
00127           return residue < rhs.residue;
00128         else if (loss.getString() != rhs.loss.getString())
00129           return loss.getString() < rhs.loss.getString();
00130         else
00131           return charge < rhs.charge;
00132       }
00133 
00134     };
00136 
00138     struct DescriptorSet
00139     {
00140       typedef std::vector<svm_node> DescriptorSetType;
00141       DescriptorSetType descriptors;
00142     };
00143 
00144 
00146     struct SvmModelParameterSet
00147     {
00148       //pointers to the svm classification models (one per ion_type)
00149       std::vector<boost::shared_ptr<SVMWrapper> > class_models;
00150 
00151       //pointers to the svm regression models (one per ion_type)
00152       std::vector<boost::shared_ptr<SVMWrapper> > reg_models;
00153 
00154       //The intensity for each ion type for the SVC mode
00155       std::map<Residue::ResidueType, DoubleReal> static_intensities;
00156 
00157       //The selected primary IonTypes
00158       std::vector<IonType> ion_types;
00159 
00160       //The selected secondary IonTypes
00161       std::map<IonType, std::vector<IonType> > secondary_types;
00162 
00163       //The number of intensity levels
00164       Size number_intensity_levels;
00165 
00166       //The number of regions for every spectrum
00167       Size number_regions;
00168 
00169       //upper limits (required for scaling)
00170       std::vector<DoubleReal> feature_max;
00171 
00172       //lower limits (required for scaling)
00173       std::vector<DoubleReal> feature_min;
00174 
00175       //lower bound for scaling
00176       double scaling_lower;
00177 
00178       //upper bound for scaling
00179       double scaling_upper;
00180 
00181       //border values for binning secondary types intensity
00182       std::vector<DoubleReal> intensity_bin_boarders;
00183 
00184       //intensity values for binned secondary types intensity
00185       std::vector<DoubleReal> intensity_bin_values;
00186 
00187       //conditional probabilities for secondary types
00188       std::map<std::pair<IonType, Size>, std::vector<std::vector<DoubleReal> > > conditional_prob;
00189     };
00190 
00191 
00192 
00196 
00197     SvmTheoreticalSpectrumGenerator();
00198 
00200     SvmTheoreticalSpectrumGenerator(const SvmTheoreticalSpectrumGenerator & source);
00201 
00203     SvmTheoreticalSpectrumGenerator & operator=(const SvmTheoreticalSpectrumGenerator & tsg);
00204 
00205 
00207     virtual ~SvmTheoreticalSpectrumGenerator();
00209 
00210 
00212     void simulate(RichPeakSpectrum & spectrum, const AASequence & peptide, const gsl_rng * rng, Size precursor_charge);
00213 
00215     void load();
00216 
00218     const std::vector<IonType> & getIonTypes()
00219     {
00220       return mp_.ion_types;
00221     }
00222 
00223 protected:
00224     typedef std::map<IonType, DoubleReal> IntensityMap;
00225 
00227     Size precursor_charge_;
00228 
00230     SvmModelParameterSet mp_;
00231 
00233     static std::map<String, Size> aa_to_index_;
00234 
00236     static std::map<String, DoubleReal> hydrophobicity_;
00237 
00239     static std::map<String, DoubleReal> helicity_;
00240 
00242     static std::map<String, DoubleReal> basicity_;
00243 
00245     std::map<IonType, bool> hide_type_;
00246 
00248     inline void scaleSingleFeature_(double & value, double feature_min, double feature_max, double lower = -1.0, double upper = 1.0);
00249 
00251     void scaleDescriptorSet_(DescriptorSet & desc, double lower, double upper);
00252 
00254     Size generateDescriptorSet_(AASequence peptide, Size position, IonType type, Size precursor_charge, DescriptorSet & desc_set);
00255 
00257     String ResidueTypeToString_(Residue::ResidueType type);
00258 
00260     static void initializeMaps_();
00261 
00263     static bool initializedMaps_;
00264 
00265     void updateMembers_();
00266   };
00267 
00268   void inline SvmTheoreticalSpectrumGenerator::scaleSingleFeature_(double & value, double lower, double upper, double feature_min, double feature_max)
00269   {
00270     double prev = value;
00271     if (feature_max == feature_min)
00272     {
00273       return;
00274     }
00275 
00276     if (value <= feature_min)
00277     {
00278       value = lower;
00279     }
00280     else if (value >= feature_max)
00281     {
00282       value = upper;
00283     }
00284     else
00285     {
00286       value = lower + (upper - lower) *
00287               (value - feature_min) /
00288               (feature_max - feature_min);
00289     }
00290 
00291     if (value < 0)
00292     {
00293       std::cerr << "negative value!! " << value << "  l: " << lower << " u: " << upper << " fm: " << feature_min << " fma: " << feature_max << "  prev: " << prev << std::endl;
00294     }
00295   }
00296 
00297 } // namespace OpenMS
00298 
00299 #endif // #ifdef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATORTRAINER_H

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