Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
BernNorm.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Mathias Walzer $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 #ifndef OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
36 #define OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
37 
39 
41 
42 #include <map>
43 
44 namespace OpenMS
45 {
57  class OPENMS_DLLAPI BernNorm :
58  public DefaultParamHandler
59  {
60 public:
61 
62  // @name Constructors and Destructors
64  BernNorm();
66 
68  BernNorm(const BernNorm & source);
69 
71  virtual ~BernNorm();
73 
74  // @name Operators
75  // @{
77  BernNorm & operator=(const BernNorm & source);
79 
80  // @name Accessors
81  // @{
82 
84  template <typename SpectrumType>
85  void filterSpectrum(SpectrumType & spectrum)
86  {
87  typedef typename SpectrumType::Iterator Iterator;
88  typedef typename SpectrumType::ConstIterator ConstIterator;
89 
90  c1_ = (double)param_.getValue("C1");
91  c2_ = (double)param_.getValue("C2");
92  th_ = (double)param_.getValue("threshold");
93 
94  spectrum.sortByPosition();
95 
96  // find highest peak and ranking
97  double maxint = 0;
98  std::map<double, Size> peakranks;
99  for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
100  {
101  peakranks[it->getIntensity()] = 0;
102  if (it->getIntensity() > maxint)
103  {
104  maxint = it->getIntensity();
105  }
106  }
107  UInt rank = 0;
108  for (std::map<double, Size>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
109  {
110  mit->second = ++rank;
111  }
112 
113  // find maxmz i.e. significant (> threshold * maxpeak) peak with highest m/z
114  double maxmz = 0;
115  for (SignedSize i = spectrum.size() - 1; i >= 0; --i)
116  {
117  if (spectrum[i].getIntensity() > maxint * th_)
118  {
119  maxmz = spectrum[i].getMZ();
120  break;
121  }
122  }
123 
124  // rank
125  for (Iterator it = spectrum.begin(); it != spectrum.end(); )
126  {
127  double newint = c1_ - (c2_ / maxmz) * peakranks[it->getIntensity()];
128  if (newint < 0)
129  {
130  it = spectrum.erase(it);
131  }
132  else
133  {
134  it->setIntensity(newint);
135  ++it;
136  }
137  }
138  return;
139  }
140 
141  void filterPeakSpectrum(PeakSpectrum & spectrum);
142 
143  void filterPeakMap(PeakMap & exp);
144  //TODO reimplement DefaultParamHandler::updateMembers_()
145 
146 private:
147  double c1_;
148  double c2_;
149  double th_;
150 
151  // @}
152 
153  };
154 
155 } // namespace OpenMS
156 
157 #endif //OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
double th_
Definition: BernNorm.h:149
void sortByPosition()
Lexicographically sorts the peaks by their position.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:102
double c2_
Definition: BernNorm.h:148
BernNorm scales the peaks by ranking them and then scaling them according to rank.
Definition: BernNorm.h:57
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
void filterSpectrum(SpectrumType &spectrum)
Definition: BernNorm.h:85
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
double c1_
Definition: BernNorm.h:147
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13