OpenMS
BinnedSpectrum Class Reference

This is a binned representation of a PeakSpectrum. More...

#include <OpenMS/COMPARISON/SPECTRA/BinnedSpectrum.h>

Collaboration diagram for BinnedSpectrum:
[legend]

Public Types

using SparseVectorType = Eigen::SparseVector< float, 0, int >
 typedef for the underlying sparse vector More...
 

Public Member Functions

 BinnedSpectrum ()
 the empty SparseVector More...
 
 BinnedSpectrum (const PeakSpectrum &ps, float size, bool unit_ppm, UInt spread, float offset)
 detailed constructor More...
 
 BinnedSpectrum (const BinnedSpectrum &)
 copy constructor More...
 
virtual ~BinnedSpectrum ()
 destructor More...
 
BinnedSpectrumoperator= (const BinnedSpectrum &)
 assignment operator More...
 
bool operator== (const BinnedSpectrum &rhs) const
 equality operator More...
 
bool operator!= (const BinnedSpectrum &rhs) const
 inequality operator More...
 
float getBinIntensity (double mz)
 returns the bin intensity at a given m/z position More...
 
size_t getBinIndex (float mz) const
 return the bin index of a given m/z position More...
 
float getBinLowerMZ (size_t i) const
 return the lower m/z of a bin given its index More...
 
float getBinSize () const
 get the bin size More...
 
size_t getBinSpread () const
 get the bin spread More...
 
const SparseVectorTypegetBins () const
 immutable access to the bin container More...
 
SparseVectorTypegetBins ()
 mutable access to the bin container More...
 
float getOffset () const
 return offset More...
 
const std::vector< Precursor > & getPrecursors () const
 immutable access to precursors More...
 
std::vector< Precursor > & getPrecursors ()
 mutable access to precursors More...
 

Static Public Member Functions

static bool isCompatible (const BinnedSpectrum &a, const BinnedSpectrum &b)
 Check if two BinnedSpectrum objects have equally sized bins and offset. More...
 

Static Public Attributes

static constexpr const float DEFAULT_BIN_WIDTH_LOWRES = 1.0005f
 
static constexpr const float DEFAULT_BIN_WIDTH_HIRES = 0.02f
 
static constexpr const float DEFAULT_BIN_OFFSET_HIRES = 0.0f
 default bin offset for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x) More...
 
static constexpr const float DEFAULT_BIN_OFFSET_LOWRES = 0.4f
 default bin offset for low-resolution data (adapted from doi:10.1007/s13361-015-1179-x) More...
 

Private Member Functions

void binSpectrum_ (const PeakSpectrum &ps)
 calculate binning of peak spectrum More...
 

Private Attributes

UInt bin_spread_ {0}
 the spread to left or right More...
 
float bin_size_ {0}
 the size of each bin More...
 
bool unit_ppm_ {false}
 absolute bin size or relative bin size More...
 
float offset_ {0}
 offset of bin start More...
 
SparseVectorTypebins_ {nullptr}
 bins More...
 
std::vector< Precursorprecursors_
 precursor information More...
 

Static Private Attributes

static constexpr const float MIN_MZ_ = 1.0
 

Detailed Description

This is a binned representation of a PeakSpectrum.

Parameters
szthe size of the bins and
spnumber of neighboring bins to both sides affected by a peak contribution
psthe PeakSpectrum, used to calculate the binned spectrum

sz denotes the size of a bin in Th, thereby deciding the number of bins (all of size sz) the spectrum is discretized to. Each bin will represent a certain Th range and the peaks will be put in the respective bins and sum up inside. sp denotes the number of neighboring bins to the left and the number of neighboring bins to the right a peak is also added to. E.g. a BinnedSpectrum with binsize of 0.5 Th will have a peak at 100 Th in bin no. 200, a peak at 100.1 Th will be in bin no. 201. If the binspread is 1, the peak at 100 Th will be added to bin no. 199, 200 and 201. If the binspread is 2, the peak at 100 Th will also be added to bin no. 198 and 202, and so on.

Many operations are provided by the underlying SparseVector implementation:

  • bin-wise addition (e.g.: c = a.getBins() + b.getBins())
  • bin-wise scaling (e.g.: c = a.getBins() * 5f)
  • to get the number of filled bins, call: getBins().nonZeros()
  • many more... See the Eigen SparseVector implementation for details.

Implementation detail: Eigen SparseVectors need to have the same dimensionality. EmptySparseVector provides an empty SparseVector with compatible dimension to perform all supported operations.

Member Typedef Documentation

◆ SparseVectorType

using SparseVectorType = Eigen::SparseVector<float, 0, int>

typedef for the underlying sparse vector

Constructor & Destructor Documentation

◆ BinnedSpectrum() [1/3]

BinnedSpectrum ( )
inline

the empty SparseVector

default constructor

◆ BinnedSpectrum() [2/3]

BinnedSpectrum ( const PeakSpectrum ps,
float  size,
bool  unit_ppm,
UInt  spread,
float  offset 
)

detailed constructor

◆ BinnedSpectrum() [3/3]

copy constructor

◆ ~BinnedSpectrum()

virtual ~BinnedSpectrum ( )
virtual

destructor

Member Function Documentation

◆ binSpectrum_()

void binSpectrum_ ( const PeakSpectrum ps)
private

calculate binning of peak spectrum

◆ getBinIndex()

size_t getBinIndex ( float  mz) const

return the bin index of a given m/z position

◆ getBinIntensity()

float getBinIntensity ( double  mz)

returns the bin intensity at a given m/z position

◆ getBinLowerMZ()

float getBinLowerMZ ( size_t  i) const
inline

return the lower m/z of a bin given its index

◆ getBins() [1/2]

SparseVectorType* getBins ( )

mutable access to the bin container

◆ getBins() [2/2]

const SparseVectorType* getBins ( ) const

immutable access to the bin container

◆ getBinSize()

float getBinSize ( ) const
inline

get the bin size

◆ getBinSpread()

size_t getBinSpread ( ) const
inline

get the bin spread

◆ getOffset()

float getOffset ( ) const
inline

return offset

◆ getPrecursors() [1/2]

std::vector<Precursor>& getPrecursors ( )

mutable access to precursors

◆ getPrecursors() [2/2]

const std::vector<Precursor>& getPrecursors ( ) const

immutable access to precursors

◆ isCompatible()

static bool isCompatible ( const BinnedSpectrum a,
const BinnedSpectrum b 
)
static

Check if two BinnedSpectrum objects have equally sized bins and offset.

◆ operator!=()

bool operator!= ( const BinnedSpectrum rhs) const

inequality operator

◆ operator=()

BinnedSpectrum& operator= ( const BinnedSpectrum )

assignment operator

◆ operator==()

bool operator== ( const BinnedSpectrum rhs) const

equality operator

Member Data Documentation

◆ bin_size_

float bin_size_ {0}
private

the size of each bin

◆ bin_spread_

UInt bin_spread_ {0}
private

the spread to left or right

◆ bins_

SparseVectorType* bins_ {nullptr}
private

bins

◆ DEFAULT_BIN_OFFSET_HIRES

constexpr const float DEFAULT_BIN_OFFSET_HIRES = 0.0f
staticconstexpr

default bin offset for high-resolution data (adapted from doi:10.1007/s13361-015-1179-x)

◆ DEFAULT_BIN_OFFSET_LOWRES

constexpr const float DEFAULT_BIN_OFFSET_LOWRES = 0.4f
staticconstexpr

default bin offset for low-resolution data (adapted from doi:10.1007/s13361-015-1179-x)

◆ DEFAULT_BIN_WIDTH_HIRES

constexpr const float DEFAULT_BIN_WIDTH_HIRES = 0.02f
staticconstexpr

◆ DEFAULT_BIN_WIDTH_LOWRES

constexpr const float DEFAULT_BIN_WIDTH_LOWRES = 1.0005f
staticconstexpr

Sensible default values and notes from doi:10.1007/s13361-015-1179-x Low-resolution MS/MS data: bin width = 1.0005 offset = 0.4 spread should be 0

High-resolution MS/MS data: bin width = 0.02 offset = 0.0 spread should be 0 Note: in sum scores, intensities from neighboring bins should be considered with half intensity of each flanking bin. @TODO: Weighted intensity spread is currently not implemented(but could replace the spread parameter).

◆ MIN_MZ_

constexpr const float MIN_MZ_ = 1.0
staticconstexprprivate

◆ offset_

float offset_ {0}
private

offset of bin start

◆ precursors_

std::vector<Precursor> precursors_
private

precursor information

◆ unit_ppm_

bool unit_ppm_ {false}
private

absolute bin size or relative bin size