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

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:21 using doxygen 1.8.5