OpenMS
Loading...
Searching...
No Matches
IsotopeDistribution.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: Chris Bielow $
6// $Authors: Clemens Groepl, Andreas Bertsch, Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13#include <functional>
14#include <vector>
15
16namespace OpenMS
17{
37 class Element;
38
39 class OPENMS_DLLAPI IsotopeDistribution
40 {
41public:
42
44
45
47 typedef std::vector<MassAbundance> ContainerType;
48 typedef ContainerType::iterator iterator;
49 typedef ContainerType::iterator Iterator;
50 typedef ContainerType::const_iterator const_iterator;
51 typedef ContainerType::const_iterator ConstIterator;
52
53 typedef ContainerType::reverse_iterator reverse_iterator;
54 typedef ContainerType::reverse_iterator ReverseIterator;
55 typedef ContainerType::const_reverse_iterator const_reverse_iterator;
56 typedef ContainerType::const_reverse_iterator ConstReverseIterator;
58
59 enum Sorted {INTENSITY, MASS, UNDEFINED};
60
62
63
66
69
72
74 virtual ~IsotopeDistribution() = default;
76
78
79
81 void set(const ContainerType & distribution);
82
84 void set(ContainerType && distribution);
85
87 const ContainerType & getContainer() const;
88
90 Peak1D::CoordinateType getMax() const;
91
93 Peak1D::CoordinateType getMin() const;
94
96 Peak1D getMostAbundant() const;
97
99 Size size() const;
100
102 void clear();
103
104 // resizes distribution container
105 void resize(UInt size);
106
108 void trimIntensities(double cutoff);
109
111 void sortByIntensity();
112
114 void sortByMass();
115
121 void renormalize();
122
130 void merge(double resolution, double min_prob);
131
140 void trimRight(double cutoff);
141
150 void trimLeft(double cutoff);
151
153 double averageMass() const;
155
157
158
159 IsotopeDistribution & operator=(const IsotopeDistribution & isotope_distribution);
160
162 bool operator==(const IsotopeDistribution & isotope_distribution) const;
163
165 bool operator!=(const IsotopeDistribution & isotope_distribution) const;
166
168 bool operator<(const IsotopeDistribution & isotope_distribution) const;
170
172
173 inline Iterator begin() { return distribution_.begin(); }
174
175 inline Iterator end() { return distribution_.end(); }
176
177 inline ConstIterator begin() const { return distribution_.begin(); }
178
179 inline ConstIterator end() const { return distribution_.end(); }
180
181 inline ReverseIterator rbegin() { return distribution_.rbegin(); }
182
183 inline ReverseIterator rend() { return distribution_.rend(); }
184
185 inline ConstReverseIterator rbegin() const { return distribution_.rbegin(); }
186
187 inline ConstReverseIterator rend() const { return distribution_.rend(); }
188
189 inline void insert(const Peak1D::CoordinateType& mass, const Peak1D::IntensityType& intensity)
190 {
191 distribution_.push_back(Peak1D(mass, intensity));
192 }
194
196
197
198 Peak1D& operator[](const Size& index){ return distribution_[index];}
200 const Peak1D& operator[](const Size& index) const { return distribution_[index]; }
202
203protected:
204
206 void sort_(std::function<bool(const MassAbundance& p1, const MassAbundance& p2)> sorter);
207
209 void transform_(std::function<void(MassAbundance&)> lambda);
210
213 };
214
215
216} // namespace OpenMS
217
218// Hash function specialization for IsotopeDistribution
219namespace std
220{
221 template<>
222 struct hash<OpenMS::IsotopeDistribution>
223 {
224 std::size_t operator()(const OpenMS::IsotopeDistribution& id) const noexcept
225 {
226 std::size_t seed = OpenMS::hash_int(id.size());
227 for (const auto& peak : id)
228 {
229 OpenMS::hash_combine(seed, std::hash<OpenMS::Peak1D>{}(peak));
230 }
231 return seed;
232 }
233 };
234} // namespace std
235
Definition IsotopeDistribution.h:40
void sort_(std::function< bool(const MassAbundance &p1, const MassAbundance &p2)> sorter)
sort wrapper of the distribution
ContainerType::const_iterator ConstIterator
Definition IsotopeDistribution.h:51
ConstReverseIterator rend() const
Definition IsotopeDistribution.h:187
ContainerType::reverse_iterator ReverseIterator
Definition IsotopeDistribution.h:54
ContainerType distribution_
stores the isotope distribution
Definition IsotopeDistribution.h:212
ContainerType::reverse_iterator reverse_iterator
Definition IsotopeDistribution.h:53
ContainerType::const_reverse_iterator ConstReverseIterator
Definition IsotopeDistribution.h:56
ConstIterator end() const
Definition IsotopeDistribution.h:179
ContainerType::iterator Iterator
Definition IsotopeDistribution.h:49
ContainerType::iterator iterator
Definition IsotopeDistribution.h:48
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:200
void transform_(std::function< void(MassAbundance &)> lambda)
takes a function as a parameter to transform the distribution
Peak1D MassAbundance
container type, first holds the weight of the isotope, second the probability
Definition IsotopeDistribution.h:46
ConstReverseIterator rbegin() const
Definition IsotopeDistribution.h:185
void insert(const Peak1D::CoordinateType &mass, const Peak1D::IntensityType &intensity)
Definition IsotopeDistribution.h:189
ReverseIterator rend()
Definition IsotopeDistribution.h:183
Iterator end()
Definition IsotopeDistribution.h:175
std::vector< MassAbundance > ContainerType
Definition IsotopeDistribution.h:47
ContainerType::const_iterator const_iterator
Definition IsotopeDistribution.h:50
ConstIterator begin() const
Definition IsotopeDistribution.h:177
Sorted
Definition IsotopeDistribution.h:59
@ INTENSITY
Definition IsotopeDistribution.h:59
Peak1D & operator[](const Size &index)
operator to access a cell of the distribution and wraps it in SpectrumFragment struct
Definition IsotopeDistribution.h:198
ReverseIterator rbegin()
Definition IsotopeDistribution.h:181
ContainerType::const_reverse_iterator const_reverse_iterator
Definition IsotopeDistribution.h:55
IsotopeDistribution(const IsotopeDistribution &)=default
Copy constructor.
IsotopeDistribution(IsotopeDistribution &&) noexcept=default
Move constructor.
A 1-dimensional raw data point or peak.
Definition Peak1D.h:30
double CoordinateType
Coordinate type.
Definition Peak1D.h:42
float IntensityType
Intensity type.
Definition Peak1D.h:38
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
STL namespace.
std::size_t operator()(const OpenMS::IsotopeDistribution &id) const noexcept
Definition IsotopeDistribution.h:224