OpenMS
IMSIsotopeDistribution.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Anton Pervukhin <Anton.Pervukhin@CeBiTec.Uni-Bielefeld.DE> $
7 // --------------------------------------------------------------------------
8 //
9 
10 #pragma once
11 
12 #include <algorithm> // std::min
13 #include <vector>
14 #include <iosfwd>
15 
16 #include <OpenMS/config.h>
17 
18 namespace OpenMS
19 {
20 
21  namespace ims
22  {
23 
61  class OPENMS_DLLAPI IMSIsotopeDistribution
62  {
63 
64 public:
66  typedef double mass_type;
67 
69  typedef double abundance_type;
70 
72  typedef unsigned int nominal_mass_type;
73 
75  struct Peak
76  {
77  Peak(mass_type local_mass = 0.0, abundance_type local_abundance = 0.0) :
78  mass(local_mass), abundance(local_abundance)
79  {}
80 
81  bool operator==(const Peak & peak) const
82  {
83 #pragma clang diagnostic push
84 #pragma clang diagnostic ignored "-Wfloat-equal"
85  return peak.mass == mass && peak.abundance == abundance;
86 #pragma clang diagnostic pop
87  }
88 
91  };
92 
94  typedef Peak peak_type;
95 
97  typedef std::vector<peak_type> peaks_container;
98 
100  typedef peaks_container::iterator peaks_iterator;
101 
103  typedef peaks_container::const_iterator const_peaks_iterator;
104 
106  typedef peaks_container::size_type size_type;
107 
109  typedef std::vector<mass_type> masses_container;
110 
112  typedef masses_container::iterator masses_iterator;
113 
115  typedef masses_container::const_iterator const_masses_iterator;
116 
118  typedef std::vector<abundance_type> abundances_container;
119 
121  typedef abundances_container::iterator abundances_iterator;
122 
124  typedef abundances_container::const_iterator const_abundances_iterator;
125 
128 
130  static size_type SIZE;
131 
133  explicit IMSIsotopeDistribution(nominal_mass_type nominalMass = 0) :
134  nominal_mass_(nominalMass)
135  {}
136 
139  nominal_mass_(0)
140  {
141  peaks_.push_back(peaks_container::value_type(mass, 1.0));
142  }
143 
146  nominal_mass_type nominalMass = 0) :
147  peaks_(peaks),
148  nominal_mass_(nominalMass)
149  {}
150 
153  peaks_(distribution.peaks_),
154  nominal_mass_(distribution.nominal_mass_)
155  {}
156 
159  {}
160 
167  size_type size() const { return std::min(peaks_.size(), SIZE); }
168 
176  const IMSIsotopeDistribution & distribution);
177 
185  bool operator==(const IMSIsotopeDistribution & distribution) const;
186 
194  bool operator!=(const IMSIsotopeDistribution & distribution) const;
195 
207  const IMSIsotopeDistribution & distribution);
208 
219  IMSIsotopeDistribution & operator*=(unsigned int pow);
220 
228  {
229  return peaks_[i].mass + nominal_mass_ + i;
230  }
231 
239  {
240  return peaks_[i].abundance;
241  }
242 
249 
255  nominal_mass_type getNominalMass() const { return nominal_mass_; }
256 
263  {
264  this->nominal_mass_ = nominalMass;
265  }
266 
273 
280 
286  void normalize();
287 
293  bool empty() const { return peaks_.empty(); }
294 
295 private:
298 
301 
304  };
305 
312  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os,
313  const IMSIsotopeDistribution & distribution);
314 
315  } // namespace ims
316 } // namespace OpenMS
317 
Represents a distribution of isotopes restricted to the first K elements.
Definition: IMSIsotopeDistribution.h:62
masses_container getMasses() const
IMSIsotopeDistribution & operator*=(unsigned int pow)
peaks_container peaks_
Container for isotopes.
Definition: IMSIsotopeDistribution.h:297
void setMinimumSize_()
Sets peaks/isotopes container minimum size.
std::vector< peak_type > peaks_container
Type of container to store peaks.
Definition: IMSIsotopeDistribution.h:97
bool operator!=(const IMSIsotopeDistribution &distribution) const
nominal_mass_type nominal_mass_
Nominal mass of distribution.
Definition: IMSIsotopeDistribution.h:300
IMSIsotopeDistribution(nominal_mass_type nominalMass=0)
Constructor with nominal mass.
Definition: IMSIsotopeDistribution.h:133
IMSIsotopeDistribution(const peaks_container &peaks, nominal_mass_type nominalMass=0)
Constructor with isotopes and nominal mass.
Definition: IMSIsotopeDistribution.h:145
nominal_mass_type getNominalMass() const
Definition: IMSIsotopeDistribution.h:255
IMSIsotopeDistribution & operator=(const IMSIsotopeDistribution &distribution)
double abundance_type
Type of isotope abundance.
Definition: IMSIsotopeDistribution.h:69
IMSIsotopeDistribution(mass_type mass)
Constructor with single isotope.
Definition: IMSIsotopeDistribution.h:138
size_type size() const
Definition: IMSIsotopeDistribution.h:167
std::vector< abundance_type > abundances_container
Type of container with isotope abundances.
Definition: IMSIsotopeDistribution.h:118
bool empty() const
Definition: IMSIsotopeDistribution.h:293
abundances_container getAbundances() const
IMSIsotopeDistribution & operator*=(const IMSIsotopeDistribution &distribution)
peaks_container::size_type size_type
Type of peaks container's size.
Definition: IMSIsotopeDistribution.h:106
peaks_container::iterator peaks_iterator
Type of iterator over container with peaks.
Definition: IMSIsotopeDistribution.h:100
static size_type SIZE
Length of isotope distribution.
Definition: IMSIsotopeDistribution.h:130
~IMSIsotopeDistribution()
Destructor.
Definition: IMSIsotopeDistribution.h:158
bool operator==(const IMSIsotopeDistribution &distribution) const
Peak peak_type
Type of isotope peak.
Definition: IMSIsotopeDistribution.h:94
IMSIsotopeDistribution(const IMSIsotopeDistribution &distribution)
Copy constructor.
Definition: IMSIsotopeDistribution.h:152
abundance_type getAbundance(size_type i) const
Definition: IMSIsotopeDistribution.h:238
mass_type getMass(size_type i) const
Definition: IMSIsotopeDistribution.h:227
abundances_container::iterator abundances_iterator
Type of iterator over container with isotope abundances.
Definition: IMSIsotopeDistribution.h:121
masses_container::const_iterator const_masses_iterator
Type of const iterator over container with isotope masses.
Definition: IMSIsotopeDistribution.h:115
abundances_container::const_iterator const_abundances_iterator
Type of const iterator over container with isotope abundances.
Definition: IMSIsotopeDistribution.h:124
peaks_container::const_iterator const_peaks_iterator
Type of const iterator over container with peaks.
Definition: IMSIsotopeDistribution.h:103
std::vector< mass_type > masses_container
Type of container with isotope masses.
Definition: IMSIsotopeDistribution.h:109
masses_container::iterator masses_iterator
Type of iterator over container with isotope masses.
Definition: IMSIsotopeDistribution.h:112
double mass_type
Type of isotope mass.
Definition: IMSIsotopeDistribution.h:66
static abundance_type ABUNDANCES_SUM_ERROR
Error to be allowed for isotope distribution.
Definition: IMSIsotopeDistribution.h:127
void setNominalMass(nominal_mass_type nominalMass)
Definition: IMSIsotopeDistribution.h:262
unsigned int nominal_mass_type
Type of isotope nominal mass.
Definition: IMSIsotopeDistribution.h:72
std::ostream & operator<<(std::ostream &os, const IMSAlphabet &alphabet)
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Structure that represents an isotope peak - pair of mass and abundance.
Definition: IMSIsotopeDistribution.h:76
Peak(mass_type local_mass=0.0, abundance_type local_abundance=0.0)
Definition: IMSIsotopeDistribution.h:77
abundance_type abundance
Definition: IMSIsotopeDistribution.h:90
bool operator==(const Peak &peak) const
Definition: IMSIsotopeDistribution.h:81
mass_type mass
Definition: IMSIsotopeDistribution.h:89