OpenMS
Loading...
Searching...
No Matches
BinnedSpectrum.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: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg, Mathias Walzer $
7// --------------------------------------------------------------------------
8//
9#pragma once
10
13
14#include <cmath>
15
16// forward decl
17namespace Eigen
18{
19 template<typename _Scalar, int _Flags, typename _StorageIndex>
21}
22
23namespace OpenMS
24{
25
53 class OPENMS_DLLAPI BinnedSpectrum
54 {
55 // smallest possible m/z value (needs to be >= 1)
56 static constexpr const float MIN_MZ_ = 1.0;
57
58public:
73 // default bin width for low-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
74 static constexpr const float DEFAULT_BIN_WIDTH_LOWRES = 1.0005f;
75
76 // default bin width for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x)
77 static constexpr const float DEFAULT_BIN_WIDTH_HIRES = 0.02f;
78
80 static constexpr const float DEFAULT_BIN_OFFSET_HIRES = 0.0f;
81
83 static constexpr const float DEFAULT_BIN_OFFSET_LOWRES = 0.4f;
84
87
89 // static const SparseVectorType EmptySparseVector;
90
92 // BinnedSpectrum() = delete;
94
96 BinnedSpectrum(const PeakSpectrum& ps, float size, bool unit_ppm, UInt spread, float offset);
97
100
103
106
108 bool operator==(const BinnedSpectrum& rhs) const;
109
111 bool operator!=(const BinnedSpectrum& rhs) const;
112
114 float getBinIntensity(double mz);
115
117 size_t getBinIndex(float mz) const;
118
120 inline float getBinLowerMZ(size_t i) const
121 {
122 if (unit_ppm_)
123 {
124 // mz = MIN_MZ_ * (1.0 + bin_size_)^index for index
125 return float(MIN_MZ_ * pow(1.0 + bin_size_ * 1e-6, i));
126 }
127 else
128 {
129 return ((static_cast<float>(i) - offset_) * bin_size_);
130 }
131 }
132
134 inline float getBinSize() const { return bin_size_; }
135
137 inline size_t getBinSpread() const { return bin_spread_; }
138
140 const SparseVectorType* getBins() const;
141
144
146 inline float getOffset() const { return offset_; }
147
149 const std::vector<Precursor>& getPrecursors() const;
150
152 std::vector<Precursor>& getPrecursors();
153
155 // returns true if bin size, unit and offset are equal, otherwise false
156 static bool isCompatible(const BinnedSpectrum& a, const BinnedSpectrum& b);
157
158private:
160 UInt bin_spread_ {0};
161
163 float bin_size_ {0};
164
166 bool unit_ppm_ {false};
167
169 float offset_ {0};
170
172 SparseVectorType* bins_ {nullptr};
173
175 void binSpectrum_(const PeakSpectrum& ps);
176
178 std::vector<Precursor> precursors_;
179 };
180
181}
182
This is a binned representation of a PeakSpectrum.
Definition BinnedSpectrum.h:54
std::vector< Precursor > & getPrecursors()
mutable access to precursors
const SparseVectorType * getBins() const
immutable access to the bin container
size_t getBinSpread() const
get the bin spread
Definition BinnedSpectrum.h:137
BinnedSpectrum()
the empty SparseVector
Definition BinnedSpectrum.h:93
const std::vector< Precursor > & getPrecursors() const
immutable 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:120
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
BinnedSpectrum & operator=(const BinnedSpectrum &)
assignment operator
SparseVectorType * getBins()
mutable access to the bin container
void binSpectrum_(const PeakSpectrum &ps)
calculate binning of peak spectrum
float getOffset() const
return offset
Definition BinnedSpectrum.h:146
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:178
static bool isCompatible(const BinnedSpectrum &a, const BinnedSpectrum &b)
Check if two BinnedSpectrum objects have equally sized bins and offset.
virtual ~BinnedSpectrum()
destructor
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:134
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
Definition BinnedSpectrum.h:18
Definition BinnedSpectrum.h:20
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19