OpenMS  2.8.0
BinnedSpectrum.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-2021.
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: Timo Sachsenberg $
32 // $Authors: Timo Sachsenberg, Mathias Walzer $
33 // --------------------------------------------------------------------------
34 //
35 #pragma once
36 
40 
41 #include <cmath>
42 
43 // forward decl
44 namespace Eigen
45 {
46  template<typename _Scalar, int _Flags, typename _StorageIndex>
47  class SparseVector;
48 }
49 
50 namespace OpenMS
51 {
52 
80  class OPENMS_DLLAPI BinnedSpectrum
81  {
82  // smallest possible m/z value (needs to be >= 1)
83  static constexpr const float MIN_MZ_ = 1.0;
84 
85 public:
100  // default bin width for low-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
101  static constexpr const float DEFAULT_BIN_WIDTH_LOWRES = 1.0005f;
102 
103  // default bin width for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
104  static constexpr const float DEFAULT_BIN_WIDTH_HIRES = 0.02f;
105 
107  static constexpr const float DEFAULT_BIN_OFFSET_HIRES = 0.0f;
108 
110  static constexpr const float DEFAULT_BIN_OFFSET_LOWRES = 0.4f;
111 
114 
116  // static const SparseVectorType EmptySparseVector;
117 
119  // BinnedSpectrum() = delete;
121 
123  BinnedSpectrum(const PeakSpectrum& ps, float size, bool unit_ppm, UInt spread, float offset);
124 
127 
129  virtual ~BinnedSpectrum();
130 
133 
135  bool operator==(const BinnedSpectrum& rhs) const;
136 
138  bool operator!=(const BinnedSpectrum& rhs) const;
139 
141  float getBinIntensity(double mz);
142 
144  size_t getBinIndex(float mz) const;
145 
147  inline float getBinLowerMZ(size_t i) const
148  {
149  if (unit_ppm_)
150  {
151  // mz = MIN_MZ_ * (1.0 + bin_size_)^index for index
152  return (MIN_MZ_ * pow(1.0 + bin_size_ * 1e-6, i));
153  }
154  else
155  {
156  return ((static_cast<float>(i) - offset_) * bin_size_);
157  }
158  }
159 
161  inline float getBinSize() const { return bin_size_; }
162 
164  inline size_t getBinSpread() const { return bin_spread_; }
165 
167  const SparseVectorType* getBins() const;
168 
171 
173  inline float getOffset() const { return offset_; }
174 
176  const std::vector<Precursor>& getPrecursors() const;
177 
179  std::vector<Precursor>& getPrecursors();
180 
182  // returns true if bin size, unit and offset are equal, otherwise false
183  static bool isCompatible(const BinnedSpectrum& a, const BinnedSpectrum& b);
184 
185 private:
188 
190  float bin_size_;
191 
193  bool unit_ppm_;
194 
196  float offset_;
197 
200 
202  void binSpectrum_(const PeakSpectrum& ps);
203 
205  std::vector<Precursor> precursors_;
206  };
207 
208 }
209 
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:81
const SparseVectorType * getBins() const
immutable access to the bin container
float bin_size_
the size of each bin
Definition: BinnedSpectrum.h:190
size_t getBinSpread() const
get the bin spread
Definition: BinnedSpectrum.h:164
float offset_
offset of bin start
Definition: BinnedSpectrum.h:196
BinnedSpectrum()
the empty SparseVector
Definition: BinnedSpectrum.h:120
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:147
float getBinIntensity(double mz)
returns the bin intensity at a given m/z position
bool operator==(const BinnedSpectrum &rhs) const
equality operator
SparseVectorType * bins_
bins
Definition: BinnedSpectrum.h:199
BinnedSpectrum(const BinnedSpectrum &)
copy constructor
UInt bin_spread_
the spread to left or right
Definition: BinnedSpectrum.h:187
void binSpectrum_(const PeakSpectrum &ps)
calculate binning of peak spectrum
bool unit_ppm_
absolute bin size or relative bin size
Definition: BinnedSpectrum.h:193
const std::vector< Precursor > & getPrecursors() const
immutable access to precursors
float getOffset() const
return offset
Definition: BinnedSpectrum.h:173
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:205
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:161
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
Definition: IsobaricIsotopeCorrector.h:41
Definition: BinnedSpectrum.h:47
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47