OpenMS  2.4.0
QTCluster.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-2018.
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: Hendrik Weisser $
32 // $Authors: Steffen Sass, Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 
36 #pragma once
37 
38 #include <OpenMS/CONCEPT/Types.h>
40 #include <OpenMS/OpenMSConfig.h>
41 #include <OpenMS/config.h>
42 
43 #include <boost/unordered_map.hpp>
44 
45 #include <map> // for multimap<>
46 #include <vector> // for vector<>
47 #include <set> // for set<>
48 #include <utility> // for pair<>
49 
50 
51 namespace OpenMS
52 {
53  class GridFeature;
54 
55  // Boost switch since with 1.47 several classes got moved into a new
56  // boost::unordered namespace (specifically unordered_map).
57  namespace OpenMSBoost
58  {
59 #if OPENMS_BOOST_VERSION_MINOR > 47
60  using namespace boost::unordered;
61 #else
62  using namespace boost;
63 #endif
64  }
65 
66 
111  class OPENMS_DLLAPI QTCluster
112  {
113 private:
114 
115  // need to store more than one
116  typedef std::multimap<double, GridFeature*> NeighborListType;
117  typedef OpenMSBoost::unordered_map<Size, NeighborListType> NeighborMapMulti;
118 
119  typedef std::pair<double, GridFeature*> NeighborPairType;
120  typedef OpenMSBoost::unordered_map<Size, NeighborPairType> NeighborMap;
121 
124 
130 
139 
142 
145 
147  double quality_;
148 
150  bool changed_;
151 
153  bool use_IDs_;
154 
156  bool valid_;
157 
168 
171 
174 
177 
184  std::set<AASequence> annotations_;
185 
187  QTCluster();
188 
190  void computeQuality_();
191 
211  double optimizeAnnotations_();
212 
213 public:
214 
222  QTCluster(GridFeature* center_point, Size num_maps,
223  double max_distance, bool use_IDs,
224  Int x_coord, Int y_coord);
225 
227  virtual ~QTCluster();
228 
230  GridFeature* getCenterPoint();
231 
233  double getCenterRT() const;
234 
236  double getCenterMZ() const;
237 
239  Int getXCoord() const;
240 
242  Int getYCoord() const;
243 
245  Size size() const;
246 
248  bool operator<(QTCluster& cluster);
249 
256  void add(GridFeature* element, double distance);
257 
259  void getElements(OpenMSBoost::unordered_map<Size, GridFeature*>& elements);
260 
268  bool update(const OpenMSBoost::unordered_map<Size, GridFeature*>& removed);
269 
271  double getQuality();
272 
274  const std::set<AASequence>& getAnnotations();
275 
283  void setInvalid();
284 
286  inline bool isInvalid() const
287  {
288  return !valid_;
289  }
290 
292  void initializeCluster();
293 
295  void finalizeCluster();
296 
298  OpenMSBoost::unordered_map<Size, std::vector<GridFeature*> > getAllNeighbors();
299  };
300 } // namespace OpenMS
301 
std::set< AASequence > annotations_
Set of annotations of the cluster.
Definition: QTCluster.h:184
A representation of a QT cluster used for feature grouping.
Definition: QTCluster.h:111
NeighborMap neighbors_
Map that keeps track of the best current feature for each map.
Definition: QTCluster.h:129
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
GridFeature * center_point_
Pointer to the cluster center.
Definition: QTCluster.h:123
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
Representation of a feature in a hash grid.
Definition: GridFeature.h:52
bool use_IDs_
Keep track of peptide IDs and use them for matching?
Definition: QTCluster.h:153
bool collect_annotations_
Whether initial collection of all neighbors is needed.
Definition: QTCluster.h:167
NeighborMapMulti * tmp_neighbors_
Temporary map tracking *all* neighbors.
Definition: QTCluster.h:138
bool finalized_
Whether current cluster is accepting new elements or not (if true, no more new elements allowed) ...
Definition: QTCluster.h:170
Int x_coord_
x coordinate in the grid cell
Definition: QTCluster.h:173
bool changed_
Has the cluster changed (if yes, quality needs to be recomputed)?
Definition: QTCluster.h:150
Int y_coord_
y coordinate in the grid cell
Definition: QTCluster.h:176
std::pair< double, GridFeature * > NeighborPairType
Definition: QTCluster.h:119
OpenMSBoost::unordered_map< Size, NeighborPairType > NeighborMap
Definition: QTCluster.h:120
OpenMSBoost::unordered_map< Size, NeighborListType > NeighborMapMulti
Definition: QTCluster.h:117
Size num_maps_
Number of input maps.
Definition: QTCluster.h:144
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::multimap< double, GridFeature * > NeighborListType
Definition: QTCluster.h:116
bool valid_
Whether current cluster is valid.
Definition: QTCluster.h:156
double quality_
Quality of the cluster.
Definition: QTCluster.h:147
bool isInvalid() const
Whether current cluster is invalid.
Definition: QTCluster.h:286
int Int
Signed integer type.
Definition: Types.h:102
double max_distance_
Maximum distance of a point that can still belong to the cluster.
Definition: QTCluster.h:141