OpenMS
BinnedSpectrum.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: Timo Sachsenberg, Mathias Walzer $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
14 
15 #include <cmath>
16 
17 // forward decl
18 namespace Eigen
19 {
20  template<typename _Scalar, int _Flags, typename _StorageIndex>
21  class SparseVector;
22 }
23 
24 namespace OpenMS
25 {
26 
54  class OPENMS_DLLAPI BinnedSpectrum
55  {
56  // smallest possible m/z value (needs to be >= 1)
57  static constexpr const float MIN_MZ_ = 1.0;
58 
59 public:
74  // default bin width for low-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
75  static constexpr const float DEFAULT_BIN_WIDTH_LOWRES = 1.0005f;
76 
77  // default bin width for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
78  static constexpr const float DEFAULT_BIN_WIDTH_HIRES = 0.02f;
79 
81  static constexpr const float DEFAULT_BIN_OFFSET_HIRES = 0.0f;
82 
84  static constexpr const float DEFAULT_BIN_OFFSET_LOWRES = 0.4f;
85 
88 
90  // static const SparseVectorType EmptySparseVector;
91 
93  // BinnedSpectrum() = delete;
95 
97  BinnedSpectrum(const PeakSpectrum& ps, float size, bool unit_ppm, UInt spread, float offset);
98 
101 
103  virtual ~BinnedSpectrum();
104 
107 
109  bool operator==(const BinnedSpectrum& rhs) const;
110 
112  bool operator!=(const BinnedSpectrum& rhs) const;
113 
115  float getBinIntensity(double mz);
116 
118  size_t getBinIndex(float mz) const;
119 
121  inline float getBinLowerMZ(size_t i) const
122  {
123  if (unit_ppm_)
124  {
125  // mz = MIN_MZ_ * (1.0 + bin_size_)^index for index
126  return float(MIN_MZ_ * pow(1.0 + bin_size_ * 1e-6, i));
127  }
128  else
129  {
130  return ((static_cast<float>(i) - offset_) * bin_size_);
131  }
132  }
133 
135  inline float getBinSize() const { return bin_size_; }
136 
138  inline size_t getBinSpread() const { return bin_spread_; }
139 
141  const SparseVectorType* getBins() const;
142 
145 
147  inline float getOffset() const { return offset_; }
148 
150  const std::vector<Precursor>& getPrecursors() const;
151 
153  std::vector<Precursor>& getPrecursors();
154 
156  // returns true if bin size, unit and offset are equal, otherwise false
157  static bool isCompatible(const BinnedSpectrum& a, const BinnedSpectrum& b);
158 
159 private:
161  UInt bin_spread_ {0};
162 
164  float bin_size_ {0};
165 
167  bool unit_ppm_ {false};
168 
170  float offset_ {0};
171 
173  SparseVectorType* bins_ {nullptr};
174 
176  void binSpectrum_(const PeakSpectrum& ps);
177 
179  std::vector<Precursor> precursors_;
180  };
181 
182 }
183 
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:55
const SparseVectorType * getBins() const
immutable access to the bin container
size_t getBinSpread() const
get the bin spread
Definition: BinnedSpectrum.h:138
BinnedSpectrum()
the empty SparseVector
Definition: BinnedSpectrum.h:94
BinnedSpectrum & operator=(const BinnedSpectrum &)
assignment operator
std::vector< Precursor > & getPrecursors()
mutable access to precursors
bool operator!=(const BinnedSpectrum &rhs) const
inequality operator
float getBinLowerMZ(size_t i) const
return the lower m/z of a bin given its index
Definition: BinnedSpectrum.h:121
float getBinIntensity(double mz)
returns the bin intensity at a given m/z position
bool operator==(const BinnedSpectrum &rhs) const
equality operator
BinnedSpectrum(const BinnedSpectrum &)
copy constructor
void binSpectrum_(const PeakSpectrum &ps)
calculate binning of peak spectrum
const std::vector< Precursor > & getPrecursors() const
immutable access to precursors
float getOffset() const
return offset
Definition: BinnedSpectrum.h:147
size_t getBinIndex(float mz) const
return the bin index of a given m/z position
std::vector< Precursor > precursors_
precursor information
Definition: BinnedSpectrum.h:179
static bool isCompatible(const BinnedSpectrum &a, const BinnedSpectrum &b)
Check if two BinnedSpectrum objects have equally sized bins and offset.
virtual ~BinnedSpectrum()
destructor
SparseVectorType * getBins()
mutable access to the bin container
BinnedSpectrum(const PeakSpectrum &ps, float size, bool unit_ppm, UInt spread, float offset)
detailed constructor
float getBinSize() const
get the bin size
Definition: BinnedSpectrum.h:135
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Definition: IsobaricIsotopeCorrector.h:15
Definition: BinnedSpectrum.h:21
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19