1
// -*- Mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
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.
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.
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.
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.
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Andreas Bertsch $
42
49
#include <OpenMS/ANALYSIS/ID/PILISNeutralLossModel.h>
50
@brief This class implements the simulation of the spectra from PILIS
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
56
@htmlinclude OpenMS_PILISModel.parameters
60
class OPENMS_DLLAPI PILISModel : public DefaultParamHandler
64
/** @name Constructors and destructors
67
/// default constructor
71
PILISModel(const PILISModel& model);
74
virtual ~PILISModel();
77
/// assignment operator
78
PILISModel& operator = (const PILISModel& mode);
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);
86
/** reads the model parameters from the given files
87
@param filename filename of the model
89
void readFromFile(const String& filename);
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);
94
/** writes the model parameters into the given files
95
@param filename filename of the base model
97
void writeToFile(const String& filename);
100
void init(bool generate_models = true);
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);
105
/// this method evaluates the model after training; it should be called after all training steps with train
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);
120
DoubleReal getAvailableBackboneCharge_(const AASequence& ion, Residue::ResidueType res_type, int charge);
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);
125
/// parse the base model
126
void parseHMMModel_(const TextFile::ConstIterator& begin, const TextFile::ConstIterator& end, HiddenMarkovModel& hmm, Param& param);
128
/// write parameters of the model
129
void writeParameters_(std::ostream& os, const Param& param);
132
HiddenMarkovModel hmm_;
134
/// proton distribution model
135
ProtonDistributionModel prot_dist_;
137
/// theoretical spectrum generator (needed for training/aligning and spectrum intensity extraction)
138
TheoreticalSpectrumGenerator tsg_;
140
/// true if the instance is valid
143
/// stores the peaks of a spectrum
144
Map<DoubleReal, std::vector<RichPeak1D> > peaks_;
146
/// the alignment algorithm used
147
SpectrumAlignment spectra_aligner_;
149
/// precursor model used
150
PILISNeutralLossModel precursor_model_cr_;
152
PILISNeutralLossModel precursor_model_cd_;
154
PILISNeutralLossModel a_ion_losses_cr_;
155
PILISNeutralLossModel a_ion_losses_cd_;
157
PILISNeutralLossModel b_ion_losses_cr_;
158
PILISNeutralLossModel b_ion_losses_cd_;
160
PILISNeutralLossModel b2_ion_losses_cr_;
161
PILISNeutralLossModel b2_ion_losses_cd_;
163
PILISNeutralLossModel y_ion_losses_cr_;
164
PILISNeutralLossModel y_ion_losses_cd_;
166
void updateMembers_();
57
@brief This class implements the simulation of the spectra from PILIS
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
63
@htmlinclude OpenMS_PILISModel.parameters
67
class OPENMS_DLLAPI PILISModel :
68
public DefaultParamHandler
72
/** @name Constructors and destructors
75
/// default constructor
79
PILISModel(const PILISModel & model);
82
virtual ~PILISModel();
85
/// assignment operator
86
PILISModel & operator=(const PILISModel & mode);
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);
94
/** reads the model parameters from the given files
95
@param filename filename of the model
97
void readFromFile(const String & filename);
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);
102
/** writes the model parameters into the given files
103
@param filename filename of the base model
105
void writeToFile(const String & filename);
108
void init(bool generate_models = true);
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);
113
/// this method evaluates the model after training; it should be called after all training steps with train
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);
128
DoubleReal getAvailableBackboneCharge_(const AASequence & ion, Residue::ResidueType res_type, int charge);
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);
133
/// parse the base model
134
void parseHMMModel_(const TextFile::ConstIterator & begin, const TextFile::ConstIterator & end, HiddenMarkovModel & hmm, Param & param);
136
/// write parameters of the model
137
void writeParameters_(std::ostream & os, const Param & param);
140
HiddenMarkovModel hmm_;
142
/// proton distribution model
143
ProtonDistributionModel prot_dist_;
145
/// theoretical spectrum generator (needed for training/aligning and spectrum intensity extraction)
146
TheoreticalSpectrumGenerator tsg_;
148
/// true if the instance is valid
151
/// stores the peaks of a spectrum
152
Map<DoubleReal, std::vector<RichPeak1D> > peaks_;
154
/// the alignment algorithm used
155
SpectrumAlignment spectra_aligner_;
157
/// precursor model used
158
PILISNeutralLossModel precursor_model_cr_;
160
PILISNeutralLossModel precursor_model_cd_;
162
PILISNeutralLossModel a_ion_losses_cr_;
163
PILISNeutralLossModel a_ion_losses_cd_;
165
PILISNeutralLossModel b_ion_losses_cr_;
166
PILISNeutralLossModel b_ion_losses_cd_;
168
PILISNeutralLossModel b2_ion_losses_cr_;
169
PILISNeutralLossModel b2_ion_losses_cd_;
171
PILISNeutralLossModel y_ion_losses_cr_;
172
PILISNeutralLossModel y_ion_losses_cd_;
174
void updateMembers_();