OpenMS
BernNorm.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: Mathias Walzer $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
12 
14 
15 #include <map>
16 
17 namespace OpenMS
18 {
30  class OPENMS_DLLAPI BernNorm :
31  public DefaultParamHandler
32  {
33 public:
34 
35  // @name Constructors and Destructors
37  BernNorm();
39 
41  BernNorm(const BernNorm & source);
42 
44  ~BernNorm() override;
46 
47  // @name Operators
48  // @{
50  BernNorm & operator=(const BernNorm & source);
52 
53  // @name Accessors
54  // @{
55 
57  template <typename SpectrumType>
58  void filterSpectrum(SpectrumType & spectrum)
59  {
60  typedef typename SpectrumType::Iterator Iterator;
61  typedef typename SpectrumType::ConstIterator ConstIterator;
62 
63  c1_ = (double)param_.getValue("C1");
64  c2_ = (double)param_.getValue("C2");
65  th_ = (double)param_.getValue("threshold");
66 
67  spectrum.sortByPosition();
68 
69  // find highest peak and ranking
70  double maxint = 0;
71  std::map<double, Size> peakranks;
72  for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
73  {
74  peakranks[it->getIntensity()] = 0;
75  if (it->getIntensity() > maxint)
76  {
77  maxint = it->getIntensity();
78  }
79  }
80  UInt rank = 0;
81  for (std::map<double, Size>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
82  {
83  mit->second = ++rank;
84  }
85 
86  // find maxmz i.e. significant (> threshold * maxpeak) peak with highest m/z
87  double maxmz = 0;
88  for (SignedSize i = spectrum.size() - 1; i >= 0; --i)
89  {
90  if (spectrum[i].getIntensity() > maxint * th_)
91  {
92  maxmz = spectrum[i].getMZ();
93  break;
94  }
95  }
96 
97  // rank
98  for (Iterator it = spectrum.begin(); it != spectrum.end(); )
99  {
100  double newint = c1_ - (c2_ / maxmz) * peakranks[it->getIntensity()];
101  if (newint < 0)
102  {
103  it = spectrum.erase(it);
104  }
105  else
106  {
107  it->setIntensity(newint);
108  ++it;
109  }
110  }
111  return;
112  }
113 
115 
116  void filterPeakMap(PeakMap & exp);
117  //TODO reimplement DefaultParamHandler::updateMembers_()
118 
119 private:
120  double c1_;
121  double c2_;
122  double th_;
123 
124  // @}
125 
126  };
127 
128 } // namespace OpenMS
129 
BernNorm scales the peaks by ranking them and then scaling them according to rank.
Definition: BernNorm.h:32
double th_
Definition: BernNorm.h:122
void filterPeakSpectrum(PeakSpectrum &spectrum)
void filterPeakMap(PeakMap &exp)
BernNorm & operator=(const BernNorm &source)
assignment operator
double c2_
Definition: BernNorm.h:121
~BernNorm() override
destructor
void filterSpectrum(SpectrumType &spectrum)
Definition: BernNorm.h:58
double c1_
Definition: BernNorm.h:120
BernNorm(const BernNorm &source)
copy constructor
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:110
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:108
void sortByPosition()
Lexicographically sorts the peaks by their position.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22