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-2015.
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: Sandro Andreotti $
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>
43 
44 #include <boost/random/mersenne_twister.hpp>
45 
46 
47 
48 namespace OpenMS
49 {
68  class OPENMS_DLLAPI SvmTheoreticalSpectrumGenerator :
69  public DefaultParamHandler
70  {
72 public:
73 
78  struct IonType
80  {
84 
87  //Default constructor
88  IonType() :
89  residue((Residue::ResidueType) 0),
90  loss(),
91  charge(0)
92  {
93  }
94 
95  //Custom constructor
96  IonType(Residue::ResidueType local_residue, EmpiricalFormula local_loss = EmpiricalFormula(), Int local_charge = 1) :
97  residue(local_residue),
98  loss(local_loss),
99  charge(local_charge)
100  {
101  }
102 
103  //Copy constructor
104  IonType(const IonType & rhs) :
105  residue(rhs.residue),
106  loss(rhs.loss),
107  charge(rhs.charge)
108  {
109  }
110 
111  //Assignment operator
112  IonType & operator=(const IonType & rhs)
113  {
114  if (this != &rhs)
115  {
116  residue = rhs.residue;
117  loss = rhs.loss;
118  charge = rhs.charge;
119  }
120  return *this;
121  }
122 
123  bool operator<(const IonType & rhs) const
124  {
125  if (residue != rhs.residue)
126  return residue < rhs.residue;
127  else if (loss.toString() != rhs.loss.toString())
128  return loss.toString() < rhs.loss.toString();
129  else
130  return charge < rhs.charge;
131  }
132 
133  };
135 
138  {
139  typedef std::vector<svm_node> DescriptorSetType;
140  DescriptorSetType descriptors;
141  };
142 
143 
146  {
147  //pointers to the svm classification models (one per ion_type)
148  std::vector<boost::shared_ptr<SVMWrapper> > class_models;
149 
150  //pointers to the svm regression models (one per ion_type)
151  std::vector<boost::shared_ptr<SVMWrapper> > reg_models;
152 
153  //The intensity for each ion type for the SVC mode
154  std::map<Residue::ResidueType, double> static_intensities;
155 
156  //The selected primary IonTypes
157  std::vector<IonType> ion_types;
158 
159  //The selected secondary IonTypes
160  std::map<IonType, std::vector<IonType> > secondary_types;
161 
162  //The number of intensity levels
164 
165  //The number of regions for every spectrum
167 
168  //upper limits (required for scaling)
169  std::vector<double> feature_max;
170 
171  //lower limits (required for scaling)
172  std::vector<double> feature_min;
173 
174  //lower bound for scaling
176 
177  //upper bound for scaling
179 
180  //border values for binning secondary types intensity
181  std::vector<double> intensity_bin_boarders;
182 
183  //intensity values for binned secondary types intensity
184  std::vector<double> intensity_bin_values;
185 
186  //conditional probabilities for secondary types
187  std::map<std::pair<IonType, Size>, std::vector<std::vector<double> > > conditional_prob;
188  };
189 
190 
191 
197 
200 
203 
204 
208 
209 
211  void simulate(RichPeakSpectrum & spectrum, const AASequence & peptide, boost::random::mt19937_64& rng, Size precursor_charge);
212 
214  void load();
215 
217  const std::vector<IonType> & getIonTypes()
218  {
219  return mp_.ion_types;
220  }
221 
222 protected:
223  typedef std::map<IonType, double> IntensityMap;
224 
227 
230 
232  static std::map<String, Size> aa_to_index_;
233 
235  static std::map<String, double> hydrophobicity_;
236 
238  static std::map<String, double> helicity_;
239 
241  static std::map<String, double> basicity_;
242 
244  std::map<IonType, bool> hide_type_;
245 
247  inline void scaleSingleFeature_(double & value, double feature_min, double feature_max, double lower = -1.0, double upper = 1.0);
248 
250  void scaleDescriptorSet_(DescriptorSet & desc, double lower, double upper);
251 
253  Size generateDescriptorSet_(AASequence peptide, Size position, IonType type, Size precursor_charge, DescriptorSet & desc_set);
254 
256  String ResidueTypeToString_(Residue::ResidueType type);
257 
259  static void initializeMaps_();
260 
262  static bool initializedMaps_;
263 
264  void updateMembers_();
265  };
266 
267  void inline SvmTheoreticalSpectrumGenerator::scaleSingleFeature_(double & value, double lower, double upper, double feature_min, double feature_max)
268  {
269  double prev = value;
270  if (feature_max == feature_min)
271  {
272  return;
273  }
274 
275  if (value <= feature_min)
276  {
277  value = lower;
278  }
279  else if (value >= feature_max)
280  {
281  value = upper;
282  }
283  else
284  {
285  value = lower + (upper - lower) *
286  (value - feature_min) /
287  (feature_max - feature_min);
288  }
289 
290  if (value < 0)
291  {
292  std::cerr << "negative value!! " << value << " l: " << lower << " u: " << upper << " fm: " << feature_min << " fma: " << feature_max << " prev: " << prev << std::endl;
293  }
294  }
295 
296 } // namespace OpenMS
297 
298 #endif // #ifdef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATORTRAINER_H
static std::map< String, double > hydrophobicity_
hydrophobicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:235
nested class
Definition: SvmTheoreticalSpectrumGenerator.h:79
static std::map< String, Size > aa_to_index_
map AA to integers
Definition: SvmTheoreticalSpectrumGenerator.h:232
std::vector< double > intensity_bin_values
Definition: SvmTheoreticalSpectrumGenerator.h:184
A more convenient string class.
Definition: String.h:57
std::map< IonType, std::vector< IonType > > secondary_types
Definition: SvmTheoreticalSpectrumGenerator.h:160
std::vector< double > feature_max
Definition: SvmTheoreticalSpectrumGenerator.h:169
std::vector< double > feature_min
Definition: SvmTheoreticalSpectrumGenerator.h:172
Size number_regions
Definition: SvmTheoreticalSpectrumGenerator.h:166
double scaling_upper
Definition: SvmTheoreticalSpectrumGenerator.h:178
static std::map< String, double > helicity_
helicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:238
static std::map< String, double > basicity_
basicity values for each AA
Definition: SvmTheoreticalSpectrumGenerator.h:241
IonType()
Definition: SvmTheoreticalSpectrumGenerator.h:88
std::map< Residue::ResidueType, double > static_intensities
Definition: SvmTheoreticalSpectrumGenerator.h:154
Residue::ResidueType residue
Definition: SvmTheoreticalSpectrumGenerator.h:81
Representation of a peptide/protein sequence.
Definition: AASequence.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::vector< svm_node > DescriptorSetType
Definition: SvmTheoreticalSpectrumGenerator.h:139
Representation of a residue.
Definition: Residue.h:62
Representation of an empirical formula.
Definition: EmpiricalFormula.h:79
Simulates MS2 spectra with support vector machines.
Definition: SvmTheoreticalSpectrumGenerator.h:68
EmpiricalFormula loss
Definition: SvmTheoreticalSpectrumGenerator.h:82
Simple container storing the model parameters required for simulation.
Definition: SvmTheoreticalSpectrumGenerator.h:145
Train SVM models that are used by SvmTheoreticalSpectrumGenerator.
Definition: SvmTheoreticalSpectrumGeneratorTrainer.h:62
A set of descriptors for a single training row.
Definition: SvmTheoreticalSpectrumGenerator.h:137
static bool initializedMaps_
flag to indicate if the hydrophobicity, helicity, and basicity maps were already initialized ...
Definition: SvmTheoreticalSpectrumGenerator.h:262
IonType(const IonType &rhs)
Definition: SvmTheoreticalSpectrumGenerator.h:104
std::map< IonType, double > IntensityMap
Definition: SvmTheoreticalSpectrumGenerator.h:223
std::vector< boost::shared_ptr< SVMWrapper > > reg_models
Definition: SvmTheoreticalSpectrumGenerator.h:151
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:267
const std::vector< IonType > & getIonTypes()
return the set of ion types that are modeled by the loaded SVMs
Definition: SvmTheoreticalSpectrumGenerator.h:217
ResidueType
Definition: Residue.h:359
std::vector< boost::shared_ptr< SVMWrapper > > class_models
Definition: SvmTheoreticalSpectrumGenerator.h:148
Size precursor_charge_
charge of the precursors used for training
Definition: SvmTheoreticalSpectrumGenerator.h:226
DescriptorSetType descriptors
Definition: SvmTheoreticalSpectrumGenerator.h:140
SvmModelParameterSet mp_
set of model parameters read from model file
Definition: SvmTheoreticalSpectrumGenerator.h:229
IonType(Residue::ResidueType local_residue, EmpiricalFormula local_loss=EmpiricalFormula(), Int local_charge=1)
Definition: SvmTheoreticalSpectrumGenerator.h:96
std::vector< double > intensity_bin_boarders
Definition: SvmTheoreticalSpectrumGenerator.h:181
std::map< IonType, bool > hide_type_
whether ion types are hidden or not
Definition: SvmTheoreticalSpectrumGenerator.h:244
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Size number_intensity_levels
Definition: SvmTheoreticalSpectrumGenerator.h:163
String toString() const
returns the formula as a string (charges are not included)
Int charge
Definition: SvmTheoreticalSpectrumGenerator.h:83
IonType & operator=(const IonType &rhs)
Definition: SvmTheoreticalSpectrumGenerator.h:112
int Int
Signed integer type.
Definition: Types.h:96
bool operator<(const IonType &rhs) const
Definition: SvmTheoreticalSpectrumGenerator.h:123
std::vector< IonType > ion_types
Definition: SvmTheoreticalSpectrumGenerator.h:157
double scaling_lower
Definition: SvmTheoreticalSpectrumGenerator.h:175
std::map< std::pair< IonType, Size >, std::vector< std::vector< double > > > conditional_prob
Definition: SvmTheoreticalSpectrumGenerator.h:187

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Nov 1 2016 16:34:46 using doxygen 1.8.11