OpenMS  3.0.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-2022.
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 <unordered_map>
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 
107  class OPENMS_DLLAPI QTCluster
108  {
109 public:
110 
111  // need to store more than one
112  typedef std::multimap<double, const GridFeature*> NeighborList;
113  typedef std::unordered_map<Size, NeighborList> NeighborMapMulti;
114 
115  struct Neighbor
116  {
117  double distance;
119  };
120 
121  typedef std::unordered_map<Size, Neighbor> NeighborMap;
122 
123  struct Element
124  {
127  };
128 
129  typedef std::vector<Element> Elements;
130 
137  class OPENMS_DLLAPI BulkData
138  {
139  friend class QTCluster;
140 
141  public:
142 
150  BulkData(const OpenMS::GridFeature* const center_point,
151  Size num_maps, double max_distance,
152  Int x_coord, Int y_coord, Size id);
153 
154  private:
155 
158 
161 
167 
176 
179 
182 
185 
188 
195  std::set<AASequence> annotations_;
196  };
197 
204  QTCluster(BulkData* const data, bool use_IDs);
205 
211  QTCluster() = delete;
212 
219  QTCluster(const QTCluster& rhs) = default;
220 
222  QTCluster& operator=(const QTCluster& rhs) = default;
223 
225  QTCluster(QTCluster&& rhs) = default;
226 
228  QTCluster& operator=(QTCluster&& rhs) = default;
229 
230  ~QTCluster() = default;
231 
233  const GridFeature* getCenterPoint() const;
234 
236  Size getId() const;
237 
239  double getCenterRT() const;
240 
242  double getCenterMZ() const;
243 
245  Int getXCoord() const;
246 
248  Int getYCoord() const;
249 
251  Size size() const;
252 
254  bool operator<(const QTCluster& cluster) const;
255 
262  void add(const GridFeature* const element, double distance);
263 
265  Elements getElements() const;
266 
274  bool update(const Elements& removed);
275 
277  double getQuality();
278 
280  double getCurrentQuality() const;
281 
283  const std::set<AASequence>& getAnnotations();
284 
292  void setInvalid();
293 
295  inline bool isInvalid() const
296  {
297  return !valid_;
298  }
299 
301  void initializeCluster();
302 
304  void finalizeCluster();
305 
307  Elements getAllNeighbors() const;
308 
309  private:
311  void computeQuality_();
312 
332  double optimizeAnnotations_();
333 
335  void makeSeqTable_(std::map<AASequence, std::map<Size,double>>& seq_table) const;
336 
338  void recomputeNeighbors_();
339 
341  double quality_;
342 
345 
347  bool valid_;
348 
350  bool changed_;
351 
353  bool use_IDs_;
354 
365 
368  };
369 
370 } // 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:147
OpenMS::QTCluster::BulkData::y_coord_
Int y_coord_
y coordinate in the grid cell
Definition: QTCluster.h:187
OpenMS::QTCluster::BulkData::annotations_
std::set< AASequence > annotations_
Set of annotations of the cluster.
Definition: QTCluster.h:195
Size
OpenMS::QTCluster::BulkData::id_
Size id_
unique id of this cluster
Definition: QTCluster.h:160
Types.h
OpenMS::QTCluster::Neighbor
Definition: QTCluster.h:115
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::QTCluster::NeighborMap
std::unordered_map< Size, Neighbor > NeighborMap
Definition: QTCluster.h:121
OpenMS::QTCluster::isInvalid
bool isInvalid() const
Whether current cluster is invalid.
Definition: QTCluster.h:295
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:367
OpenMS::QTCluster::Elements
std::vector< Element > Elements
Definition: QTCluster.h:129
OpenMS::QTCluster::Element
Definition: QTCluster.h:123
OpenMS::GridFeature
Representation of a feature in a hash grid.
Definition: GridFeature.h:52
OpenMS::operator<
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
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:125
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::QTCluster
A representation of a QT cluster used for feature grouping.
Definition: QTCluster.h:107
OpenMS::QTCluster::changed_
bool changed_
Has the cluster changed (if yes, quality needs to be recomputed)?
Definition: QTCluster.h:350
OpenMS::QTCluster::NeighborList
std::multimap< double, const GridFeature * > NeighborList
Definition: QTCluster.h:112
OpenMS::QTCluster::BulkData::num_maps_
Size num_maps_
Number of input maps.
Definition: QTCluster.h:181
OpenMS::QTCluster::collect_annotations_
bool collect_annotations_
Whether initial collection of all neighbors is needed.
Definition: QTCluster.h:364
OpenMS::QTCluster::valid_
bool valid_
Whether current cluster is valid.
Definition: QTCluster.h:347
QcMLFile.h
OpenMS::QTCluster::use_IDs_
bool use_IDs_
Keep track of peptide IDs and use them for matching?
Definition: QTCluster.h:353
OpenMS::QTCluster::data_
BulkData * data_
Pointer to data members.
Definition: QTCluster.h:344
OpenMS::QTCluster::BulkData::max_distance_
double max_distance_
Maximum distance of a point that can still belong to the cluster.
Definition: QTCluster.h:178
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:157
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
OpenMS::QTCluster::BulkData
Class to store the bulk internal data (neighbors, annotations, etc.)
Definition: QTCluster.h:137
OpenMS::QTCluster::BulkData::tmp_neighbors_
NeighborMapMulti tmp_neighbors_
Temporary map tracking *all* neighbors.
Definition: QTCluster.h:175
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:166
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:111
OpenMS::QTCluster::Neighbor::feature
const GridFeature * feature
Definition: QTCluster.h:118
OpenMS::QTCluster::Neighbor::distance
double distance
Definition: QTCluster.h:117
StandardTypes.h
OpenMS::QTCluster::BulkData::x_coord_
Int x_coord_
x coordinate in the grid cell
Definition: QTCluster.h:184
OpenMS::QTCluster::NeighborMapMulti
std::unordered_map< Size, NeighborList > NeighborMapMulti
Definition: QTCluster.h:113
TOPPBase.h
OpenMS::QTCluster::quality_
double quality_
Quality of the cluster.
Definition: QTCluster.h:341