OpenMS
Loading...
Searching...
No Matches
QTClusterFinder.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: Hendrik Weisser $
6// $Authors: Steffen Sass, Hendrik Weisser $
7// --------------------------------------------------------------------------
8
9#pragma once
10
16
17#include <unordered_map>
18
19#include <list>
20#include <vector>
21#include <unordered_set>
22#include <utility> // for pair<>
23
24namespace OpenMS
25{
26
76 class OPENMS_DLLAPI QTClusterFinder :
77 public BaseGroupFinder
78 {
79 public:
80
82 typedef std::unordered_map<
83 std::pair<OpenMS::GridFeature*, OpenMS::GridFeature*>,
85
87 typedef std::unordered_map<
88 const OpenMS::GridFeature*, std::unordered_set<Size> > ElementMapping;
89
91 struct Heap;
92
94 struct HeapHandles;
95
97 struct Grid;
98
99 private:
102
105
106 //TODO we could also bin by equal sized RT bins, or by a fixed RT size
107 //TODO could be made dependent on nr. of maps (e.g. with 5 maps you get [around] 4 diffs per ID already)
110
113
118
121
124
127
130
132 std::unordered_set<const OpenMS::GridFeature*> already_used_;
133
136 std::map<double, double> bin_tolerances_;
137
141 double getDistance_(const OpenMS::GridFeature* left, const
142 OpenMS::GridFeature* right);
143
145 void setParameters_(double max_intensity, double max_mz);
146
158 bool makeConsensusFeature_(Heap& cluster_heads,
159 ConsensusFeature& feature,
160 ElementMapping& element_mapping,
161 const Grid& grid,
162 const HeapHandles& handles);
163
173 void computeClustering_(const Grid& grid,
174 Heap& cluster_heads,
175 std::vector<QTCluster::BulkData>& cluster_data,
176 HeapHandles& handles,
177 ElementMapping& element_mapping);
178
186 ElementMapping& element_mapping);
187
197 void createConsensusFeature_(ConsensusFeature& feature, const double quality,
198 const QTCluster::Elements& elements);
199
218 void updateClustering_(ElementMapping& element_mapping,
219 const Grid& grid,
220 const QTCluster::Elements& elements,
221 Heap& cluster_heads,
222 const HeapHandles& handles,
223 Size best_id);
224
226 template <typename MapType>
227 void run_(const std::vector<MapType>& input_maps, ConsensusMap& result_map);
228
230 template <typename MapType>
231 void run_internal_(const std::vector<MapType>& input_maps,
232 ConsensusMap& result_map, bool do_progress);
233
240 void addClusterElements_(const Grid& grid, QTCluster& cluster);
241
245 bool distIsOutlier_(double dist, double rt);
246
247protected:
248
249 enum
250 {
251 RT = Peak2D::RT,
252 MZ = Peak2D::MZ
253 };
254
255public:
256
259
262
270 void run(const std::vector<ConsensusMap>& input_maps,
271 ConsensusMap& result_map) override;
272
280 void run(const std::vector<FeatureMap>& input_maps,
281 ConsensusMap& result_map);
282
283 };
284} // namespace OpenMS
285
The base class of all element group finding algorithms.
Definition BaseGroupFinder.h:38
A consensus feature spanning multiple LC-MS/MS experiments.
Definition ConsensusFeature.h:45
A container for consensus elements.
Definition ConsensusMap.h:67
A functor class for the calculation of distances between features or consensus features.
Definition FeatureDistance.h:65
Representation of a feature in a hash grid.
Definition GridFeature.h:27
A variant of QT clustering for the detection of feature groups.
Definition QTClusterFinder.h:78
std::unordered_map< std::pair< OpenMS::GridFeature *, OpenMS::GridFeature * >, double > PairDistances
Distances between pairs of grid features.
Definition QTClusterFinder.h:84
void run_internal_(const std::vector< MapType > &input_maps, ConsensusMap &result_map, bool do_progress)
Runs the algorithm on feature maps or consensus maps (internal)
double max_diff_mz_
Maximum m/z difference.
Definition QTClusterFinder.h:123
~QTClusterFinder() override
Destructor.
void createConsensusFeature_(ConsensusFeature &feature, const double quality, const QTCluster::Elements &elements)
creates a consensus feature from the given elements
int nr_partitions_
Maximum m/z difference.
Definition QTClusterFinder.h:126
void computeClustering_(const Grid &grid, Heap &cluster_heads, std::vector< QTCluster::BulkData > &cluster_data, HeapHandles &handles, ElementMapping &element_mapping)
Computes an initial QT clustering of the points in the hash grid.
void run(const std::vector< FeatureMap > &input_maps, ConsensusMap &result_map)
Runs the algorithm on feature maps.
double getDistance_(const OpenMS::GridFeature *left, const OpenMS::GridFeature *right)
Calculates the distance between two grid features.
std::map< double, double > bin_tolerances_
Definition QTClusterFinder.h:136
Size min_nr_diffs_per_bin_
Min. nr. of differences from matched IDs requested to calculate a linking tolerance per RT bin.
Definition QTClusterFinder.h:109
bool makeConsensusFeature_(Heap &cluster_heads, ConsensusFeature &feature, ElementMapping &element_mapping, const Grid &grid, const HeapHandles &handles)
Extract the best cluster from cluster_heads and turn it into a consensus feature.
std::unordered_set< const OpenMS::GridFeature * > already_used_
Set of features already used.
Definition QTClusterFinder.h:132
double min_score_
Min. score for an ID to be considered for tolerance estimation.
Definition QTClusterFinder.h:112
void setParameters_(double max_intensity, double max_mz)
Sets algorithm parameters.
bool use_IDs_
Consider peptide identifications for grouping?
Definition QTClusterFinder.h:104
FeatureDistance feature_distance_
Feature distance functor.
Definition QTClusterFinder.h:129
double noID_penalty_
Definition QTClusterFinder.h:117
void run(const std::vector< ConsensusMap > &input_maps, ConsensusMap &result_map) override
Runs the algorithm on consensus maps.
std::unordered_map< const OpenMS::GridFeature *, std::unordered_set< Size > > ElementMapping
Map to store which grid features are next to which clusters (saves the clusters ids)
Definition QTClusterFinder.h:88
double max_diff_rt_
Maximum RT difference.
Definition QTClusterFinder.h:120
QTClusterFinder()
Constructor.
void updateClustering_(ElementMapping &element_mapping, const Grid &grid, const QTCluster::Elements &elements, Heap &cluster_heads, const HeapHandles &handles, Size best_id)
update the clustering:
Size num_maps_
Number of input maps.
Definition QTClusterFinder.h:101
void removeFromElementMapping_(const QTCluster &cluster, ElementMapping &element_mapping)
Removes id of current top cluster in the heap from element mapping.
void addClusterElements_(const Grid &grid, QTCluster &cluster)
Adds elements to the cluster based on the elements hashed in the grid.
bool distIsOutlier_(double dist, double rt)
Looks up the matching bin for rt in bin_tolerances_ and checks if dist is in the allowed range.
void run_(const std::vector< MapType > &input_maps, ConsensusMap &result_map)
Runs the algorithm on feature maps or consensus maps.
A representation of a QT cluster used for feature grouping.
Definition QTCluster.h:82
std::vector< Element > Elements
Definition QTCluster.h:103
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
@ RT
RT in seconds.