Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MZTrafoModel.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: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 
36 #ifndef OPENMS_FILTERING_CALIBRATION_MZTRAFOMODEL_H
37 #define OPENMS_FILTERING_CALIBRATION_MZTRAFOMODEL_H
38 
42 
43 #include <vector>
44 
45 namespace OpenMS
46 {
47 
67  class OPENMS_DLLAPI MZTrafoModel
68  {
69 
70  private:
71  std::vector<double> coeff_; //< Model coefficients (for both linear and quadratic models), estimated from the data
72  bool use_ppm_; //< during training, model is build on absolute or relative(ppm) predictions. predict(), i.e. applying the model, requires this information too
73  double rt_; //< retention time associated to the model (i.e. where the calibrant data was taken from)
74 
75  static Math::RANSACParam* ransac_params_; //< global pointer, init to NULL at startup; set class-global RANSAC params
76  static double limit_offset_; //< acceptable boundary for the estimated offset; if estimated offset is larger (absolute) the model does not validate (isValidModel())
77  static double limit_scale_; //< acceptable boundary for the estimated scale; if estimated scale is larger (absolute) the model does not validate (isValidModel())
78  static double limit_power_; //< acceptable boundary for the estimated power; if estimated power is larger (absolute) the model does not validate (isValidModel())
79 
80  public:
81 
85  MZTrafoModel();
86 
97  MZTrafoModel(bool ppm_model);
98 
99  enum MODELTYPE { LINEAR, LINEAR_WEIGHTED, QUADRATIC, QUADRATIC_WEIGHTED, SIZE_OF_MODELTYPE };
100  static const std::string names_of_modeltype[]; //< strings corresponding to enum MODELTYPE
108  static MODELTYPE nameToEnum(const std::string& name);
115  static const std::string& enumToName(MODELTYPE mt);
116 
117 
127  static void setRANSACParams(const Math::RANSACParam& p);
128 
137  static void setCoefficientLimits(double offset, double scale, double power);
148  static bool isValidModel(const MZTrafoModel& trafo);
149 
156  bool isTrained() const;
157 
161  double getRT() const;
162 
175  double predict(double mz) const;
176 
188  static Size findNearest(const std::vector<MZTrafoModel>& tms, double rt);
189 
190 
192  struct RTLess :
193  public std::binary_function<MZTrafoModel, MZTrafoModel, bool>
194  {
195  inline bool operator()(const double& left, const MZTrafoModel& right) const
196  {
197  return left < right.rt_;
198  }
199  inline bool operator()(const MZTrafoModel& left, const double& right) const
200  {
201  return left.rt_ < right;
202  }
203  inline bool operator()(const MZTrafoModel& left, const MZTrafoModel& right) const
204  {
205  return left.rt_ < right.rt_;
206  }
207  };
229  bool train(const CalibrationData& cd, MODELTYPE md, bool use_RANSAC,
230  double rt_left = -std::numeric_limits<double>::max(),
231  double rt_right = std::numeric_limits<double>::max()
232  );
233 
258  bool train(std::vector<double> error_mz,
259  std::vector<double> theo_mz,
260  std::vector<double> weights,
261  MODELTYPE md,
262  bool use_RANSAC);
263 
275  void getCoefficients(double& intercept, double& slope, double& power);
276 
280  void setCoefficients(const MZTrafoModel& rhs);
281 
293  void setCoefficients(double intercept, double slope, double power);
294 
301  String toString() const;
302 
303  }; // MZTrafoModel
304 
305 } // namespace OpenMS
306 
307 #endif // OPENMS_FILTERING_CALIBRATION_MZTRAFOMODEL_H
static double limit_offset_
Definition: MZTrafoModel.h:76
static double limit_scale_
Definition: MZTrafoModel.h:77
A more convenient string class.
Definition: String.h:57
Comparator by position. As this class has dimension 1, this is basically an alias for MZLess...
Definition: MZTrafoModel.h:192
MODELTYPE
Definition: MZTrafoModel.h:99
std::vector< double > coeff_
Definition: MZTrafoModel.h:71
static double limit_power_
Definition: MZTrafoModel.h:78
A simple struct to carry all the parameters required for a RANSAC run.
Definition: RANSAC.h:59
Create and apply models of a mass recalibration function.
Definition: MZTrafoModel.h:67
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool use_ppm_
Definition: MZTrafoModel.h:72
bool operator()(const MZTrafoModel &left, const double &right) const
Definition: MZTrafoModel.h:199
double rt_
Definition: MZTrafoModel.h:73
A helper class, holding all calibration points.
Definition: CalibrationData.h:65
bool operator()(const MZTrafoModel &left, const MZTrafoModel &right) const
Definition: MZTrafoModel.h:203
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
bool operator()(const double &left, const MZTrafoModel &right) const
Definition: MZTrafoModel.h:195
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:69
static Math::RANSACParam * ransac_params_
Definition: MZTrafoModel.h:75

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