| OpenMS 2.5.0

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-2020.
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 #pragma once
37
38 #include <OpenMS/CONCEPT/LogStream.h>
39 #include <OpenMS/DATASTRUCTURES/CalibrationData.h>
40 #include <OpenMS/MATH/MISC/RANSAC.h>
41
42 #include <vector>
43
44 namespace OpenMS
45 {
46
66 class OPENMS_DLLAPI MZTrafoModel
67 {
68
69 private:
70 std::vector<double> coeff_;
71 bool use_ppm_;
72 double rt_;
73
74 static Math::RANSACParam* ransac_params_;
75 static double limit_offset_;
76 static double limit_scale_;
77 static double limit_power_;
78
79 public:
80
84 MZTrafoModel();
85
96 MZTrafoModel(bool ppm_model);
97
98 enum MODELTYPE { LINEAR, LINEAR_WEIGHTED, QUADRATIC, QUADRATIC_WEIGHTED, SIZE_OF_MODELTYPE };
99 static const std::string names_of_modeltype[];
100
107 static MODELTYPE nameToEnum(const std::string& name);
114 static const std::string& enumToName(MODELTYPE mt);
115
116
126 static void setRANSACParams(const Math::RANSACParam& p);
127
136 static void setCoefficientLimits(double offset, double scale, double power);
147 static bool isValidModel(const MZTrafoModel& trafo);
148
155 bool isTrained() const;
156
160 double getRT() const;
161
174 double predict(double mz) const;
175
187 static Size findNearest(const std::vector<MZTrafoModel>& tms, double rt);
188
189
191 struct RTLess :
192 public std::binary_function<MZTrafoModel, MZTrafoModel, bool>
193 {
194 inline bool operator()(const double& left, const MZTrafoModel& right) const
195 {
196 return left < right.rt_;
197 }
198 inline bool operator()(const MZTrafoModel& left, const double& right) const
199 {
200 return left.rt_ < right;
201 }
202 inline bool operator()(const MZTrafoModel& left, const MZTrafoModel& right) const
203 {
204 return left.rt_ < right.rt_;
205 }
206 };
228 bool train(const CalibrationData& cd, MODELTYPE md, bool use_RANSAC,
229 double rt_left = -std::numeric_limits<double>::max(),
230 double rt_right = std::numeric_limits<double>::max()
231 );
232
257 bool train(std::vector<double> error_mz,
258 std::vector<double> theo_mz,
259 std::vector<double> weights,
260 MODELTYPE md,
261 bool use_RANSAC);
262
274 void getCoefficients(double& intercept, double& slope, double& power);
275
279 void setCoefficients(const MZTrafoModel& rhs);
280
292 void setCoefficients(double intercept, double slope, double power);
293
300 String toString() const;
301
302 }; // MZTrafoModel
303
304 } // namespace OpenMS
305
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MZTrafoModel::limit_offset_
static double limit_offset_
acceptable boundary for the estimated offset; if estimated offset is larger (absolute) the model does...
Definition: MZTrafoModel.h:75
OpenMS::MZTrafoModel::limit_power_
static double limit_power_
acceptable boundary for the estimated power; if estimated power is larger (absolute) the model does n...
Definition: MZTrafoModel.h:77
OpenMS::MZTrafoModel::RTLess::operator()
bool operator()(const MZTrafoModel &left, const double &right) const
Definition: MZTrafoModel.h:198
CalibrationData.h
OpenMS::StringConversions::toString
String toString(const T &i)
fallback template for general purpose using Boost::Karma; more specializations below ...
Definition: StringUtils.h:85
OpenMS::MZTrafoModel::MODELTYPE
MODELTYPE
Definition: MZTrafoModel.h:98
OpenMS::MZTrafoModel::rt_
double rt_
retention time associated to the model (i.e. where the calibrant data was taken from) ...
Definition: MZTrafoModel.h:72
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
LogStream.h
OpenMS::MZTrafoModel::coeff_
std::vector< double > coeff_
Model coefficients (for both linear and quadratic models), estimated from the data.
Definition: MZTrafoModel.h:70
OpenMS::MZTrafoModel::RTLess
Comparator by position. As this class has dimension 1, this is basically an alias for MZLess...
Definition: MZTrafoModel.h:191
OpenMS::MZTrafoModel::ransac_params_
static Math::RANSACParam * ransac_params_
global pointer, init to NULL at startup; set class-global RANSAC params
Definition: MZTrafoModel.h:74
OpenMS::CalibrationData
A helper class, holding all calibration points.
Definition: CalibrationData.h:64
OpenMS::MZTrafoModel::RTLess::operator()
bool operator()(const double &left, const MZTrafoModel &right) const
Definition: MZTrafoModel.h:194
OpenMS::MZTrafoModel
Create and apply models of a mass recalibration function.
Definition: MZTrafoModel.h:66
OpenMS::MZTrafoModel::RTLess::operator()
bool operator()(const MZTrafoModel &left, const MZTrafoModel &right) const
Definition: MZTrafoModel.h:202
OpenMS::Math::RANSACParam
A simple struct to carry all the parameters required for a RANSAC run.
Definition: RANSAC.h:58
OpenMS::MZTrafoModel::use_ppm_
bool use_ppm_
during training, model is build on absolute or relative(ppm) predictions. predict(), i.e. applying the model, requires this information too
Definition: MZTrafoModel.h:71
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::MZTrafoModel::limit_scale_
static double limit_scale_
acceptable boundary for the estimated scale; if estimated scale is larger (absolute) the model does n...
Definition: MZTrafoModel.h:76
RANSAC.h