Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
00037 #define OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATOR_H
00038
00039 #include <OpenMS/config.h>
00040 #include <OpenMS/CHEMISTRY/TheoreticalSpectrumGenerator.h>
00041 #include <OpenMS/SIMULATION/SimTypes.h>
00042 #include <OpenMS/ANALYSIS/SVM/SVMWrapper.h>
00043 #include <boost/smart_ptr.hpp>
00044
00045
00046
00047
00048
00049 namespace OpenMS
00050 {
00069 class OPENMS_DLLAPI SvmTheoreticalSpectrumGenerator :
00070 public DefaultParamHandler
00071 {
00072 friend class SvmTheoreticalSpectrumGeneratorTrainer;
00073 public:
00074
00079
00080 struct IonType
00081 {
00082 Residue::ResidueType residue;
00083 EmpiricalFormula loss;
00084 Int charge;
00085
00088
00089 IonType() :
00090 residue((Residue::ResidueType) 0),
00091 loss(),
00092 charge(0)
00093 {
00094 }
00095
00096
00097 IonType(Residue::ResidueType residue, EmpiricalFormula loss = EmpiricalFormula(), Int charge = 1) :
00098 residue(residue),
00099 loss(loss),
00100 charge(charge)
00101 {
00102 }
00103
00104
00105 IonType(const IonType & rhs) :
00106 residue(rhs.residue),
00107 loss(rhs.loss),
00108 charge(rhs.charge)
00109 {
00110 }
00111
00112
00113 IonType & operator=(const IonType & rhs)
00114 {
00115 if (this != &rhs)
00116 {
00117 residue = rhs.residue;
00118 loss = rhs.loss;
00119 charge = rhs.charge;
00120 }
00121 return *this;
00122 }
00123
00124 bool operator<(const IonType & rhs) const
00125 {
00126 if (residue != rhs.residue)
00127 return residue < rhs.residue;
00128 else if (loss.getString() != rhs.loss.getString())
00129 return loss.getString() < rhs.loss.getString();
00130 else
00131 return charge < rhs.charge;
00132 }
00133
00134 };
00136
00138 struct DescriptorSet
00139 {
00140 typedef std::vector<svm_node> DescriptorSetType;
00141 DescriptorSetType descriptors;
00142 };
00143
00144
00146 struct SvmModelParameterSet
00147 {
00148
00149 std::vector<boost::shared_ptr<SVMWrapper> > class_models;
00150
00151
00152 std::vector<boost::shared_ptr<SVMWrapper> > reg_models;
00153
00154
00155 std::map<Residue::ResidueType, DoubleReal> static_intensities;
00156
00157
00158 std::vector<IonType> ion_types;
00159
00160
00161 std::map<IonType, std::vector<IonType> > secondary_types;
00162
00163
00164 Size number_intensity_levels;
00165
00166
00167 Size number_regions;
00168
00169
00170 std::vector<DoubleReal> feature_max;
00171
00172
00173 std::vector<DoubleReal> feature_min;
00174
00175
00176 double scaling_lower;
00177
00178
00179 double scaling_upper;
00180
00181
00182 std::vector<DoubleReal> intensity_bin_boarders;
00183
00184
00185 std::vector<DoubleReal> intensity_bin_values;
00186
00187
00188 std::map<std::pair<IonType, Size>, std::vector<std::vector<DoubleReal> > > conditional_prob;
00189 };
00190
00191
00192
00196
00197 SvmTheoreticalSpectrumGenerator();
00198
00200 SvmTheoreticalSpectrumGenerator(const SvmTheoreticalSpectrumGenerator & source);
00201
00203 SvmTheoreticalSpectrumGenerator & operator=(const SvmTheoreticalSpectrumGenerator & tsg);
00204
00205
00207 virtual ~SvmTheoreticalSpectrumGenerator();
00209
00210
00212 void simulate(RichPeakSpectrum & spectrum, const AASequence & peptide, const gsl_rng * rng, Size precursor_charge);
00213
00215 void load();
00216
00218 const std::vector<IonType> & getIonTypes()
00219 {
00220 return mp_.ion_types;
00221 }
00222
00223 protected:
00224 typedef std::map<IonType, DoubleReal> IntensityMap;
00225
00227 Size precursor_charge_;
00228
00230 SvmModelParameterSet mp_;
00231
00233 static std::map<String, Size> aa_to_index_;
00234
00236 static std::map<String, DoubleReal> hydrophobicity_;
00237
00239 static std::map<String, DoubleReal> helicity_;
00240
00242 static std::map<String, DoubleReal> basicity_;
00243
00245 std::map<IonType, bool> hide_type_;
00246
00248 inline void scaleSingleFeature_(double & value, double feature_min, double feature_max, double lower = -1.0, double upper = 1.0);
00249
00251 void scaleDescriptorSet_(DescriptorSet & desc, double lower, double upper);
00252
00254 Size generateDescriptorSet_(AASequence peptide, Size position, IonType type, Size precursor_charge, DescriptorSet & desc_set);
00255
00257 String ResidueTypeToString_(Residue::ResidueType type);
00258
00260 static void initializeMaps_();
00261
00263 static bool initializedMaps_;
00264
00265 void updateMembers_();
00266 };
00267
00268 void inline SvmTheoreticalSpectrumGenerator::scaleSingleFeature_(double & value, double lower, double upper, double feature_min, double feature_max)
00269 {
00270 double prev = value;
00271 if (feature_max == feature_min)
00272 {
00273 return;
00274 }
00275
00276 if (value <= feature_min)
00277 {
00278 value = lower;
00279 }
00280 else if (value >= feature_max)
00281 {
00282 value = upper;
00283 }
00284 else
00285 {
00286 value = lower + (upper - lower) *
00287 (value - feature_min) /
00288 (feature_max - feature_min);
00289 }
00290
00291 if (value < 0)
00292 {
00293 std::cerr << "negative value!! " << value << " l: " << lower << " u: " << upper << " fm: " << feature_min << " fma: " << feature_max << " prev: " << prev << std::endl;
00294 }
00295 }
00296
00297 }
00298
00299 #endif // #ifdef OPENMS_CHEMISTRY_SVMTHEORETICALSPECTRUMGENERATORTRAINER_H