OpenMS  2.4.0
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-2018.
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 #ifndef OPENMS_CHEMISTRY_ISOTOPEDISTRIBUTION_ISOTOPEDISTRIBUTION_H
36 #define OPENMS_CHEMISTRY_ISOTOPEDISTRIBUTION_ISOTOPEDISTRIBUTION_H
37 
38 
40 #include <OpenMS/KERNEL/Peak1D.h>
41 
42 #include <utility>
43 #include <functional>
44 
45 #include <vector>
46 #include <set>
47 #include <map>
48 
49 
50 namespace OpenMS
51 {
70  class Element;
71 
72  class OPENMS_DLLAPI IsotopeDistribution
73  {
74 public:
75 
77 
78  typedef Peak1D MassAbundance;
80  typedef std::vector<MassAbundance> ContainerType;
81  typedef ContainerType::iterator iterator;
82  typedef ContainerType::iterator Iterator;
83  typedef ContainerType::const_iterator const_iterator;
84  typedef ContainerType::const_iterator ConstIterator;
85 
86  typedef ContainerType::reverse_iterator reverse_iterator;
87  typedef ContainerType::reverse_iterator ReverseIterator;
88  typedef ContainerType::const_reverse_iterator const_reverse_iterator;
89  typedef ContainerType::const_reverse_iterator ConstReverseIterator;
91 
92  enum Sorted {INTENSITY, MASS, UNDEFINED};
93 
95 
96 
99 
101  IsotopeDistribution(const IsotopeDistribution & isotope_distribution) = default;
102 
104  IsotopeDistribution(IsotopeDistribution&&) noexcept = default;
105 
107  virtual ~IsotopeDistribution() = default;
109 
111 
112 
114  void set(const ContainerType & distribution);
115 
116  void set(ContainerType && distribution);
117 
119  const ContainerType & getContainer() const;
120 
122  Peak1D::CoordinateType getMax() const;
123 
125  Peak1D::CoordinateType getMin() const;
126 
128  Peak1D getMostAbundant() const;
129 
131  Size size() const;
132 
134  void clear();
135 
136  // resizes distribution container
137  void resize(UInt size);
138 
140  void trimIntensities(double cutoff);
141 
143  void sortByIntensity();
144 
146  void sortByMass();
147 
153  void renormalize();
154 
162  void merge(double resolution, double min_prob);
163 
172  void trimRight(double cutoff);
173 
182  void trimLeft(double cutoff);
183 
185  double averageMass() const;
187 
189 
190  IsotopeDistribution & operator=(const IsotopeDistribution & isotope_distribution);
192 
194  bool operator==(const IsotopeDistribution & isotope_distribution) const;
195 
197  bool operator!=(const IsotopeDistribution & isotope_distribution) const;
198 
200  bool operator<(const IsotopeDistribution & isotope_distribution) const;
202 
204 
205  inline Iterator begin() { return distribution_.begin(); }
206 
207  inline Iterator end() { return distribution_.end(); }
208 
209  inline ConstIterator begin() const { return distribution_.begin(); }
210 
211  inline ConstIterator end() const { return distribution_.end(); }
212 
213  inline ReverseIterator rbegin() { return distribution_.rbegin(); }
214 
215  inline ReverseIterator rend() { return distribution_.rend(); }
216 
217  inline ConstReverseIterator rbegin() const { return distribution_.rbegin(); }
218 
219  inline ConstReverseIterator rend() const { return distribution_.rend(); }
220 
221  inline void insert(const Peak1D::CoordinateType& mass, const Peak1D::IntensityType& intensity)
222  {
223  distribution_.push_back(Peak1D(mass, intensity));
224  }
226 
228 
229  Peak1D& operator[](const Size& index){ return distribution_[index];}
231 
233 
234 
235 protected:
236 
238  void sort_(std::function<bool(const MassAbundance& p1, const MassAbundance& p2)> sorter);
240  void transform_(std::function<void(MassAbundance&)> lambda);
241 
244  };
245 
246 
247 } // namespace OpenMS
248 
249 #endif // OPENMS_CHEMISTRY_ISOTOPEDISTRIBUTION_ISOTOPEDISTRIBUTION_H
Sorted
Definition: IsotopeDistribution.h:92
ContainerType::iterator Iterator
Definition: IsotopeDistribution.h:82
ContainerType::reverse_iterator reverse_iterator
Definition: IsotopeDistribution.h:86
ReverseIterator rbegin()
Definition: IsotopeDistribution.h:213
Iterator end()
Definition: IsotopeDistribution.h:207
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
Definition: IsotopeDistribution.h:72
ContainerType::iterator iterator
Definition: IsotopeDistribution.h:81
std::vector< MassAbundance > ContainerType
Definition: IsotopeDistribution.h:80
ReverseIterator rend()
Definition: IsotopeDistribution.h:215
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
ContainerType::reverse_iterator ReverseIterator
Definition: IsotopeDistribution.h:87
void insert(const Peak1D::CoordinateType &mass, const Peak1D::IntensityType &intensity)
Definition: IsotopeDistribution.h:221
ContainerType::const_reverse_iterator const_reverse_iterator
Definition: IsotopeDistribution.h:88
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
Iterator begin()
Definition: IsotopeDistribution.h:205
ConstReverseIterator rbegin() const
Definition: IsotopeDistribution.h:217
ConstReverseIterator rend() const
Definition: IsotopeDistribution.h:219
ContainerType::const_iterator const_iterator
Definition: IsotopeDistribution.h:83
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
ConstIterator begin() const
Definition: IsotopeDistribution.h:209
ContainerType distribution_
stores the isotope distribution
Definition: IsotopeDistribution.h:243
ConstIterator end() const
Definition: IsotopeDistribution.h:211
ContainerType::const_iterator ConstIterator
Definition: IsotopeDistribution.h:84
ContainerType::const_reverse_iterator ConstReverseIterator
Definition: IsotopeDistribution.h:89