OpenMS
IntensityBalanceFilter.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, 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  // @{
53  static FilterFunctor * create() { return new IntensityBalanceFilter(); }
54 
56  template <typename SpectrumType>
57  double apply(SpectrumType & spectrum)
58  {
59  double bands = 10;
60  std::multimap<double, Size> band_intensity;
61  double parentmass = 0.0;
62  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
63  Size j = 0;
64  for (Size i = 0; i < bands; ++i)
65  {
66  double intensity = 0;
67 
68  //bern 2004 says to only check between 300 and size
69  //but that seems inappropriate for small peptides (smallest is ca 450)
70  while (j < spectrum.size() && spectrum[j].getPosition()[0] < (parentmass - 300) / bands * (i + 1) + 300)
71  {
72  intensity += spectrum[j++].getIntensity();
73  }
74  band_intensity.insert(std::make_pair(intensity, i));
75  }
76  j = 0;
77  double total_intensity = 0;
78  double twobiggest = 0;
79  double sevensmallest = 0;
80  for (std::multimap<double, Size>::reverse_iterator mmrit = band_intensity.rbegin(); mmrit != band_intensity.rend(); ++mmrit, ++j)
81  {
82  total_intensity += mmrit->first;
83  //take the two biggest
84  if (j < 2)
85  {
86  twobiggest += mmrit->first;
87  }
88  //take the seven smallest
89  if (j > 2)
90  {
91  sevensmallest += mmrit->first;
92  }
93  }
94 
95  return (twobiggest - sevensmallest) / total_intensity;
96  }
97 
99  static const String getProductName()
100  {
101  return "IntensityBalanceFilter";
102  }
103 
104  // @}
105 
106  };
107 }
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
static FilterFunctor * create()
Definition: IntensityBalanceFilter.h:53
~IntensityBalanceFilter() override
destructor
IntensityBalanceFilter & operator=(const IntensityBalanceFilter &source)
assignment operator
double apply(SpectrumType &spectrum)
Definition: IntensityBalanceFilter.h:57
IntensityBalanceFilter(const IntensityBalanceFilter &source)
copy constructor
static const String getProductName()
Definition: IntensityBalanceFilter.h:99
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22