Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SvmTheoreticalSpectrumGenerator.h
Go to the documentation of this file.
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-2017.
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.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Sandro Andreotti $
33 // --------------------------------------------------------------------------
34 
35 
36 #ifndef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
37 #define OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
38 
39 #include <OpenMS/config.h>
42 
47 
48 #include <boost/random/mersenne_twister.hpp>
49 
50 
51 
52 namespace OpenMS
53 {
72  class OPENMS_DLLAPI SvmTheoreticalSpectrumGenerator :
73  public DefaultParamHandler
74  {
76 public:
77 
82  struct IonType
84  {
88 
91  //Default constructor
92  IonType() :
93  residue((Residue::ResidueType) 0),
94  loss(),
95  charge(0)
96  {
97  }
98 
99  //Custom constructor
100  IonType(Residue::ResidueType local_residue, EmpiricalFormula local_loss = EmpiricalFormula(), Int local_charge = 1) :
101  residue(local_residue),
102  loss(local_loss),
103  charge(local_charge)
104  {
105  }
106 
107  //Copy constructor
108  IonType(const IonType & rhs) :
109  residue(rhs.residue),
110  loss(rhs.loss),
111  charge(rhs.charge)
112  {
113  }
114 
115  //Assignment operator
116  IonType & operator=(const IonType & rhs)
117  {
118  if (this != &rhs)
119  {
120  residue = rhs.residue;
121  loss = rhs.loss;
122  charge = rhs.charge;
123  }
124  return *this;
125  }
126 
127  bool operator<(const IonType & rhs) const
128  {
129  if (residue != rhs.residue)
130  return residue < rhs.residue;
131  else if (loss.toString() != rhs.loss.toString())
132  return loss.toString() < rhs.loss.toString();
133  else
134  return charge < rhs.charge;
135  }
136 
137  };
139 
142  {
143  typedef std::vector<svm_node> DescriptorSetType;
144  DescriptorSetType descriptors;
145  };
146 
147 
150  {
151  //pointers to the svm classification models (one per ion_type)
152  std::vector<boost::shared_ptr<SVMWrapper> > class_models;
153 
154  //pointers to the svm regression models (one per ion_type)
155  std::vector<boost::shared_ptr<SVMWrapper> > reg_models;
156 
157  //The intensity for each ion type for the SVC mode
158  std::map<Residue::ResidueType, double> static_intensities;
159 
160  //The selected primary IonTypes
161  std::vector<IonType> ion_types;
162 
163  //The selected secondary IonTypes
164  std::map<IonType, std::vector<IonType> > secondary_types;
165 
166  //The number of intensity levels
168 
169  //The number of regions for every spectrum
171 
172  //upper limits (required for scaling)
173  std::vector<double> feature_max;
174 
175  //lower limits (required for scaling)
176  std::vector<double> feature_min;
177 
178  //lower bound for scaling
180 
181  //upper bound for scaling
183 
184  //border values for binning secondary types intensity
185  std::vector<double> intensity_bin_boarders;
186 
187  //intensity values for binned secondary types intensity
188  std::vector<double> intensity_bin_values;
189 
190  //conditional probabilities for secondary types
191  std::map<std::pair<IonType, Size>, std::vector<std::vector<double> > > conditional_prob;
192  };
193 
194 
195 
201 
204 
207 
208 
212 
213 
215  void simulate(PeakSpectrum & spectrum, const AASequence & peptide, boost::random::mt19937_64& rng, Size precursor_charge);
216 
218  void load();
219 
221  const std::vector<IonType> & getIonTypes()
222  {
223  return mp_.ion_types;
224  }
225 
226 protected:
227  typedef std::map<IonType, double> IntensityMap;
228 
231 
234 
236  static std::map<String, Size> aa_to_index_;
237 
239  static std::map<String, double> hydrophobicity_;
240 
242  static std::map<String, double> helicity_;
243 
245  static std::map<String, double> basicity_;
246 
248  std::map<IonType, bool> hide_type_;
249 
251  inline void scaleSingleFeature_(double & value, double feature_min, double feature_max, double lower = -1.0, double upper = 1.0);
252 
254  void scaleDescriptorSet_(DescriptorSet & desc, double lower, double upper);
255 
257  Size generateDescriptorSet_(AASequence peptide, Size position, IonType type, Size precursor_charge, DescriptorSet & desc_set);
258 
260  String ResidueTypeToString_(Residue::ResidueType type);
261 
263  static void initializeMaps_();
264 
266  static bool initializedMaps_;
267 
268  void updateMembers_();
269  };
270 
271  void inline SvmTheoreticalSpectrumGenerator::scaleSingleFeature_(double & value, double lower, double upper, double feature_min, double feature_max)
272  {
273  double prev = value;
274  if (feature_max == feature_min)
275  {
276  return;
277  }
278 
279  if (value <= feature_min)
280  {
281  value = lower;
282  }
283  else if (value >= feature_max)
284  {
285  value = upper;
286  }
287  else
288  {
289  value = lower + (upper - lower) *
290  (value - feature_min) /
291  (feature_max - feature_min);
292  }
293 
294  if (value < 0)
295  {
296  std::cerr << "negative value!! " << value << " l: " << lower << " u: " << upper << " fm: " << feature_min << " fma: " << feature_max << " prev: " << prev << std::endl;
297  }
298  }
299 
300 } // namespace OpenMS
301 
302 #endif // #ifdef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATORTRAINER_H
static std::map< String, double > hydrophobicity_
hydrophobicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:239
nested class
Definition: SvmTheoreticalSpectrumGenerator.h:83
static std::map< String, Size > aa_to_index_
map AA to integers
Definition: SvmTheoreticalSpectrumGenerator.h:236
std::vector< double > intensity_bin_values
Definition: SvmTheoreticalSpectrumGenerator.h:188
A more convenient string class.
Definition: String.h:57
std::map< IonType, std::vector< IonType > > secondary_types
Definition: SvmTheoreticalSpectrumGenerator.h:164
std::vector< double > feature_max
Definition: SvmTheoreticalSpectrumGenerator.h:173
String toString() const
returns the formula as a string (charges are not included)
std::vector< double > feature_min
Definition: SvmTheoreticalSpectrumGenerator.h:176
Size number_regions
Definition: SvmTheoreticalSpectrumGenerator.h:170
double scaling_upper
Definition: SvmTheoreticalSpectrumGenerator.h:182
static std::map< String, double > helicity_
helicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:242
static std::map< String, double > basicity_
basicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:245
IonType()
Definition: SvmTheoreticalSpectrumGenerator.h:92
std::map< Residue::ResidueType, double > static_intensities
Definition: SvmTheoreticalSpectrumGenerator.h:158
Residue::ResidueType residue
Definition: SvmTheoreticalSpectrumGenerator.h:85
Representation of a peptide/protein sequence.
Definition: AASequence.h:108
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::vector< svm_node > DescriptorSetType
Definition: SvmTheoreticalSpectrumGenerator.h:143
Representation of a residue.
Definition: Residue.h:62
Representation of an empirical formula.
Definition: EmpiricalFormula.h:80
Simulates MS2 spectra with support vector machines.
Definition: SvmTheoreticalSpectrumGenerator.h:72
EmpiricalFormula loss
Definition: SvmTheoreticalSpectrumGenerator.h:86
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
Simple container storing the model parameters required for simulation.
Definition: SvmTheoreticalSpectrumGenerator.h:149
Train SVM models that are used by SvmTheoreticalSpectrumGenerator.
Definition: SvmTheoreticalSpectrumGeneratorTrainer.h:66
A set of descriptors for a single training row.
Definition: SvmTheoreticalSpectrumGenerator.h:141
static bool initializedMaps_
flag to indicate if the hydrophobicity, helicity, and basicity maps were already initialized ...
Definition: SvmTheoreticalSpectrumGenerator.h:266
IonType(const IonType &rhs)
Definition: SvmTheoreticalSpectrumGenerator.h:108
std::map< IonType, double > IntensityMap
Definition: SvmTheoreticalSpectrumGenerator.h:227
std::vector< boost::shared_ptr< SVMWrapper > > reg_models
Definition: SvmTheoreticalSpectrumGenerator.h:155
void scaleSingleFeature_(double &value, double feature_min, double feature_max, double lower=-1.0, double upper=1.0)
scale value to the interval [lower,max] given the maximal and minimal entries for a feature ...
Definition: SvmTheoreticalSpectrumGenerator.h:271
const std::vector< IonType > & getIonTypes()
return the set of ion types that are modeled by the loaded SVMs
Definition: SvmTheoreticalSpectrumGenerator.h:221
ResidueType
Definition: Residue.h:144
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
std::vector< boost::shared_ptr< SVMWrapper > > class_models
Definition: SvmTheoreticalSpectrumGenerator.h:152
Size precursor_charge_
charge of the precursors used for training
Definition: SvmTheoreticalSpectrumGenerator.h:230
bool operator<(const IonType &rhs) const
Definition: SvmTheoreticalSpectrumGenerator.h:127
DescriptorSetType descriptors
Definition: SvmTheoreticalSpectrumGenerator.h:144
SvmModelParameterSet mp_
set of model parameters read from model file
Definition: SvmTheoreticalSpectrumGenerator.h:233
IonType(Residue::ResidueType local_residue, EmpiricalFormula local_loss=EmpiricalFormula(), Int local_charge=1)
Definition: SvmTheoreticalSpectrumGenerator.h:100
std::vector< double > intensity_bin_boarders
Definition: SvmTheoreticalSpectrumGenerator.h:185
std::map< IonType, bool > hide_type_
whether ion types are hidden or not
Definition: SvmTheoreticalSpectrumGenerator.h:248
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Size number_intensity_levels
Definition: SvmTheoreticalSpectrumGenerator.h:167
Int charge
Definition: SvmTheoreticalSpectrumGenerator.h:87
IonType & operator=(const IonType &rhs)
Definition: SvmTheoreticalSpectrumGenerator.h:116
int Int
Signed integer type.
Definition: Types.h:103
std::vector< IonType > ion_types
Definition: SvmTheoreticalSpectrumGenerator.h:161
double scaling_lower
Definition: SvmTheoreticalSpectrumGenerator.h:179
std::map< std::pair< IonType, Size >, std::vector< std::vector< double > > > conditional_prob
Definition: SvmTheoreticalSpectrumGenerator.h:191

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:04 using doxygen 1.8.13