OpenMS  2.7.0
FeatureDistance.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-2021.
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: Hendrik Weisser $
32 // $Authors: Clemens Groepl, Hendrik Weisser, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 
40 #include <limits>
41 
42 namespace OpenMS
43 {
89  class OPENMS_DLLAPI FeatureDistance :
90  public DefaultParamHandler
91  {
92 public:
94  static const double infinity;
95 
102  FeatureDistance(double max_intensity = 1.0,
103  bool force_constraints = false);
104 
106  ~FeatureDistance() override;
107 
110 
118  std::pair<bool, double> operator()(const BaseFeature & left,
119  const BaseFeature & right);
120 
121 protected:
122 
125  {
127 
128  DistanceParams_(const String & what, const Param & global)
129  {
130  Param param = global.copy("distance_" + what + ":", true);
131  if (what == "MZ")
132  {
133  max_diff_ppm = (param.getValue("unit") == "ppm");
134  }
135  else
136  {
137  max_diff_ppm = false;
138  }
139 
140  max_difference = param.getValue("max_difference");
141  exponent = param.getValue("exponent");
142  weight = param.getValue("weight");
143  norm_factor = 1 / max_difference;
144 
145  relevant = (weight != 0.0) && (exponent != 0.0);
146  if (!relevant)
147  {
148  weight = 0.0;
149  }
150  }
151 
152  double max_difference, exponent, weight, norm_factor;
153  bool max_diff_ppm, relevant;
154  };
155 
157  void updateMembers_() override;
158 
160  inline double distance_(double diff, const DistanceParams_ & params) const;
161 
163  DistanceParams_ params_rt_, params_mz_, params_intensity_;
164 
167 
170 
173 
176 
179 
182  };
183 
184 } // namespace OpenMS
185 
A basic LC-MS feature.
Definition: BaseFeature.h:58
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
A functor class for the calculation of distances between features or consensus features.
Definition: FeatureDistance.h:91
~FeatureDistance() override
Destructor.
static const double infinity
Value to return if max. difference is exceeded or if charge states don't match.
Definition: FeatureDistance.h:94
bool ignore_adduct_
Compute a distance even if adducts don't match?
Definition: FeatureDistance.h:175
std::pair< bool, double > operator()(const BaseFeature &left, const BaseFeature &right)
Evaluation operator - checks constraints and computes the distance between two features.
FeatureDistance & operator=(const FeatureDistance &other)
Assignment operator.
bool force_constraints_
Always return infinity if "max. difference" constraints are not met?
Definition: FeatureDistance.h:178
DistanceParams_ params_intensity_
Definition: FeatureDistance.h:163
double max_intensity_
Maximum intensity of features (for normalization)
Definition: FeatureDistance.h:169
bool log_transform_
Log-transform intensities when computing intensity distance?
Definition: FeatureDistance.h:181
double distance_(double diff, const DistanceParams_ &params) const
Computes a distance component given absolute difference and parameters.
void updateMembers_() override
Docu in base class.
FeatureDistance(double max_intensity=1.0, bool force_constraints=false)
Constructor.
bool ignore_charge_
Compute a distance even if charge states don't match?
Definition: FeatureDistance.h:172
double total_weight_reciprocal_
Reciprocal value of the total weight in the distance function.
Definition: FeatureDistance.h:166
Management and storage of parameters / INI files.
Definition: Param.h:70
Param copy(const std::string &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
const ParamValue & getValue(const std::string &key) const
Returns a value of a parameter.
A more convenient string class.
Definition: String.h:61
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Structure for storing distance parameters.
Definition: FeatureDistance.h:125
DistanceParams_()
Definition: FeatureDistance.h:126
bool max_diff_ppm
Definition: FeatureDistance.h:153
DistanceParams_(const String &what, const Param &global)
Definition: FeatureDistance.h:128
double exponent
Definition: FeatureDistance.h:152