OpenMS  2.6.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-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: 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 namespace OpenMS
51 {
52  class GridFeature;
53 
54  // Boost switch since with 1.47 several classes got moved into a new
55  // boost::unordered namespace (specifically unordered_map).
56  namespace OpenMSBoost
57  {
58 #if OPENMS_BOOST_VERSION_MINOR > 47
59  using namespace boost::unordered;
60 #else
61  using namespace boost;
62 #endif
63  }
64 
65 
110  class OPENMS_DLLAPI QTCluster
111  {
112 public:
113 
114  // need to store more than one
115  typedef std::multimap<double, const GridFeature*> NeighborList;
116  typedef OpenMSBoost::unordered_map<Size, NeighborList> NeighborMapMulti;
117 
118  struct Neighbor
119  {
120  double distance;
122  };
123 
124  typedef OpenMSBoost::unordered_map<Size, Neighbor> NeighborMap;
125 
126  struct Element
127  {
130  };
131 
132  typedef std::vector<Element> Elements;
133 
140  class OPENMS_DLLAPI BulkData
141  {
142  friend class QTCluster;
143 
144  public:
145 
153  BulkData(const OpenMS::GridFeature* const center_point,
154  Size num_maps, double max_distance,
155  Int x_coord, Int y_coord, Size id);
156 
157  private:
158 
161 
164 
170 
179 
182 
185 
188 
191 
198  std::set<AASequence> annotations_;
199  };
200 
207  QTCluster(BulkData* const data, bool use_IDs);
208 
214  QTCluster() = delete;
215 
222  QTCluster(const QTCluster& rhs) = default;
223 
225  QTCluster& operator=(const QTCluster& rhs) = default;
226 
228  QTCluster(QTCluster&& rhs) = default;
229 
231  QTCluster& operator=(QTCluster&& rhs) = default;
232 
233  ~QTCluster() = default;
234 
236  const GridFeature* getCenterPoint() const;
237 
239  Size getId() const;
240 
242  double getCenterRT() const;
243 
245  double getCenterMZ() const;
246 
248  Int getXCoord() const;
249 
251  Int getYCoord() const;
252 
254  Size size() const;
255 
257  bool operator<(const QTCluster& cluster);
258 
265  void add(const GridFeature* const element, double distance);
266 
268  Elements getElements() const;
269 
277  bool update(const Elements& removed);
278 
280  double getQuality();
281 
283  double getCurrentQuality() const;
284 
286  const std::set<AASequence>& getAnnotations();
287 
295  void setInvalid();
296 
298  inline bool isInvalid() const
299  {
300  return !valid_;
301  }
302 
304  void initializeCluster();
305 
307  void finalizeCluster();
308 
310  Elements getAllNeighbors() const;
311 
312  private:
314  void computeQuality_();
315 
335  double optimizeAnnotations_();
336 
338  void makeSeqTable_(std::map<std::set<AASequence>, std::vector<double>>& seq_table) const;
339 
341  void recomputeNeighbors_();
342 
344  double quality_;
345 
348 
350  bool valid_;
351 
353  bool changed_;
354 
356  bool use_IDs_;
357 
368 
371  };
372 
373  // needed for the heap
374  bool operator<(const QTCluster& q1, const QTCluster& q2);
375 } // namespace OpenMS
OpenMS::QcMLFile::removeAttachment
void removeAttachment(String r, std::vector< String > &ids, String at="")
Removes attachments referencing a id given in ids, from run/set r. All attachments if no attachment n...
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::QTCluster::BulkData::y_coord_
Int y_coord_
y coordinate in the grid cell
Definition: QTCluster.h:190
OpenMS::QTCluster::BulkData::annotations_
std::set< AASequence > annotations_
Set of annotations of the cluster.
Definition: QTCluster.h:198
OpenMS::QTCluster::BulkData::id_
Size id_
unique id of this cluster
Definition: QTCluster.h:163
Types.h
OpenMS::QTCluster::Neighbor
Definition: QTCluster.h:118
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::QTCluster::isInvalid
bool isInvalid() const
Whether current cluster is invalid.
Definition: QTCluster.h:298
OpenMS::QTCluster::NeighborMap
OpenMSBoost::unordered_map< Size, Neighbor > NeighborMap
Definition: QTCluster.h:124
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::QcMLFile::removeAllAttachments
void removeAllAttachments(String at)
Removes attachment with cv accession at from all runs/sets.
OpenMS::QTCluster::finalized_
bool finalized_
Whether current cluster is accepting new elements or not (if true, no more new elements allowed)
Definition: QTCluster.h:370
OpenMS::QTCluster::Elements
std::vector< Element > Elements
Definition: QTCluster.h:132
OpenMS::QTCluster::Element
Definition: QTCluster.h:126
OpenMS::GridFeature
Representation of a feature in a hash grid.
Definition: GridFeature.h:52
OpenMS::operator<
bool operator<(const QTCluster &q1, const QTCluster &q2)
OpenMS::QcMLFile::load
void load(const String &filename)
Load a QCFile.
OpenMS::QcMLFile::store
void store(const String &filename) const
Store the QCFile.
OpenMS::QTCluster::Element::map_index
Size map_index
Definition: QTCluster.h:128
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::QTCluster
A representation of a QT cluster used for feature grouping.
Definition: QTCluster.h:110
OpenMS::QTCluster::changed_
bool changed_
Has the cluster changed (if yes, quality needs to be recomputed)?
Definition: QTCluster.h:353
int
OpenMS::QTCluster::NeighborList
std::multimap< double, const GridFeature * > NeighborList
Definition: QTCluster.h:115
OpenMS::QTCluster::BulkData::num_maps_
Size num_maps_
Number of input maps.
Definition: QTCluster.h:184
OpenMS::QTCluster::collect_annotations_
bool collect_annotations_
Whether initial collection of all neighbors is needed.
Definition: QTCluster.h:367
OpenMS::QTCluster::valid_
bool valid_
Whether current cluster is valid.
Definition: QTCluster.h:350
QcMLFile.h
OpenMS::QTCluster::use_IDs_
bool use_IDs_
Keep track of peptide IDs and use them for matching?
Definition: QTCluster.h:356
OpenMS::QTCluster::data_
BulkData * data_
Pointer to data members.
Definition: QTCluster.h:347
OpenMS::QTCluster::BulkData::max_distance_
double max_distance_
Maximum distance of a point that can still belong to the cluster.
Definition: QTCluster.h:181
OpenMS::QTCluster::NeighborMapMulti
OpenMSBoost::unordered_map< Size, NeighborList > NeighborMapMulti
Definition: QTCluster.h:116
CsvFile.h
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::QTCluster::BulkData::center_point_
const GridFeature *const center_point_
Pointer to the cluster center.
Definition: QTCluster.h:160
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
OpenMS::QTCluster::BulkData
Class to store the bulk internal data (neighbors, annotations, etc.)
Definition: QTCluster.h:140
OpenMS::QTCluster::BulkData::tmp_neighbors_
NeighborMapMulti tmp_neighbors_
Temporary map tracking *all* neighbors.
Definition: QTCluster.h:178
OpenMS::QcMLFile
File adapter for QcML files used to load and store QcML files.
Definition: QcMLFile.h:57
AASequence.h
String.h
OpenMS::QTCluster::BulkData::neighbors_
NeighborMap neighbors_
Map that keeps track of the best current feature for each map.
Definition: QTCluster.h:169
OpenMS::QTCluster::Neighbor::feature
const GridFeature * feature
Definition: QTCluster.h:121
OpenMS::QTCluster::Neighbor::distance
double distance
Definition: QTCluster.h:120
StandardTypes.h
OpenMS::QTCluster::BulkData::x_coord_
Int x_coord_
x coordinate in the grid cell
Definition: QTCluster.h:187
TOPPBase.h
OpenMS::QTCluster::quality_
double quality_
Quality of the cluster.
Definition: QTCluster.h:344