| OpenMS 2.5.0

FeatureGroupingAlgorithmKD.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: Johannes Veit $
32 // $Authors: Johannes Veit $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/ANALYSIS/MAPMATCHING/FeatureGroupingAlgorithm.h>
38 #include <OpenMS/ANALYSIS/QUANTITATION/KDTreeFeatureMaps.h>
39 #include <OpenMS/ANALYSIS/MAPMATCHING/FeatureDistance.h>
40 #include <OpenMS/CONCEPT/ProgressLogger.h>
41
42 namespace OpenMS
43 {
44
46
58 class OPENMS_DLLAPI ClusterProxyKD
59 {
60
61 public:
62
64 ClusterProxyKD() :
65 size_(0), // => isValid() returns false
66 avg_distance_(0),
67 center_index_(0)
68 {
69 }
70
72 ClusterProxyKD(Size size, double avg_distance, Size center_index) :
73 size_(size),
74 avg_distance_(avg_distance),
75 center_index_(center_index)
76 {
77 }
78
80 ClusterProxyKD(const ClusterProxyKD& rhs) :
81 size_(rhs.size_),
82 avg_distance_(rhs.avg_distance_),
83 center_index_(rhs.center_index_)
84 {
85 }
86
88 ~ClusterProxyKD()
89 {
90 }
91
93 ClusterProxyKD& operator=(const ClusterProxyKD& rhs)
94 {
95 size_ = rhs.size_;
96 avg_distance_ = rhs.avg_distance_;
97 center_index_ = rhs.center_index_;
98
99 return *this;
100 }
101
103 bool operator<(const ClusterProxyKD& rhs) const
104 {
105 if (size_ > rhs.size_) return true;
106 if (size_ < rhs.size_) return false;
107
108 if (avg_distance_ < rhs.avg_distance_) return true;
109 if (avg_distance_ > rhs.avg_distance_) return false;
110
111 // arbitrary, but required for finding unambiguous elements in std::set
112 if (center_index_ > rhs.center_index_) return true;
113 if (center_index_ < rhs.center_index_) return false;
114
115 // they are equal
116 return false;
117 }
118
120 bool operator!=(const ClusterProxyKD& rhs) const
121 {
122 return *this < rhs || rhs < *this;
123 }
124
126 bool operator==(const ClusterProxyKD& rhs) const
127 {
128 return !(*this != rhs);
129 }
130
132 Size getSize() const
133 {
134 return size_;
135 }
136
138 bool isValid() const
139 {
140 return size_;
141 }
142
144 double getAvgDistance() const
145 {
146 return avg_distance_;
147 }
148
150 Size getCenterIndex() const
151 {
152 return center_index_;
153 }
154
155 private:
156
158 Size size_;
159
161 double avg_distance_;
162
164 Size center_index_;
165 };
166
167
178 class OPENMS_DLLAPI FeatureGroupingAlgorithmKD :
179 public FeatureGroupingAlgorithm,
180 public ProgressLogger
181 {
182
183 public:
184
186 FeatureGroupingAlgorithmKD();
187
189 ~FeatureGroupingAlgorithmKD() override;
190
196 void group(const std::vector<FeatureMap>& maps, ConsensusMap& out) override;
197
203 void group(const std::vector<ConsensusMap>& maps,
204 ConsensusMap& out) override;
205
207 static FeatureGroupingAlgorithm* create()
208 {
209 return new FeatureGroupingAlgorithmKD();
210 }
211
213 static String getProductName()
214 {
215 return "unlabeled_kd";
216 }
217
218 private:
219
221 FeatureGroupingAlgorithmKD(const FeatureGroupingAlgorithmKD&);
222
224 FeatureGroupingAlgorithmKD& operator=(const FeatureGroupingAlgorithmKD&);
225
231 template <typename MapType>
232 void group_(const std::vector<MapType>& input_maps, ConsensusMap& out);
233
235 void runClustering_(const KDTreeFeatureMaps& kd_data, ConsensusMap& out);
236
238 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);
239
241 ClusterProxyKD computeBestClusterForCenter_(Size i, std::vector<Size>& cf_indices, const std::vector<Int>& assigned, const KDTreeFeatureMaps& kd_data) const;
242
244 void addConsensusFeature_(const std::vector<Size>& indices, const KDTreeFeatureMaps& kd_data, ConsensusMap& out) const;
245
247 SignedSize progress_;
248
250 double rt_tol_secs_;
251
253 double mz_tol_;
254
256 bool mz_ppm_;
257
259 FeatureDistance feature_distance_;
260 };
261
262 } // namespace OpenMS
263
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::FeatureDistance
A functor class for the calculation of distances between features or consensus features.
Definition: FeatureDistance.h:89
OpenMS::FeatureGroupingAlgorithmKD::create
static FeatureGroupingAlgorithm * create()
Creates a new instance of this class (for Factory)
Definition: FeatureGroupingAlgorithmKD.h:207
OpenMS::ClusterProxyKD::ClusterProxyKD
ClusterProxyKD(Size size, double avg_distance, Size center_index)
Constructor.
Definition: FeatureGroupingAlgorithmKD.h:72
OpenMS::ClusterProxyKD::size_
Size size_
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:158
OpenMS::KDTreeFeatureMaps
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:49
OpenMS::ClusterProxyKD::~ClusterProxyKD
~ClusterProxyKD()
Destructor (non-virtual to save memory)
Definition: FeatureGroupingAlgorithmKD.h:88
OpenMS::FeatureGroupingAlgorithm
Base class for all feature grouping algorithms.
Definition: FeatureGroupingAlgorithm.h:49
OpenMS::ClusterProxyKD::getCenterIndex
Size getCenterIndex() const
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:150
OpenMS::ClusterProxyKD::avg_distance_
double avg_distance_
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:161
OpenMS::ClusterProxyKD::ClusterProxyKD
ClusterProxyKD(const ClusterProxyKD &rhs)
Copy constructor.
Definition: FeatureGroupingAlgorithmKD.h:80
OpenMS::FeatureGroupingAlgorithmKD::mz_tol_
double mz_tol_
m/z tolerance
Definition: FeatureGroupingAlgorithmKD.h:253
FeatureDistance.h
OpenMS::FeatureGroupingAlgorithmKD
A feature grouping algorithm for unlabeled data.
Definition: FeatureGroupingAlgorithmKD.h:178
OpenMS::ClusterProxyKD::isValid
bool isValid() const
Valid?
Definition: FeatureGroupingAlgorithmKD.h:138
ProgressLogger.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::FeatureGroupingAlgorithmKD::feature_distance_
FeatureDistance feature_distance_
Feature distance functor.
Definition: FeatureGroupingAlgorithmKD.h:259
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::ClusterProxyKD::operator=
ClusterProxyKD & operator=(const ClusterProxyKD &rhs)
Assignment operator.
Definition: FeatureGroupingAlgorithmKD.h:93
OpenMS::ClusterProxyKD::getSize
Size getSize() const
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:132
OpenMS::ClusterProxyKD
Proxy for a (potential) cluster.
Definition: FeatureGroupingAlgorithmKD.h:58
OpenMS::ClusterProxyKD::ClusterProxyKD
ClusterProxyKD()
Default constructor.
Definition: FeatureGroupingAlgorithmKD.h:64
OpenMS::FeatureGroupingAlgorithmKD::mz_ppm_
bool mz_ppm_
m/z unit ppm?
Definition: FeatureGroupingAlgorithmKD.h:256
OpenMS::ClusterProxyKD::center_index_
Size center_index_
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:164
FeatureGroupingAlgorithm.h
OpenMS::FeatureGroupingAlgorithmKD::rt_tol_secs_
double rt_tol_secs_
RT tolerance.
Definition: FeatureGroupingAlgorithmKD.h:250
OpenMS::ConsensusMap
A container for consensus elements.
Definition: ConsensusMap.h:79
OpenMS::FeatureGroupingAlgorithmKD::getProductName
static String getProductName()
Returns the product name (for the Factory)
Definition: FeatureGroupingAlgorithmKD.h:213
OpenMS::ClusterProxyKD::getAvgDistance
double getAvgDistance() const
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:144
OpenMS::ClusterProxyKD::operator<
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:103
OpenMS::ClusterProxyKD::operator!=
bool operator!=(const ClusterProxyKD &rhs) const
Inequality operator.
Definition: FeatureGroupingAlgorithmKD.h:120
OpenMS::FeatureGroupingAlgorithmKD::progress_
SignedSize progress_
Current progress for logging.
Definition: FeatureGroupingAlgorithmKD.h:247
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::ClusterProxyKD::operator==
bool operator==(const ClusterProxyKD &rhs) const
Equality operator.
Definition: FeatureGroupingAlgorithmKD.h:126
KDTreeFeatureMaps.h