OpenMS
QTCluster.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 
10 #pragma once
11 
12 #include <OpenMS/CONCEPT/Types.h>
14 #include <OpenMS/OpenMSConfig.h>
15 #include <OpenMS/config.h>
16 
17 #include <unordered_map>
18 
19 #include <map> // for multimap<>
20 #include <vector> // for vector<>
21 #include <set> // for set<>
22 #include <utility> // for pair<>
23 
24 namespace OpenMS
25 {
26  class GridFeature;
27 
81  class OPENMS_DLLAPI QTCluster
82  {
83 public:
84 
85  // need to store more than one
86  typedef std::multimap<double, const GridFeature*> NeighborList;
87  typedef std::unordered_map<Size, NeighborList> NeighborMapMulti;
88 
89  struct Neighbor
90  {
91  double distance;
93  };
94 
95  typedef std::unordered_map<Size, Neighbor> NeighborMap;
96 
97  struct Element
98  {
101  };
102 
103  typedef std::vector<Element> Elements;
104 
111  class OPENMS_DLLAPI BulkData
112  {
113  friend class QTCluster;
114 
115  public:
116 
126  BulkData(const OpenMS::GridFeature* const center_point,
127  Size num_maps, double max_distance,
128  Int x_coord, Int y_coord, Size id);
129 
130  private:
131 
134 
137 
143 
152 
155 
158 
161 
164 
171  std::set<AASequence> annotations_;
172  };
173 
180  QTCluster(BulkData* const data, bool use_IDs);
181 
187  QTCluster() = delete;
188 
195  QTCluster(const QTCluster& rhs) = default;
196 
198  QTCluster& operator=(const QTCluster& rhs) = default;
199 
201  QTCluster(QTCluster&& rhs) = default;
202 
204  QTCluster& operator=(QTCluster&& rhs) = default;
205 
206  ~QTCluster() = default;
207 
209  const GridFeature* getCenterPoint() const;
210 
212  Size getId() const;
213 
215  double getCenterRT() const;
216 
218  double getCenterMZ() const;
219 
221  Int getXCoord() const;
222 
224  Int getYCoord() const;
225 
227  Size size() const;
228 
230  bool operator<(const QTCluster& cluster) const;
231 
238  void add(const GridFeature* const element, double distance);
239 
242 
250  bool update(const Elements& removed);
251 
253  double getQuality();
254 
256  double getCurrentQuality() const;
257 
259  const std::set<AASequence>& getAnnotations();
260 
268  void setInvalid();
269 
271  inline bool isInvalid() const
272  {
273  return !valid_;
274  }
275 
278 
281 
284 
285  private:
288 
309 
311  void makeSeqTable_(std::map<AASequence, std::map<Size,double>>& seq_table) const;
312 
315 
317  double quality_;
318 
321 
323  bool valid_;
324 
326  bool changed_;
327 
329  bool use_IDs_;
330 
341 
344  };
345 
346 } // namespace OpenMS
Representation of a peptide/protein sequence.
Definition: AASequence.h:86
Representation of a feature in a hash grid.
Definition: GridFeature.h:27
Class to store the bulk internal data (neighbors, annotations, etc.)
Definition: QTCluster.h:112
NeighborMapMulti tmp_neighbors_
Temporary map tracking all neighbors.
Definition: QTCluster.h:151
BulkData(const OpenMS::GridFeature *const center_point, Size num_maps, double max_distance, Int x_coord, Int y_coord, Size id)
Detailed constructor of the cluster body.
Int x_coord_
x coordinate in the grid cell
Definition: QTCluster.h:160
const GridFeature *const center_point_
Pointer to the cluster center.
Definition: QTCluster.h:133
std::set< AASequence > annotations_
Set of annotations of the cluster.
Definition: QTCluster.h:171
NeighborMap neighbors_
Map that keeps track of the best current feature for each map.
Definition: QTCluster.h:142
Size num_maps_
Number of input maps.
Definition: QTCluster.h:157
Int y_coord_
y coordinate in the grid cell
Definition: QTCluster.h:163
double max_distance_
Maximum distance of a point that can still belong to the cluster.
Definition: QTCluster.h:154
Size id_
unique id of this cluster
Definition: QTCluster.h:136
A representation of a QT cluster used for feature grouping.
Definition: QTCluster.h:82
std::vector< Element > Elements
Definition: QTCluster.h:103
const std::set< AASequence > & getAnnotations()
Return the set of peptide sequences annotated to the cluster center.
void setInvalid()
Sets current cluster as invalid (also frees some memory)
Int getXCoord() const
Returns the x coordinate in the grid.
void initializeCluster()
Has to be called before adding elements (calling QTCluster::add)
double getCurrentQuality() const
Returns the cluster quality without recomputing.
QTCluster(const QTCluster &rhs)=default
Cheap copy ctor because most of the data lies outside of this class (BulkData*) Be very careful with ...
bool isInvalid() const
Whether current cluster is invalid.
Definition: QTCluster.h:271
bool valid_
Whether current cluster is valid.
Definition: QTCluster.h:323
void add(const GridFeature *const element, double distance)
Adds a new element/neighbor to the cluster.
double quality_
Quality of the cluster.
Definition: QTCluster.h:317
bool collect_annotations_
Whether initial collection of all neighbors is needed.
Definition: QTCluster.h:340
QTCluster & operator=(const QTCluster &rhs)=default
Cheap copy assignment, see copy ctor for details.
bool operator<(const QTCluster &cluster) const
Compare by quality.
void recomputeNeighbors_()
report elements that are compatible with the optimal annotation
const GridFeature * getCenterPoint() const
Returns the cluster center.
void makeSeqTable_(std::map< AASequence, std::map< Size, double >> &seq_table) const
compute seq table, mapping: peptides -> best distance per input map
std::multimap< double, const GridFeature * > NeighborList
Definition: QTCluster.h:86
Size map_index
Definition: QTCluster.h:99
Size getId() const
returns the clusters id
void finalizeCluster()
Has to be called after adding elements (after calling QTCluster::add one or multiple times)
double distance
Definition: QTCluster.h:91
BulkData * data_
Pointer to data members.
Definition: QTCluster.h:320
double optimizeAnnotations_()
Finds the optimal annotation (peptide sequences) for the cluster.
~QTCluster()=default
Elements getAllNeighbors() const
Get all current neighbors.
bool changed_
Has the cluster changed (if yes, quality needs to be recomputed)?
Definition: QTCluster.h:326
bool use_IDs_
Keep track of peptide IDs and use them for matching?
Definition: QTCluster.h:329
std::unordered_map< Size, NeighborList > NeighborMapMulti
Definition: QTCluster.h:87
bool update(const Elements &removed)
Updates the cluster after the indicated data points are removed.
Size size() const
Returns the size of the cluster (number of elements, incl. center)
QTCluster(BulkData *const data, bool use_IDs)
Detailed constructor of the cluster head.
double getQuality()
Returns the cluster quality and recomputes if necessary.
double getCenterMZ() const
Returns the m/z value of the cluster center.
QTCluster(QTCluster &&rhs)=default
cheap move ctor because most of the data lies outside of this class (BulkData*)
QTCluster & operator=(QTCluster &&rhs)=default
cheap move assignment because most of the data lies outside of this class (BulkData*)
Int getYCoord() const
Returns the y coordinate in the grid.
double getCenterRT() const
Returns the RT value of the cluster.
bool finalized_
Whether current cluster is accepting new elements or not (if true, no more new elements allowed)
Definition: QTCluster.h:343
const GridFeature * feature
Definition: QTCluster.h:92
void computeQuality_()
Computes the quality of the cluster.
QTCluster()=delete
Default constructor not accessible Objects of this class should only exist with a valid BulkData* giv...
Elements getElements() const
Gets the clustered elements meaning neighbors + cluster center.
std::unordered_map< Size, Neighbor > NeighborMap
Definition: QTCluster.h:95
Definition: QTCluster.h:98
Definition: QTCluster.h:90
int Int
Signed integer type.
Definition: Types.h:72
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