Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SignalToNoiseEstimator.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-2013.
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: Chris Bielow $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 
36 #ifndef OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
37 #define OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
38 
42 
43 #include <iostream>
44 #include <vector>
45 #include <cmath>
46 #include <map>
47 
48 namespace OpenMS
49 {
57  template <typename Container = MSSpectrum<> >
59  public DefaultParamHandler, public ProgressLogger
60  {
61 public:
62 
66  typedef typename Container::const_iterator PeakIterator;
67  typedef typename PeakIterator::value_type PeakType;
68 
69 
71 
74  DefaultParamHandler("SignalToNoiseEstimator"),
76  first_(),
77  last_(),
78  is_result_valid_(false)
79  {
80  }
81 
84  DefaultParamHandler(source),
85  ProgressLogger(source),
87  first_(source.first_),
88  last_(source.last_),
90  {}
91 
94  {
95  if (&source == this) return *this;
96 
98  ProgressLogger::operator=(source);
100  first_ = source.first_;
101  last_ = source.last_;
102  return *this;
103  }
104 
107  {}
108 
109 
111  virtual void init(const PeakIterator & it_begin, const PeakIterator & it_end)
112  {
113  first_ = it_begin;
114  last_ = it_end;
116  is_result_valid_ = true;
117  }
118 
120  virtual void init(const Container & c)
121  {
122  init(c.begin(), c.end());
123  }
124 
130  virtual double getSignalToNoise(const PeakIterator & data_point)
131  {
132  if (!is_result_valid_)
133  {
134  // recompute ...
135  init(first_, last_);
136  }
137 
138  return stn_estimates_[*data_point];
139  }
140 
141  virtual double getSignalToNoise(const PeakType & data_point)
142  {
143  if (!is_result_valid_)
144  {
145  // recompute ...
146  init(first_, last_);
147  }
148 
149  return stn_estimates_[data_point];
150  }
151 
152 protected:
153 
159  virtual void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) = 0;
160 
161 
162 
169  {
170  double mean;
171  double variance;
172  };
173 
174 
176  inline GaussianEstimate estimate_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) const
177  {
178  int size = 0;
179  // add up
180  double v = 0;
181  double m = 0;
182  PeakIterator run = scan_first_;
183  while (run != scan_last_)
184  {
185  m += (*run).getIntensity();
186  ++size;
187  ++run;
188  }
189  //average
190  m = m / size;
191 
192  //determine variance
193  run = scan_first_;
194  while (run != scan_last_)
195  {
196  DoubleReal tmp(m - (*run).getIntensity());
197  v += tmp * tmp;
198  ++run;
199  }
200  v = v / ((double)size); // divide by n
201 
202  GaussianEstimate value = {m, v};
203  return value;
204  }
205 
206  //MEMBERS:
207 
209  std::map<PeakType, double, typename PeakType::PositionLess> stn_estimates_;
210 
216  mutable bool is_result_valid_;
217  };
218 
219 } // namespace OpenMS
220 
221 #endif //OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:130
virtual void computeSTN_(const PeakIterator &scan_first_, const PeakIterator &scan_last_)=0
computes the S/N values when init() is called
SignalToNoiseEstimator & operator=(const SignalToNoiseEstimator &source)
Assignment operator.
Definition: SignalToNoiseEstimator.h:93
Container::const_iterator PeakIterator
Definition: SignalToNoiseEstimator.h:66
double variance
mean of estimated Gaussian
Definition: SignalToNoiseEstimator.h:171
const double c
double mean
Definition: SignalToNoiseEstimator.h:170
GaussianEstimate estimate_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) const
calculate mean &amp; stdev of intensities of a spectrum
Definition: SignalToNoiseEstimator.h:176
bool is_result_valid_
flag: set to true if SignalToNoise estimates are calculated and none of the params were changed...
Definition: SignalToNoiseEstimator.h:216
virtual void init(const Container &c)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:120
protected struct to store parameters my, sigma for a Gaussian distribution
Definition: SignalToNoiseEstimator.h:168
virtual void init(const PeakIterator &it_begin, const PeakIterator &it_end)
Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimat...
Definition: SignalToNoiseEstimator.h:111
PeakIterator last_
points to the right position next to the last raw data point in the interval
Definition: SignalToNoiseEstimator.h:214
PeakIterator first_
points to the first raw data point in the interval
Definition: SignalToNoiseEstimator.h:212
virtual ~SignalToNoiseEstimator()
Destructor.
Definition: SignalToNoiseEstimator.h:106
PeakIterator::value_type PeakType
Definition: SignalToNoiseEstimator.h:67
SignalToNoiseEstimator()
Constructor.
Definition: SignalToNoiseEstimator.h:73
virtual double getSignalToNoise(const PeakType &data_point)
Definition: SignalToNoiseEstimator.h:141
This class represents the abstract base class of a signal to noise estimator.
Definition: SignalToNoiseEstimator.h:58
std::map< PeakType, double, typename PeakType::PositionLess > stn_estimates_
stores the noise estimate for each peak
Definition: SignalToNoiseEstimator.h:209
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
virtual DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:90
SignalToNoiseEstimator(const SignalToNoiseEstimator &source)
Copy constructor.
Definition: SignalToNoiseEstimator.h:83

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:20 using doxygen 1.8.5