Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-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: Johannes Veit $
32 // $Authors: Johannes Veit $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_ANALYSIS_MAPMATCHING_FEATUREGROUPINGALGORITHMKD_H
36 #define OPENMS_ANALYSIS_MAPMATCHING_FEATUREGROUPINGALGORITHMKD_H
37 
42 
43 namespace OpenMS
44 {
45 
47 
59 class OPENMS_DLLAPI ClusterProxyKD
60 {
61 
62 public:
63 
66  size_(0), // => isValid() returns false
67  avg_distance_(0),
68  center_index_(0)
69  {
70  }
71 
73  ClusterProxyKD(Size size, double avg_distance, Size center_index) :
74  size_(size),
75  avg_distance_(avg_distance),
76  center_index_(center_index)
77  {
78  }
79 
82  size_(rhs.size_),
83  avg_distance_(rhs.avg_distance_),
84  center_index_(rhs.center_index_)
85  {
86  }
87 
90  {
91  }
92 
95  {
96  size_ = rhs.size_;
97  avg_distance_ = rhs.avg_distance_;
98  center_index_ = rhs.center_index_;
99 
100  return *this;
101  }
102 
104  bool operator<(const ClusterProxyKD& rhs) const
105  {
106  if (size_ > rhs.size_) return true;
107  if (size_ < rhs.size_) return false;
108 
109  if (avg_distance_ < rhs.avg_distance_) return true;
110  if (avg_distance_ > rhs.avg_distance_) return false;
111 
112  // arbitrary, but required for finding unambiguous elements in std::set
113  if (center_index_ > rhs.center_index_) return true;
114  if (center_index_ < rhs.center_index_) return false;
115 
116  // they are equal
117  return false;
118  }
119 
121  bool operator!=(const ClusterProxyKD& rhs) const
122  {
123  return *this < rhs || rhs < *this;
124  }
125 
127  bool operator==(const ClusterProxyKD& rhs) const
128  {
129  return !(*this != rhs);
130  }
131 
133  Size getSize() const
134  {
135  return size_;
136  }
137 
139  bool isValid() const
140  {
141  return size_;
142  }
143 
145  double getAvgDistance() const
146  {
147  return avg_distance_;
148  }
149 
152  {
153  return center_index_;
154  }
155 
156 private:
157 
160 
163 
166 };
167 
168 
179  class OPENMS_DLLAPI FeatureGroupingAlgorithmKD :
181  public ProgressLogger
182  {
183 
184 public:
185 
188 
190  virtual ~FeatureGroupingAlgorithmKD();
191 
197  virtual void group(const std::vector<FeatureMap>& maps, ConsensusMap& out);
198 
204  virtual void group(const std::vector<ConsensusMap>& maps,
205  ConsensusMap& out);
206 
209  {
210  return new FeatureGroupingAlgorithmKD();
211  }
212 
215  {
216  return "unlabeled_kd";
217  }
218 
219 private:
220 
223 
226 
232  template <typename MapType>
233  void group_(const std::vector<MapType>& input_maps, ConsensusMap& out);
234 
236  void runClustering_(const KDTreeFeatureMaps& kd_data, ConsensusMap& out);
237 
239  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);
240 
242  ClusterProxyKD computeBestClusterForCenter_(Size i, std::vector<Size>& cf_indices, const std::vector<Int>& assigned, const KDTreeFeatureMaps& kd_data) const;
243 
245  void addConsensusFeature_(const std::vector<Size>& indices, const KDTreeFeatureMaps& kd_data, ConsensusMap& out) const;
246 
249 
251  double rt_tol_secs_;
252 
254  double mz_tol_;
255 
257  bool mz_ppm_;
258 
261  };
262 
263 } // namespace OpenMS
264 
265 #endif // OPENMS_ANALYSIS_MAPMATCHING_FEATUREGROUPINGALGORITHMKD_H
A functor class for the calculation of distances between features or consensus features.
Definition: FeatureDistance.h:90
A more convenient string class.
Definition: String.h:57
double avg_distance_
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:162
Size center_index_
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:165
ClusterProxyKD(Size size, double avg_distance, Size center_index)
Constructor.
Definition: FeatureGroupingAlgorithmKD.h:73
ClusterProxyKD & operator=(const ClusterProxyKD &rhs)
Assignment operator.
Definition: FeatureGroupingAlgorithmKD.h:94
static FeatureGroupingAlgorithm * create()
Creates a new instance of this class (for Factory)
Definition: FeatureGroupingAlgorithmKD.h:208
FeatureDistance feature_distance_
Feature distance functor.
Definition: FeatureGroupingAlgorithmKD.h:260
static String getProductName()
Returns the product name (for the Factory)
Definition: FeatureGroupingAlgorithmKD.h:214
double mz_tol_
m/z tolerance
Definition: FeatureGroupingAlgorithmKD.h:254
Stores a set of features, together with a 2D tree for fast search.
Definition: KDTreeFeatureMaps.h:50
bool isValid() const
Valid?
Definition: FeatureGroupingAlgorithmKD.h:139
A container for consensus elements.
Definition: ConsensusMap.h:72
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
Proxy for a (potential) cluster.
Definition: FeatureGroupingAlgorithmKD.h:59
bool mz_ppm_
m/z unit ppm?
Definition: FeatureGroupingAlgorithmKD.h:257
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
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:104
Size size_
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:159
SignedSize progress_
Current progress for logging.
Definition: FeatureGroupingAlgorithmKD.h:248
Base class for all feature grouping algorithms.
Definition: FeatureGroupingAlgorithm.h:50
~ClusterProxyKD()
Destructor (non-virtual to save memory)
Definition: FeatureGroupingAlgorithmKD.h:89
bool operator==(const ClusterProxyKD &rhs) const
Equality operator.
Definition: FeatureGroupingAlgorithmKD.h:127
ClusterProxyKD()
Default constructor.
Definition: FeatureGroupingAlgorithmKD.h:65
double rt_tol_secs_
RT tolerance.
Definition: FeatureGroupingAlgorithmKD.h:251
Size getSize() const
Cluster size.
Definition: FeatureGroupingAlgorithmKD.h:133
A feature grouping algorithm for unlabeled data.
Definition: FeatureGroupingAlgorithmKD.h:179
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
double getAvgDistance() const
Average distance to center.
Definition: FeatureGroupingAlgorithmKD.h:145
ClusterProxyKD(const ClusterProxyKD &rhs)
Copy constructor.
Definition: FeatureGroupingAlgorithmKD.h:81
Size getCenterIndex() const
Index of center point.
Definition: FeatureGroupingAlgorithmKD.h:151
bool operator!=(const ClusterProxyKD &rhs) const
Inequality operator.
Definition: FeatureGroupingAlgorithmKD.h:121

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