OpenMS  2.6.0
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-2020.
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 #pragma once
37 
41 
42 #include <vector>
43 #include <cmath>
44 #include <map>
45 
46 namespace OpenMS
47 {
55  template <typename Container = MSSpectrum>
57  public DefaultParamHandler, public ProgressLogger
58  {
59 public:
60 
64  typedef typename Container::const_iterator PeakIterator;
65  typedef typename PeakIterator::value_type PeakType;
66 
67 
69 
72  DefaultParamHandler("SignalToNoiseEstimator"),
74  {
75  }
76 
79  DefaultParamHandler(source),
80  ProgressLogger(source),
82  {}
83 
86  {
87  if (&source == this) return *this;
88 
92  return *this;
93  }
94 
97  {}
98 
100  virtual void init(const Container& c)
101  {
102  computeSTN_(c);
103  }
104 
108  virtual double getSignalToNoise(const Size index) const
109  {
110  OPENMS_POSTCONDITION(index < stn_estimates_.size(),"SignalToNoiseEstimator estimates beyond container size was requested.");
111  return stn_estimates_[index];
112  }
113 
114 protected:
115 
121  virtual void computeSTN_(const Container& c) = 0;
122 
123 
124 
131  {
132  double mean;
133  double variance;
134  };
135 
136 
138  inline GaussianEstimate estimate_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) const
139  {
140  int size = 0;
141  // add up
142  double v = 0;
143  double m = 0;
144  PeakIterator run = scan_first_;
145  while (run != scan_last_)
146  {
147  m += (*run).getIntensity();
148  ++size;
149  ++run;
150  }
151  //average
152  m = m / size;
153 
154  //determine variance
155  run = scan_first_;
156  while (run != scan_last_)
157  {
158  double tmp(m - (*run).getIntensity());
159  v += tmp * tmp;
160  ++run;
161  }
162  v = v / ((double)size); // divide by n
163 
164  GaussianEstimate value = {m, v};
165  return value;
166  }
167 
168  //MEMBERS:
169 
171  std::vector<double> stn_estimates_;
172  };
173 
174 } // namespace OpenMS
175 
DefaultParamHandler.h
OpenMS::SignalToNoiseEstimator::SignalToNoiseEstimator
SignalToNoiseEstimator()
Constructor.
Definition: SignalToNoiseEstimator.h:71
double
OpenMS::DefaultParamHandler::operator=
virtual DefaultParamHandler & operator=(const DefaultParamHandler &rhs)
Assignment operator.
OpenMS::SignalToNoiseEstimator::SignalToNoiseEstimator
SignalToNoiseEstimator(const SignalToNoiseEstimator &source)
Copy constructor.
Definition: SignalToNoiseEstimator.h:78
OpenMS::SignalToNoiseEstimator
This class represents the abstract base class of a signal to noise estimator.
Definition: SignalToNoiseEstimator.h:56
OpenMS::SignalToNoiseEstimator::stn_estimates_
std::vector< double > stn_estimates_
stores the noise estimate for each peak
Definition: SignalToNoiseEstimator.h:171
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Constants::c
const double c
OpenMS::SignalToNoiseEstimator::GaussianEstimate::variance
double variance
variance of estimated Gaussian
Definition: SignalToNoiseEstimator.h:133
OpenMS::SignalToNoiseEstimator::init
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:100
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
OpenMS::SignalToNoiseEstimator::PeakType
PeakIterator::value_type PeakType
Definition: SignalToNoiseEstimator.h:65
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::SignalToNoiseEstimator::getSignalToNoise
virtual double getSignalToNoise(const Size index) const
Definition: SignalToNoiseEstimator.h:108
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
ProgressLogger.h
OpenMS::SignalToNoiseEstimator::operator=
SignalToNoiseEstimator & operator=(const SignalToNoiseEstimator &source)
Assignment operator.
Definition: SignalToNoiseEstimator.h:85
OpenMS::ProgressLogger::operator=
ProgressLogger & operator=(const ProgressLogger &other)
Assignment Operator.
OpenMS::SignalToNoiseEstimator::computeSTN_
virtual void computeSTN_(const Container &c)=0
computes the S/N values when init() is called
OpenMS::SignalToNoiseEstimator::GaussianEstimate::mean
double mean
mean of estimated Gaussian
Definition: SignalToNoiseEstimator.h:132
OpenMS::SignalToNoiseEstimator::estimate_
GaussianEstimate estimate_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) const
calculate mean & stdev of intensities of a spectrum
Definition: SignalToNoiseEstimator.h:138
OpenMS::SignalToNoiseEstimator::PeakIterator
Container::const_iterator PeakIterator
Definition: SignalToNoiseEstimator.h:64
OpenMS::SignalToNoiseEstimator::~SignalToNoiseEstimator
~SignalToNoiseEstimator() override
Destructor.
Definition: SignalToNoiseEstimator.h:96
OpenMS::SignalToNoiseEstimator::GaussianEstimate
protected struct to store parameters my, sigma for a Gaussian distribution
Definition: SignalToNoiseEstimator.h:130
OPENMS_POSTCONDITION
#define OPENMS_POSTCONDITION(condition, message)
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/Macros.h:48
MSSpectrum.h