OpenMS
IsotopeDistribution.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: Chris Bielow $
32 // $Authors: Clemens Groepl, Andreas Bertsch, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/KERNEL/Peak1D.h>
38 #include <functional>
39 #include <vector>
40 
41 namespace OpenMS
42 {
62  class Element;
63 
64  class OPENMS_DLLAPI IsotopeDistribution
65  {
66 public:
67 
69 
70  typedef Peak1D MassAbundance;
72  typedef std::vector<MassAbundance> ContainerType;
73  typedef ContainerType::iterator iterator;
74  typedef ContainerType::iterator Iterator;
75  typedef ContainerType::const_iterator const_iterator;
76  typedef ContainerType::const_iterator ConstIterator;
77 
78  typedef ContainerType::reverse_iterator reverse_iterator;
79  typedef ContainerType::reverse_iterator ReverseIterator;
80  typedef ContainerType::const_reverse_iterator const_reverse_iterator;
81  typedef ContainerType::const_reverse_iterator ConstReverseIterator;
83 
84  enum Sorted {INTENSITY, MASS, UNDEFINED};
85 
87 
88 
91 
94 
97 
99  virtual ~IsotopeDistribution() = default;
101 
103 
104 
106  void set(const ContainerType & distribution);
107 
109  void set(ContainerType && distribution);
110 
112  const ContainerType & getContainer() const;
113 
115  Peak1D::CoordinateType getMax() const;
116 
118  Peak1D::CoordinateType getMin() const;
119 
121  Peak1D getMostAbundant() const;
122 
124  Size size() const;
125 
127  void clear();
128 
129  // resizes distribution container
130  void resize(UInt size);
131 
133  void trimIntensities(double cutoff);
134 
136  void sortByIntensity();
137 
139  void sortByMass();
140 
146  void renormalize();
147 
155  void merge(double resolution, double min_prob);
156 
165  void trimRight(double cutoff);
166 
175  void trimLeft(double cutoff);
176 
178  double averageMass() const;
180 
182 
183  IsotopeDistribution & operator=(const IsotopeDistribution & isotope_distribution);
185 
187  bool operator==(const IsotopeDistribution & isotope_distribution) const;
188 
190  bool operator!=(const IsotopeDistribution & isotope_distribution) const;
191 
193  bool operator<(const IsotopeDistribution & isotope_distribution) const;
195 
197 
198  inline Iterator begin() { return distribution_.begin(); }
199 
200  inline Iterator end() { return distribution_.end(); }
201 
202  inline ConstIterator begin() const { return distribution_.begin(); }
203 
204  inline ConstIterator end() const { return distribution_.end(); }
205 
206  inline ReverseIterator rbegin() { return distribution_.rbegin(); }
207 
208  inline ReverseIterator rend() { return distribution_.rend(); }
209 
210  inline ConstReverseIterator rbegin() const { return distribution_.rbegin(); }
211 
212  inline ConstReverseIterator rend() const { return distribution_.rend(); }
213 
214  inline void insert(const Peak1D::CoordinateType& mass, const Peak1D::IntensityType& intensity)
215  {
216  distribution_.push_back(Peak1D(mass, intensity));
217  }
219 
221 
222  Peak1D& operator[](const Size& index){ return distribution_[index];}
225  const Peak1D& operator[](const Size& index) const { return distribution_[index]; }
227 
228 protected:
229 
231  void sort_(std::function<bool(const MassAbundance& p1, const MassAbundance& p2)> sorter);
232 
234  void transform_(std::function<void(MassAbundance&)> lambda);
235 
238  };
239 
240 
241 } // namespace OpenMS
242 
Definition: IsotopeDistribution.h:65
void sort_(std::function< bool(const MassAbundance &p1, const MassAbundance &p2)> sorter)
sort wrapper of the distribution
ContainerType::const_iterator ConstIterator
Definition: IsotopeDistribution.h:76
ConstReverseIterator rend() const
Definition: IsotopeDistribution.h:212
ContainerType::reverse_iterator ReverseIterator
Definition: IsotopeDistribution.h:79
ContainerType distribution_
stores the isotope distribution
Definition: IsotopeDistribution.h:237
ContainerType::reverse_iterator reverse_iterator
Definition: IsotopeDistribution.h:78
ContainerType::const_reverse_iterator ConstReverseIterator
Definition: IsotopeDistribution.h:81
ConstIterator end() const
Definition: IsotopeDistribution.h:204
ContainerType::iterator Iterator
Definition: IsotopeDistribution.h:74
ContainerType::iterator iterator
Definition: IsotopeDistribution.h:73
void transform_(std::function< void(MassAbundance &)> lambda)
takes a function as a parameter to transform the distribution
ConstReverseIterator rbegin() const
Definition: IsotopeDistribution.h:210
void insert(const Peak1D::CoordinateType &mass, const Peak1D::IntensityType &intensity)
Definition: IsotopeDistribution.h:214
ReverseIterator rend()
Definition: IsotopeDistribution.h:208
Iterator end()
Definition: IsotopeDistribution.h:200
std::vector< MassAbundance > ContainerType
Definition: IsotopeDistribution.h:72
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:225
ContainerType::const_iterator const_iterator
Definition: IsotopeDistribution.h:75
ConstIterator begin() const
Definition: IsotopeDistribution.h:202
Sorted
Definition: IsotopeDistribution.h:84
@ INTENSITY
Definition: IsotopeDistribution.h:84
ReverseIterator rbegin()
Definition: IsotopeDistribution.h:206
ContainerType::const_reverse_iterator const_reverse_iterator
Definition: IsotopeDistribution.h:80
IsotopeDistribution(const IsotopeDistribution &)=default
Copy constructor.
IsotopeDistribution(IsotopeDistribution &&) noexcept=default
Move constructor.
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
double CoordinateType
Coordinate type.
Definition: Peak1D.h:66
float IntensityType
Intensity type.
Definition: Peak1D.h:62
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48