OpenMS
FeatureGroupingAlgorithmKD.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Johannes Veit $
6 // $Authors: Johannes Veit $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
15 
16 namespace OpenMS
17 {
18 
20 
32 class OPENMS_DLLAPI ClusterProxyKD
33 {
34 
35 public:
36 
39  size_(0), // => isValid() returns false
40  avg_distance_(0),
41  center_index_(0)
42  {
43  }
44 
46  ClusterProxyKD(Size size, double avg_distance, Size center_index) :
47  size_(size),
48  avg_distance_(avg_distance),
49  center_index_(center_index)
50  {
51  }
52 
55  size_(rhs.size_),
56  avg_distance_(rhs.avg_distance_),
57  center_index_(rhs.center_index_)
58  {
59  }
60 
63  {
64  }
65 
68  {
69  size_ = rhs.size_;
70  avg_distance_ = rhs.avg_distance_;
71  center_index_ = rhs.center_index_;
72 
73  return *this;
74  }
75 
77  bool operator<(const ClusterProxyKD& rhs) const
78  {
79  if (size_ > rhs.size_) return true;
80  if (size_ < rhs.size_) return false;
81 
82  if (avg_distance_ < rhs.avg_distance_) return true;
83  if (avg_distance_ > rhs.avg_distance_) return false;
84 
85  // arbitrary, but required for finding unambiguous elements in std::set
86  if (center_index_ > rhs.center_index_) return true;
87  if (center_index_ < rhs.center_index_) return false;
88 
89  // they are equal
90  return false;
91  }
92 
94  bool operator!=(const ClusterProxyKD& rhs) const
95  {
96  return *this < rhs || rhs < *this;
97  }
98 
100  bool operator==(const ClusterProxyKD& rhs) const
101  {
102  return !(*this != rhs);
103  }
104 
106  Size getSize() const
107  {
108  return size_;
109  }
110 
112  bool isValid() const
113  {
114  return size_;
115  }
116 
118  double getAvgDistance() const
119  {
120  return avg_distance_;
121  }
122 
125  {
126  return center_index_;
127  }
128 
129 private:
130 
133 
136 
139 };
140 
141 
152  class OPENMS_DLLAPI FeatureGroupingAlgorithmKD :
154  public ProgressLogger
155  {
156 
157 public:
158 
161 
164 
170  void group(const std::vector<FeatureMap>& maps, ConsensusMap& out) override;
171 
177  void group(const std::vector<ConsensusMap>& maps,
178  ConsensusMap& out) override;
179 
180 private:
181 
184 
187 
193  template <typename MapType>
194  void group_(const std::vector<MapType>& input_maps, ConsensusMap& out);
195 
197  void runClustering_(const KDTreeFeatureMaps& kd_data, ConsensusMap& out);
198 
200  void updateClusterProxies_(std::set<ClusterProxyKD>& potential_clusters, std::vector<ClusterProxyKD>& cluster_for_idx, const std::set<Size>& update_these, const std::vector<Int>& assigned, const KDTreeFeatureMaps& kd_data);
201 
203  ClusterProxyKD computeBestClusterForCenter_(Size i, std::vector<Size>& cf_indices, const std::vector<Int>& assigned, const KDTreeFeatureMaps& kd_data) const;
204 
206  void addConsensusFeature_(const std::vector<Size>& indices, const KDTreeFeatureMaps& kd_data, ConsensusMap& out) const;
207 
210 
212  double rt_tol_secs_;
213 
215  double mz_tol_;
216 
218  bool mz_ppm_;
219 
222  };
223 
224 } // namespace OpenMS
225 
Proxy for a (potential) cluster.
Definition: FeatureGroupingAlgorithmKD.h:33
double avg_distance_
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:135
~ClusterProxyKD()
Destructor (non-virtual to save memory)
Definition: FeatureGroupingAlgorithmKD.h:62
Size getSize() const
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:106
Size getCenterIndex() const
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:124
bool isValid() const
Valid?
Definition: FeatureGroupingAlgorithmKD.h:112
double getAvgDistance() const
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:118
ClusterProxyKD(const ClusterProxyKD &rhs)
Copy constructor.
Definition: FeatureGroupingAlgorithmKD.h:54
bool operator!=(const ClusterProxyKD &rhs) const
Inequality operator.
Definition: FeatureGroupingAlgorithmKD.h:94
bool operator==(const ClusterProxyKD &rhs) const
Equality operator.
Definition: FeatureGroupingAlgorithmKD.h:100
ClusterProxyKD()
Default constructor.
Definition: FeatureGroupingAlgorithmKD.h:38
ClusterProxyKD & operator=(const ClusterProxyKD &rhs)
Assignment operator.
Definition: FeatureGroupingAlgorithmKD.h:67
Size size_
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:132
ClusterProxyKD(Size size, double avg_distance, Size center_index)
Constructor.
Definition: FeatureGroupingAlgorithmKD.h:46
bool operator<(const ClusterProxyKD &rhs) const
Less-than operator for sorting / equality check in std::set. We use the ordering in std::set as a "pr...
Definition: FeatureGroupingAlgorithmKD.h:77
Size center_index_
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:138
A container for consensus elements.
Definition: ConsensusMap.h:66
A functor class for the calculation of distances between features or consensus features.
Definition: FeatureDistance.h:65
A feature grouping algorithm for unlabeled data.
Definition: FeatureGroupingAlgorithmKD.h:155
double mz_tol_
m/z tolerance
Definition: FeatureGroupingAlgorithmKD.h:215
ClusterProxyKD computeBestClusterForCenter_(Size i, std::vector< Size > &cf_indices, const std::vector< Int > &assigned, const KDTreeFeatureMaps &kd_data) const
Compute the current best cluster with center index i (mutates proxy and cf_indices)
FeatureGroupingAlgorithmKD(const FeatureGroupingAlgorithmKD &)
Copy constructor intentionally not implemented -> private.
FeatureGroupingAlgorithmKD()
Default constructor.
void runClustering_(const KDTreeFeatureMaps &kd_data, ConsensusMap &out)
Run the actual clustering algorithm.
double rt_tol_secs_
RT tolerance.
Definition: FeatureGroupingAlgorithmKD.h:212
~FeatureGroupingAlgorithmKD() override
Destructor.
bool mz_ppm_
m/z unit ppm?
Definition: FeatureGroupingAlgorithmKD.h:218
FeatureDistance feature_distance_
Feature distance functor.
Definition: FeatureGroupingAlgorithmKD.h:221
FeatureGroupingAlgorithmKD & operator=(const FeatureGroupingAlgorithmKD &)
Assignment operator intentionally not implemented -> private.
void group(const std::vector< ConsensusMap > &maps, ConsensusMap &out) override
Applies the algorithm to consensus maps.
void group_(const std::vector< MapType > &input_maps, ConsensusMap &out)
Applies the algorithm to feature or consensus maps.
void updateClusterProxies_(std::set< ClusterProxyKD > &potential_clusters, std::vector< ClusterProxyKD > &cluster_for_idx, const std::set< Size > &update_these, const std::vector< Int > &assigned, const KDTreeFeatureMaps &kd_data)
Update maximum possible sizes of potential consensus features for indices specified in update_these.
SignedSize progress_
Current progress for logging.
Definition: FeatureGroupingAlgorithmKD.h:209
void group(const std::vector< FeatureMap > &maps, ConsensusMap &out) override
Applies the algorithm to feature maps.
void addConsensusFeature_(const std::vector< Size > &indices, const KDTreeFeatureMaps &kd_data, ConsensusMap &out) const
Construct consensus feature and add to out map.
Base class for all feature grouping algorithms.
Definition: FeatureGroupingAlgorithm.h:25
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:24
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19