OpenMS
IntensityBalanceFilter.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: $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
12 
13 #include <map>
14 #include <utility>
15 
16 namespace OpenMS
17 {
26  class OPENMS_DLLAPI IntensityBalanceFilter :
27  public FilterFunctor
28  {
29 
30 public:
31 
32  // @name Constructors and Destructors
33  // @{
36 
39 
42  // @}
43 
44  // @name Operators
45  // @{
48  // @}
49 
50  // @name Accessors
51  // @{
52 
54  template <typename SpectrumType>
55  double apply(SpectrumType & spectrum)
56  {
57  double bands = 10;
58  std::multimap<double, Size> band_intensity;
59  double parentmass = 0.0;
60  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
61  Size j = 0;
62  for (Size i = 0; i < bands; ++i)
63  {
64  double intensity = 0;
65 
66  //bern 2004 says to only check between 300 and size
67  //but that seems inappropriate for small peptides (smallest is ca 450)
68  while (j < spectrum.size() && spectrum[j].getPosition()[0] < (parentmass - 300) / bands * (i + 1) + 300)
69  {
70  intensity += spectrum[j++].getIntensity();
71  }
72  band_intensity.insert(std::make_pair(intensity, i));
73  }
74  j = 0;
75  double total_intensity = 0;
76  double twobiggest = 0;
77  double sevensmallest = 0;
78  for (std::multimap<double, Size>::reverse_iterator mmrit = band_intensity.rbegin(); mmrit != band_intensity.rend(); ++mmrit, ++j)
79  {
80  total_intensity += mmrit->first;
81  //take the two biggest
82  if (j < 2)
83  {
84  twobiggest += mmrit->first;
85  }
86  //take the seven smallest
87  if (j > 2)
88  {
89  sevensmallest += mmrit->first;
90  }
91  }
92 
93  return (twobiggest - sevensmallest) / total_intensity;
94  }
95 
96  // @}
97 
98  };
99 }
A FilterFunctor extracts some spectrum characteristics for quality assessment.
Definition: FilterFunctor.h:20
IntensityBalanceFilter divides the m/z-range into ten regions and sums the intensity in these regions...
Definition: IntensityBalanceFilter.h:28
IntensityBalanceFilter()
default constructor
~IntensityBalanceFilter() override
destructor
IntensityBalanceFilter & operator=(const IntensityBalanceFilter &source)
assignment operator
double apply(SpectrumType &spectrum)
Definition: IntensityBalanceFilter.h:55
IntensityBalanceFilter(const IntensityBalanceFilter &source)
copy constructor
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19