OpenMS
IsotopeDistribution.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Clemens Groepl, Andreas Bertsch, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/KERNEL/Peak1D.h>
12 #include <functional>
13 #include <vector>
14 
15 namespace OpenMS
16 {
36  class Element;
37 
38  class OPENMS_DLLAPI IsotopeDistribution
39  {
40 public:
41 
43 
44  typedef Peak1D MassAbundance;
46  typedef std::vector<MassAbundance> ContainerType;
47  typedef ContainerType::iterator iterator;
48  typedef ContainerType::iterator Iterator;
49  typedef ContainerType::const_iterator const_iterator;
50  typedef ContainerType::const_iterator ConstIterator;
51 
52  typedef ContainerType::reverse_iterator reverse_iterator;
53  typedef ContainerType::reverse_iterator ReverseIterator;
54  typedef ContainerType::const_reverse_iterator const_reverse_iterator;
55  typedef ContainerType::const_reverse_iterator ConstReverseIterator;
57 
58  enum Sorted {INTENSITY, MASS, UNDEFINED};
59 
61 
62 
65 
68 
71 
73  virtual ~IsotopeDistribution() = default;
75 
77 
78 
80  void set(const ContainerType & distribution);
81 
83  void set(ContainerType && distribution);
84 
86  const ContainerType & getContainer() const;
87 
89  Peak1D::CoordinateType getMax() const;
90 
92  Peak1D::CoordinateType getMin() const;
93 
95  Peak1D getMostAbundant() const;
96 
98  Size size() const;
99 
101  void clear();
102 
103  // resizes distribution container
104  void resize(UInt size);
105 
107  void trimIntensities(double cutoff);
108 
110  void sortByIntensity();
111 
113  void sortByMass();
114 
120  void renormalize();
121 
129  void merge(double resolution, double min_prob);
130 
139  void trimRight(double cutoff);
140 
149  void trimLeft(double cutoff);
150 
152  double averageMass() const;
154 
156 
157  IsotopeDistribution & operator=(const IsotopeDistribution & isotope_distribution);
159 
161  bool operator==(const IsotopeDistribution & isotope_distribution) const;
162 
164  bool operator!=(const IsotopeDistribution & isotope_distribution) const;
165 
167  bool operator<(const IsotopeDistribution & isotope_distribution) const;
169 
171 
172  inline Iterator begin() { return distribution_.begin(); }
173 
174  inline Iterator end() { return distribution_.end(); }
175 
176  inline ConstIterator begin() const { return distribution_.begin(); }
177 
178  inline ConstIterator end() const { return distribution_.end(); }
179 
180  inline ReverseIterator rbegin() { return distribution_.rbegin(); }
181 
182  inline ReverseIterator rend() { return distribution_.rend(); }
183 
184  inline ConstReverseIterator rbegin() const { return distribution_.rbegin(); }
185 
186  inline ConstReverseIterator rend() const { return distribution_.rend(); }
187 
188  inline void insert(const Peak1D::CoordinateType& mass, const Peak1D::IntensityType& intensity)
189  {
190  distribution_.push_back(Peak1D(mass, intensity));
191  }
193 
195 
196  Peak1D& operator[](const Size& index){ return distribution_[index];}
199  const Peak1D& operator[](const Size& index) const { return distribution_[index]; }
201 
202 protected:
203 
205  void sort_(std::function<bool(const MassAbundance& p1, const MassAbundance& p2)> sorter);
206 
208  void transform_(std::function<void(MassAbundance&)> lambda);
209 
212  };
213 
214 
215 } // namespace OpenMS
216 
Definition: IsotopeDistribution.h:39
void sort_(std::function< bool(const MassAbundance &p1, const MassAbundance &p2)> sorter)
sort wrapper of the distribution
ContainerType::const_iterator ConstIterator
Definition: IsotopeDistribution.h:50
ConstReverseIterator rend() const
Definition: IsotopeDistribution.h:186
ContainerType::reverse_iterator ReverseIterator
Definition: IsotopeDistribution.h:53
ContainerType distribution_
stores the isotope distribution
Definition: IsotopeDistribution.h:211
ContainerType::reverse_iterator reverse_iterator
Definition: IsotopeDistribution.h:52
ContainerType::const_reverse_iterator ConstReverseIterator
Definition: IsotopeDistribution.h:55
ConstIterator end() const
Definition: IsotopeDistribution.h:178
ContainerType::iterator Iterator
Definition: IsotopeDistribution.h:48
ContainerType::iterator iterator
Definition: IsotopeDistribution.h:47
void transform_(std::function< void(MassAbundance &)> lambda)
takes a function as a parameter to transform the distribution
ConstReverseIterator rbegin() const
Definition: IsotopeDistribution.h:184
void insert(const Peak1D::CoordinateType &mass, const Peak1D::IntensityType &intensity)
Definition: IsotopeDistribution.h:188
ReverseIterator rend()
Definition: IsotopeDistribution.h:182
Iterator end()
Definition: IsotopeDistribution.h:174
std::vector< MassAbundance > ContainerType
Definition: IsotopeDistribution.h:46
const Peak1D & operator[](const Size &index) const
const operator to access a cell of the distribution and wraps it in SpectrumFragment struct
Definition: IsotopeDistribution.h:199
ContainerType::const_iterator const_iterator
Definition: IsotopeDistribution.h:49
ConstIterator begin() const
Definition: IsotopeDistribution.h:176
Sorted
Definition: IsotopeDistribution.h:58
@ INTENSITY
Definition: IsotopeDistribution.h:58
ReverseIterator rbegin()
Definition: IsotopeDistribution.h:180
ContainerType::const_reverse_iterator const_reverse_iterator
Definition: IsotopeDistribution.h:54
IsotopeDistribution(const IsotopeDistribution &)=default
Copy constructor.
IsotopeDistribution(IsotopeDistribution &&) noexcept=default
Move constructor.
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
double CoordinateType
Coordinate type.
Definition: Peak1D.h:40
float IntensityType
Intensity type.
Definition: Peak1D.h:36
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22