~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/ANALYSIS/ID/PILISModel.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Andreas Bertsch $
42
49
#include <OpenMS/ANALYSIS/ID/PILISNeutralLossModel.h>
43
50
 
44
51
 
45
 
namespace OpenMS 
 
52
namespace OpenMS
46
53
{
47
 
        class AASequence;
48
 
        
49
 
        /** 
50
 
          @brief This class implements the simulation of the spectra from PILIS
51
 
 
52
 
                PILIS uses a HMM based structure to model the population of fragment ions
53
 
                from a peptide. The spectrum generator can be accessed via the getSpectrum
54
 
                method.
55
 
                 
56
 
                @htmlinclude OpenMS_PILISModel.parameters
57
 
 
58
 
                @ingroup Analysis_ID
59
 
        */      
60
 
        class OPENMS_DLLAPI PILISModel : public DefaultParamHandler
61
 
        {
62
 
                public:
63
 
                                                
64
 
                        /** @name Constructors and destructors
65
 
                        */
66
 
                        //@{
67
 
                        /// default constructor
68
 
                        PILISModel();
69
 
 
70
 
                        /// copy constructor
71
 
                        PILISModel(const PILISModel& model);
72
 
                        
73
 
                        /// destructor
74
 
                        virtual ~PILISModel();
75
 
                        //@}
76
 
 
77
 
                        /// assignment operator
78
 
                        PILISModel& operator = (const PILISModel& mode);
79
 
                        
80
 
                        /** @name Accessors
81
 
                        */
82
 
                        //@{
83
 
                        /// performs a training step; needs as parameters a spectrum with annotated sequence and charge
84
 
                        void train(const RichPeakSpectrum&, const AASequence& peptide, UInt charge);
85
 
 
86
 
                        /** reads the model parameters from the given files
87
 
                            @param filename filename of the model
88
 
                        */ 
89
 
                        void readFromFile(const String& filename);
90
 
 
91
 
                        /// writes the HMM to the given file in the GraphML format. A detailed description of the GraphML format can be found under http://graphml.graphdrawing.org/
92
 
                        void writeGraphMLFile(const String& filename);
93
 
 
94
 
                        /** writes the model parameters into the given files
95
 
                            @param filename filename of the base model
96
 
                        */                       
97
 
                        void writeToFile(const String& filename);
98
 
 
99
 
                        // 
100
 
                        void init(bool generate_models = true);
101
 
                        
102
 
                        /// simulates a spectrum with the model of the given peptide and charge and writes it to the given PeakSpectrum
103
 
                        void getSpectrum(RichPeakSpectrum& spec, const AASequence& peptide, UInt charge);
104
 
 
105
 
                        /// this method evaluates the model after training; it should be called after all training steps with train
106
 
                        void evaluate();
107
 
                        //@}
108
 
 
109
 
                protected:
110
 
 
111
 
                        /// get the initial transition probabilities from the proton dist, returns true if charge remote is enabled
112
 
                        bool getInitialTransitionProbabilities_(std::vector<DoubleReal>& bb_init, 
113
 
                                                                                                                                                                                        std::vector<DoubleReal>& cr_init, 
114
 
                                                                                                                                                                                        std::vector<DoubleReal>& sc_init, 
115
 
                                                                                                                                                                                        DoubleReal& precursor_init,
116
 
                                                                                                                                                                                        const std::vector<DoubleReal>& bb_charges,
117
 
                                                                                                                                                                                        const std::vector<DoubleReal>& sc_charges,
118
 
                                                                                                                                                                                        const AASequence& peptide);
119
 
 
120
 
                        DoubleReal getAvailableBackboneCharge_(const AASequence& ion, Residue::ResidueType res_type, int charge);
121
 
 
122
 
                        /// add peaks to spectrum
123
 
                        void addPeaks_(DoubleReal mz, int charge, DoubleReal mz_offset, DoubleReal intensity, RichPeakSpectrum& spectrum, const IsotopeDistribution& id, const String& name);
124
 
                
125
 
                        /// parse the base model
126
 
                        void parseHMMModel_(const TextFile::ConstIterator& begin, const TextFile::ConstIterator& end, HiddenMarkovModel& hmm, Param& param);
127
 
        
128
 
                        /// write parameters of the model
129
 
                        void writeParameters_(std::ostream& os, const Param& param);
130
 
 
131
 
                        /// base model used
132
 
                        HiddenMarkovModel hmm_;
133
 
 
134
 
                        /// proton distribution model
135
 
                        ProtonDistributionModel prot_dist_;
136
 
 
137
 
                        /// theoretical spectrum generator (needed for training/aligning and spectrum intensity extraction)
138
 
                        TheoreticalSpectrumGenerator tsg_;
139
 
 
140
 
                        /// true if the instance is valid
141
 
                        bool valid_;
142
 
 
143
 
                        /// stores the peaks of a spectrum
144
 
                        Map<DoubleReal, std::vector<RichPeak1D> > peaks_;
145
 
 
146
 
                        /// the alignment algorithm used
147
 
                        SpectrumAlignment spectra_aligner_;
148
 
 
149
 
                        /// precursor model used
150
 
                        PILISNeutralLossModel precursor_model_cr_;
151
 
 
152
 
                        PILISNeutralLossModel precursor_model_cd_;
153
 
 
154
 
                        PILISNeutralLossModel a_ion_losses_cr_;
155
 
                        PILISNeutralLossModel a_ion_losses_cd_;
156
 
                        
157
 
                        PILISNeutralLossModel b_ion_losses_cr_;
158
 
                        PILISNeutralLossModel b_ion_losses_cd_;
159
 
 
160
 
                        PILISNeutralLossModel b2_ion_losses_cr_;
161
 
                        PILISNeutralLossModel b2_ion_losses_cd_;
162
 
                        
163
 
                        PILISNeutralLossModel y_ion_losses_cr_;
164
 
                        PILISNeutralLossModel y_ion_losses_cd_;
165
 
 
166
 
                        void updateMembers_();
167
 
        };
 
54
  class AASequence;
 
55
 
 
56
  /**
 
57
    @brief This class implements the simulation of the spectra from PILIS
 
58
 
 
59
      PILIS uses a HMM based structure to model the population of fragment ions
 
60
      from a peptide. The spectrum generator can be accessed via the getSpectrum
 
61
      method.
 
62
 
 
63
      @htmlinclude OpenMS_PILISModel.parameters
 
64
 
 
65
      @ingroup Analysis_ID
 
66
  */
 
67
  class OPENMS_DLLAPI PILISModel :
 
68
    public DefaultParamHandler
 
69
  {
 
70
public:
 
71
 
 
72
    /** @name Constructors and destructors
 
73
    */
 
74
    //@{
 
75
    /// default constructor
 
76
    PILISModel();
 
77
 
 
78
    /// copy constructor
 
79
    PILISModel(const PILISModel & model);
 
80
 
 
81
    /// destructor
 
82
    virtual ~PILISModel();
 
83
    //@}
 
84
 
 
85
    /// assignment operator
 
86
    PILISModel & operator=(const PILISModel & mode);
 
87
 
 
88
    /** @name Accessors
 
89
    */
 
90
    //@{
 
91
    /// performs a training step; needs as parameters a spectrum with annotated sequence and charge
 
92
    void train(const RichPeakSpectrum &, const AASequence & peptide, UInt charge);
 
93
 
 
94
    /** reads the model parameters from the given files
 
95
        @param filename filename of the model
 
96
    */
 
97
    void readFromFile(const String & filename);
 
98
 
 
99
    /// writes the HMM to the given file in the GraphML format. A detailed description of the GraphML format can be found under http://graphml.graphdrawing.org/
 
100
    void writeGraphMLFile(const String & filename);
 
101
 
 
102
    /** writes the model parameters into the given files
 
103
        @param filename filename of the base model
 
104
    */
 
105
    void writeToFile(const String & filename);
 
106
 
 
107
    //
 
108
    void init(bool generate_models = true);
 
109
 
 
110
    /// simulates a spectrum with the model of the given peptide and charge and writes it to the given PeakSpectrum
 
111
    void getSpectrum(RichPeakSpectrum & spec, const AASequence & peptide, UInt charge);
 
112
 
 
113
    /// this method evaluates the model after training; it should be called after all training steps with train
 
114
    void evaluate();
 
115
    //@}
 
116
 
 
117
protected:
 
118
 
 
119
    /// get the initial transition probabilities from the proton dist, returns true if charge remote is enabled
 
120
    bool getInitialTransitionProbabilities_(std::vector<DoubleReal> & bb_init,
 
121
                                            std::vector<DoubleReal> & cr_init,
 
122
                                            std::vector<DoubleReal> & sc_init,
 
123
                                            DoubleReal & precursor_init,
 
124
                                            const std::vector<DoubleReal> & bb_charges,
 
125
                                            const std::vector<DoubleReal> & sc_charges,
 
126
                                            const AASequence & peptide);
 
127
 
 
128
    DoubleReal getAvailableBackboneCharge_(const AASequence & ion, Residue::ResidueType res_type, int charge);
 
129
 
 
130
    /// add peaks to spectrum
 
131
    void addPeaks_(DoubleReal mz, int charge, DoubleReal mz_offset, DoubleReal intensity, RichPeakSpectrum & spectrum, const IsotopeDistribution & id, const String & name);
 
132
 
 
133
    /// parse the base model
 
134
    void parseHMMModel_(const TextFile::ConstIterator & begin, const TextFile::ConstIterator & end, HiddenMarkovModel & hmm, Param & param);
 
135
 
 
136
    /// write parameters of the model
 
137
    void writeParameters_(std::ostream & os, const Param & param);
 
138
 
 
139
    /// base model used
 
140
    HiddenMarkovModel hmm_;
 
141
 
 
142
    /// proton distribution model
 
143
    ProtonDistributionModel prot_dist_;
 
144
 
 
145
    /// theoretical spectrum generator (needed for training/aligning and spectrum intensity extraction)
 
146
    TheoreticalSpectrumGenerator tsg_;
 
147
 
 
148
    /// true if the instance is valid
 
149
    bool valid_;
 
150
 
 
151
    /// stores the peaks of a spectrum
 
152
    Map<DoubleReal, std::vector<RichPeak1D> > peaks_;
 
153
 
 
154
    /// the alignment algorithm used
 
155
    SpectrumAlignment spectra_aligner_;
 
156
 
 
157
    /// precursor model used
 
158
    PILISNeutralLossModel precursor_model_cr_;
 
159
 
 
160
    PILISNeutralLossModel precursor_model_cd_;
 
161
 
 
162
    PILISNeutralLossModel a_ion_losses_cr_;
 
163
    PILISNeutralLossModel a_ion_losses_cd_;
 
164
 
 
165
    PILISNeutralLossModel b_ion_losses_cr_;
 
166
    PILISNeutralLossModel b_ion_losses_cd_;
 
167
 
 
168
    PILISNeutralLossModel b2_ion_losses_cr_;
 
169
    PILISNeutralLossModel b2_ion_losses_cd_;
 
170
 
 
171
    PILISNeutralLossModel y_ion_losses_cr_;
 
172
    PILISNeutralLossModel y_ion_losses_cd_;
 
173
 
 
174
    void updateMembers_();
 
175
  };
168
176
}
169
177
#endif
170