OpenMS
ConsensusFeature.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: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
14 
15 #include <OpenMS/CONCEPT/Types.h>
17 #include <OpenMS/OpenMSConfig.h>
18 
19 #include <set>
20 
21 namespace OpenMS
22 {
23  class FeatureMap;
24  class Peak2D;
25 
43  class OPENMS_DLLAPI ConsensusFeature :
44  public BaseFeature
45  {
46 public:
48 
49  typedef std::set<FeatureHandle, FeatureHandle::IndexLess> HandleSetType;
50  typedef HandleSetType::const_iterator const_iterator;
51  typedef HandleSetType::iterator iterator;
52  typedef HandleSetType::const_reverse_iterator const_reverse_iterator;
53  typedef HandleSetType::reverse_iterator reverse_iterator;
55 
57  struct SizeLess
58  {
59  inline bool operator()(ConsensusFeature const& left, ConsensusFeature const& right) const
60  {
61  return left.size() < right.size();
62  }
63 
64  inline bool operator()(ConsensusFeature const& left, UInt64 const& right) const
65  {
66  return left.size() < right;
67  }
68 
69  inline bool operator()(UInt64 const& left, ConsensusFeature const& right) const
70  {
71  return left < right.size();
72  }
73 
74  inline bool operator()(const UInt64& left, const UInt64& right) const
75  {
76  return left < right;
77  }
78 
79  };
80 
82  struct MapsLess
83  {
84  inline bool operator()(ConsensusFeature const& left, ConsensusFeature const& right) const
85  {
86  return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(), FeatureHandle::IndexLess());
87  }
88 
89  };
90 
92  struct Ratio
93  {
95  {
96  }
97 
98  Ratio(const Ratio& rhs)
99  {
100  ratio_value_ = rhs.ratio_value_;
101  denominator_ref_ = rhs.denominator_ref_;
102  numerator_ref_ = rhs.numerator_ref_;
103  description_ = rhs.description_;
104  }
105 
106  virtual ~Ratio()
107  {
108  }
109 
110  Ratio& operator=(const Ratio& rhs)
111  {
112  if (&rhs != this)
113  {
114  ratio_value_ = rhs.ratio_value_;
115  denominator_ref_ = rhs.denominator_ref_;
116  numerator_ref_ = rhs.numerator_ref_;
117  description_ = rhs.description_;
118  }
119  return *this;
120  }
121 
122  // @TODO: members are public, names shouldn't end in underscores
123  double ratio_value_;
126  std::vector<String> description_;
127  //TODO ratio cv info
128  };
129 
131 
134 
136  ConsensusFeature(const ConsensusFeature& rhs) = default;
137 
140 
142  explicit ConsensusFeature(const BaseFeature& feature);
143 
150  ConsensusFeature(UInt64 map_index, const Peak2D& element, UInt64 element_index);
151 
158  ConsensusFeature(UInt64 map_index, const BaseFeature& element);
159 
162 
165 
167  ~ConsensusFeature() override;
169 
170 
172 
173 
177  void insert(const ConsensusFeature& cf);
179 
186  void insert(const FeatureHandle& handle);
187  void insert(FeatureHandle&& handle);
188 
190  void insert(const HandleSetType& handle_set);
191  void insert(HandleSetType&& handle_set);
192 
199  void insert(UInt64 map_index, const Peak2D& element, UInt64 element_index);
200 
207  void insert(UInt64 map_index, const BaseFeature& element);
208 
210  const HandleSetType& getFeatures() const;
211 
213  std::vector<FeatureHandle> getFeatureList() const;
214 
218 
220 
221  DRange<2> getPositionRange() const;
225 
227 
238 
249 
263  void computeDechargeConsensus(const FeatureMap& fm, bool intensity_weighted_averaging = false);
264 
272  void addRatio(const Ratio& r);
273 
281  void setRatios(std::vector<Ratio>& rs);
282 
286  const std::vector<Ratio>& getRatios() const;
287 
291  std::vector<Ratio>& getRatios();
292 
294 
295  Size size() const;
296 
298 
300 
302 
304 
306 
308 
310 
312 
313  void clear();
314 
315  bool empty() const;
317 
318 private:
319 
321  std::vector<Ratio> ratios_;
322 
323 
324  };
325 
327  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusFeature& cons);
328 
329 } // namespace OpenMS
A basic LC-MS feature.
Definition: BaseFeature.h:33
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:45
ConsensusFeature(const ConsensusFeature &rhs)=default
Copy constructor.
const_reverse_iterator rend() const
void computeConsensus()
Computes and updates the consensus position, intensity, and charge.
const_iterator begin() const
void insert(ConsensusFeature &&cf)
void computeMonoisotopicConsensus()
Computes and updates the consensus position, intensity, and charge.
void addRatio(const Ratio &r)
Add a ratio.
void insert(UInt64 map_index, const BaseFeature &element)
Creates a FeatureHandle and adds it.
ConsensusFeature(ConsensusFeature &&rhs)=default
Move constructor.
~ConsensusFeature() override
Destructor.
ConsensusFeature & operator=(const ConsensusFeature &rhs)=default
Assignment operator.
void setRatios(std::vector< Ratio > &rs)
Add a ratio vector.
void insert(const ConsensusFeature &cf)
Adds all feature handles (of the CF) into the consensus feature.
std::vector< FeatureHandle > getFeatureList() const
Mutable access to a copy of the contained feature handles.
HandleSetType::iterator iterator
Definition: ConsensusFeature.h:51
ConsensusFeature(UInt64 map_index, const BaseFeature &element)
Constructor with map index for a singleton consensus feature.
void insert(const FeatureHandle &handle)
Adds an feature handle into the consensus feature.
void insert(UInt64 map_index, const Peak2D &element, UInt64 element_index)
Creates a FeatureHandle and adds it.
ConsensusFeature(UInt64 map_index, const Peak2D &element, UInt64 element_index)
Constructor with map and element index for a singleton consensus feature.
reverse_iterator rend()
HandleSetType handles_
Definition: ConsensusFeature.h:320
HandleSetType::const_reverse_iterator const_reverse_iterator
Definition: ConsensusFeature.h:52
void computeDechargeConsensus(const FeatureMap &fm, bool intensity_weighted_averaging=false)
Computes the uncharged parent RT & mass, assuming the handles are charge variants.
void insert(HandleSetType &&handle_set)
ConsensusFeature & operator=(ConsensusFeature &&rhs)=default
Move Assignment operator.
DRange< 1 > getIntensityRange() const
Returns the intensity range of the contained elements.
HandleSetType::reverse_iterator reverse_iterator
Definition: ConsensusFeature.h:53
const HandleSetType & getFeatures() const
Non-mutable access to the contained feature handles.
std::vector< Ratio > ratios_
Definition: ConsensusFeature.h:321
void insert(FeatureHandle &&handle)
ConsensusFeature(const BaseFeature &feature)
Constructor from basic feature.
HandleSetType::const_iterator const_iterator
Definition: ConsensusFeature.h:50
std::vector< Ratio > & getRatios()
Get the ratio vector.
const_iterator end() const
reverse_iterator rbegin()
std::set< FeatureHandle, FeatureHandle::IndexLess > HandleSetType
Type definitions.
Definition: ConsensusFeature.h:49
void setFeatures(HandleSetType h)
Set the feature set to a new one.
const std::vector< Ratio > & getRatios() const
Get the ratio vector.
const_reverse_iterator rbegin() const
void insert(const HandleSetType &handle_set)
Adds all feature handles in handle_set to this consensus feature.
A D-dimensional half-open interval.
Definition: DRange.h:36
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:34
A container for features.
Definition: FeatureMap.h:80
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:29
A more convenient string class.
Definition: String.h:34
uint64_t UInt64
Unsigned integer type (64bit)
Definition: Types.h:47
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
const double h
Definition: Constants.h:141
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Compare by the sets of consensus elements (lexicographically)
Definition: ConsensusFeature.h:83
bool operator()(ConsensusFeature const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:84
slim struct to feed the need for systematically storing of ratios.
Definition: ConsensusFeature.h:93
double ratio_value_
Definition: ConsensusFeature.h:123
Ratio & operator=(const Ratio &rhs)
Definition: ConsensusFeature.h:110
std::vector< String > description_
Definition: ConsensusFeature.h:126
Ratio(const Ratio &rhs)
Definition: ConsensusFeature.h:98
virtual ~Ratio()
Definition: ConsensusFeature.h:106
String denominator_ref_
Definition: ConsensusFeature.h:124
Ratio()
Definition: ConsensusFeature.h:94
String numerator_ref_
Definition: ConsensusFeature.h:125
Compare by size(), the number of consensus elements.
Definition: ConsensusFeature.h:58
bool operator()(const UInt64 &left, const UInt64 &right) const
Definition: ConsensusFeature.h:74
bool operator()(ConsensusFeature const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:59
bool operator()(ConsensusFeature const &left, UInt64 const &right) const
Definition: ConsensusFeature.h:64
bool operator()(UInt64 const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:69
Comparator by map and unique id.
Definition: FeatureHandle.h:115