OpenMS
ConsensusFeature.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-2023.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 
41 #include <OpenMS/CONCEPT/Types.h>
43 #include <OpenMS/OpenMSConfig.h>
44 
45 #include <set>
46 
47 namespace OpenMS
48 {
49  class FeatureMap;
50  class Peak2D;
51 
69  class OPENMS_DLLAPI ConsensusFeature :
70  public BaseFeature
71  {
72 public:
74 
75  typedef std::set<FeatureHandle, FeatureHandle::IndexLess> HandleSetType;
76  typedef HandleSetType::const_iterator const_iterator;
77  typedef HandleSetType::iterator iterator;
78  typedef HandleSetType::const_reverse_iterator const_reverse_iterator;
79  typedef HandleSetType::reverse_iterator reverse_iterator;
81 
83  struct SizeLess
84  {
85  inline bool operator()(ConsensusFeature const& left, ConsensusFeature const& right) const
86  {
87  return left.size() < right.size();
88  }
89 
90  inline bool operator()(ConsensusFeature const& left, UInt64 const& right) const
91  {
92  return left.size() < right;
93  }
94 
95  inline bool operator()(UInt64 const& left, ConsensusFeature const& right) const
96  {
97  return left < right.size();
98  }
99 
100  inline bool operator()(const UInt64& left, const UInt64& right) const
101  {
102  return left < right;
103  }
104 
105  };
106 
108  struct MapsLess
109  {
110  inline bool operator()(ConsensusFeature const& left, ConsensusFeature const& right) const
111  {
112  return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(), FeatureHandle::IndexLess());
113  }
114 
115  };
116 
118  struct Ratio
119  {
121  {
122  }
123 
124  Ratio(const Ratio& rhs)
125  {
126  ratio_value_ = rhs.ratio_value_;
127  denominator_ref_ = rhs.denominator_ref_;
128  numerator_ref_ = rhs.numerator_ref_;
129  description_ = rhs.description_;
130  }
131 
132  virtual ~Ratio()
133  {
134  }
135 
136  Ratio& operator=(const Ratio& rhs)
137  {
138  if (&rhs != this)
139  {
140  ratio_value_ = rhs.ratio_value_;
141  denominator_ref_ = rhs.denominator_ref_;
142  numerator_ref_ = rhs.numerator_ref_;
143  description_ = rhs.description_;
144  }
145  return *this;
146  }
147 
148  // @TODO: members are public, names shouldn't end in underscores
149  double ratio_value_;
152  std::vector<String> description_;
153  //TODO ratio cv info
154  };
155 
157 
160 
162  ConsensusFeature(const ConsensusFeature& rhs) = default;
163 
166 
168  explicit ConsensusFeature(const BaseFeature& feature);
169 
176  ConsensusFeature(UInt64 map_index, const Peak2D& element, UInt64 element_index);
177 
184  ConsensusFeature(UInt64 map_index, const BaseFeature& element);
185 
188 
191 
193  ~ConsensusFeature() override;
195 
196 
198 
199 
203  void insert(const ConsensusFeature& cf);
205 
212  void insert(const FeatureHandle& handle);
213  void insert(FeatureHandle&& handle);
214 
216  void insert(const HandleSetType& handle_set);
217  void insert(HandleSetType&& handle_set);
218 
225  void insert(UInt64 map_index, const Peak2D& element, UInt64 element_index);
226 
233  void insert(UInt64 map_index, const BaseFeature& element);
234 
236  const HandleSetType& getFeatures() const;
237 
239  std::vector<FeatureHandle> getFeatureList() const;
240 
244 
246 
247  DRange<2> getPositionRange() const;
251 
253 
264 
275 
289  void computeDechargeConsensus(const FeatureMap& fm, bool intensity_weighted_averaging = false);
290 
298  void addRatio(const Ratio& r);
299 
307  void setRatios(std::vector<Ratio>& rs);
308 
312  std::vector<Ratio> getRatios() const;
313 
317  std::vector<Ratio>& getRatios();
318 
320 
321  Size size() const;
322 
324 
326 
328 
330 
332 
334 
336 
338 
339  void clear();
340 
341  bool empty() const;
343 
344 private:
345 
347  std::vector<Ratio> ratios_;
348 
349 
350  };
351 
353  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ConsensusFeature& cons);
354 
355 } // namespace OpenMS
A basic LC-MS feature.
Definition: BaseFeature.h:59
A consensus feature spanning multiple LC-MS/MS experiments.
Definition: ConsensusFeature.h:71
ConsensusFeature(const ConsensusFeature &rhs)=default
Copy constructor.
const_reverse_iterator rend() const
std::vector< Ratio > getRatios() const
Get the ratio vector.
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:77
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:346
HandleSetType::const_reverse_iterator const_reverse_iterator
Definition: ConsensusFeature.h:78
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:79
const HandleSetType & getFeatures() const
Non-mutable access to the contained feature handles.
std::vector< Ratio > ratios_
Definition: ConsensusFeature.h:347
void insert(FeatureHandle &&handle)
ConsensusFeature(const BaseFeature &feature)
Constructor from basic feature.
HandleSetType::const_iterator const_iterator
Definition: ConsensusFeature.h:76
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:75
void setFeatures(HandleSetType h)
Set the feature set to a new one.
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:62
Representation of a Peak2D, RichPeak2D or Feature .
Definition: FeatureHandle.h:60
A container for features.
Definition: FeatureMap.h:106
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
A more convenient string class.
Definition: String.h:60
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
const double h
Definition: Constants.h:167
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Compare by the sets of consensus elements (lexicographically)
Definition: ConsensusFeature.h:109
bool operator()(ConsensusFeature const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:110
slim struct to feed the need for systematically storing of ratios (
Definition: ConsensusFeature.h:119
double ratio_value_
Definition: ConsensusFeature.h:149
Ratio & operator=(const Ratio &rhs)
Definition: ConsensusFeature.h:136
std::vector< String > description_
Definition: ConsensusFeature.h:152
Ratio(const Ratio &rhs)
Definition: ConsensusFeature.h:124
virtual ~Ratio()
Definition: ConsensusFeature.h:132
String denominator_ref_
Definition: ConsensusFeature.h:150
Ratio()
Definition: ConsensusFeature.h:120
String numerator_ref_
Definition: ConsensusFeature.h:151
Compare by size(), the number of consensus elements.
Definition: ConsensusFeature.h:84
bool operator()(const UInt64 &left, const UInt64 &right) const
Definition: ConsensusFeature.h:100
bool operator()(ConsensusFeature const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:85
bool operator()(ConsensusFeature const &left, UInt64 const &right) const
Definition: ConsensusFeature.h:90
bool operator()(UInt64 const &left, ConsensusFeature const &right) const
Definition: ConsensusFeature.h:95
Comparator by map and unique id.
Definition: FeatureHandle.h:141