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-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: 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 <vector>
44 #include <cmath>
45 #include <map>
46 
47 namespace OpenMS
48 {
56  template <typename Container = MSSpectrum>
58  public DefaultParamHandler, public ProgressLogger
59  {
60 public:
61 
65  typedef typename Container::const_iterator PeakIterator;
66  typedef typename PeakIterator::value_type PeakType;
67 
68 
70 
73  DefaultParamHandler("SignalToNoiseEstimator"),
75  first_(),
76  last_(),
77  is_result_valid_(false)
78  {
79  }
80 
83  DefaultParamHandler(source),
84  ProgressLogger(source),
86  first_(source.first_),
87  last_(source.last_),
89  {}
90 
93  {
94  if (&source == this) return *this;
95 
99  first_ = source.first_;
100  last_ = source.last_;
101  return *this;
102  }
103 
106  {}
107 
108 
110  virtual void init(const PeakIterator & it_begin, const PeakIterator & it_end)
111  {
112  first_ = it_begin;
113  last_ = it_end;
115  is_result_valid_ = true;
116  }
117 
119  virtual void init(const Container & c)
120  {
121  init(c.begin(), c.end());
122  }
123 
129  virtual double getSignalToNoise(const PeakIterator & data_point)
130  {
131  if (!is_result_valid_)
132  {
133  // recompute ...
134  init(first_, last_);
135  }
136 
137  return stn_estimates_[*data_point];
138  }
139 
140  virtual double getSignalToNoise(const PeakType & data_point)
141  {
142  if (!is_result_valid_)
143  {
144  // recompute ...
145  init(first_, last_);
146  }
147 
148  return stn_estimates_[data_point];
149  }
150 
151 protected:
152 
158  virtual void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) = 0;
159 
160 
161 
168  {
169  double mean;
170  double variance;
171  };
172 
173 
175  inline GaussianEstimate estimate_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) const
176  {
177  int size = 0;
178  // add up
179  double v = 0;
180  double m = 0;
181  PeakIterator run = scan_first_;
182  while (run != scan_last_)
183  {
184  m += (*run).getIntensity();
185  ++size;
186  ++run;
187  }
188  //average
189  m = m / size;
190 
191  //determine variance
192  run = scan_first_;
193  while (run != scan_last_)
194  {
195  double tmp(m - (*run).getIntensity());
196  v += tmp * tmp;
197  ++run;
198  }
199  v = v / ((double)size); // divide by n
200 
201  GaussianEstimate value = {m, v};
202  return value;
203  }
204 
205  //MEMBERS:
206 
208  std::map<PeakType, double, typename PeakType::PositionLess> stn_estimates_;
209 
211  PeakIterator first_;
213  PeakIterator last_;
215  mutable bool is_result_valid_;
216  };
217 
218 } // namespace OpenMS
219 
220 #endif //OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
virtual double getSignalToNoise(const PeakIterator &data_point)
Definition: SignalToNoiseEstimator.h:129
ProgressLogger & operator=(const ProgressLogger &other)
Assignment Operator.
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:92
Container::const_iterator PeakIterator
Definition: SignalToNoiseEstimator.h:65
double variance
mean of estimated Gaussian
Definition: SignalToNoiseEstimator.h:170
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
double mean
Definition: SignalToNoiseEstimator.h:169
bool is_result_valid_
flag: set to true if SignalToNoise estimates are calculated and none of the params were changed...
Definition: SignalToNoiseEstimator.h:215
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:119
GaussianEstimate estimate_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) const
calculate mean & stdev of intensities of a spectrum
Definition: SignalToNoiseEstimator.h:175
protected struct to store parameters my, sigma for a Gaussian distribution
Definition: SignalToNoiseEstimator.h:167
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:110
PeakIterator last_
points to the right position next to the last raw data point in the interval
Definition: SignalToNoiseEstimator.h:213
PeakIterator first_
points to the first raw data point in the interval
Definition: SignalToNoiseEstimator.h:211
virtual ~SignalToNoiseEstimator()
Destructor.
Definition: SignalToNoiseEstimator.h:105
PeakIterator::value_type PeakType
Definition: SignalToNoiseEstimator.h:66
SignalToNoiseEstimator()
Constructor.
Definition: SignalToNoiseEstimator.h:72
virtual double getSignalToNoise(const PeakType &data_point)
Definition: SignalToNoiseEstimator.h:140
This class represents the abstract base class of a signal to noise estimator.
Definition: SignalToNoiseEstimator.h:57
std::map< PeakType, double, typename PeakType::PositionLess > stn_estimates_
stores the noise estimate for each peak
Definition: SignalToNoiseEstimator.h:208
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
virtual DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
SignalToNoiseEstimator(const SignalToNoiseEstimator &source)
Copy constructor.
Definition: SignalToNoiseEstimator.h:82

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