Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
00037 #define OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H
00038
00039 #include <OpenMS/KERNEL/MSSpectrum.h>
00040 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00041 #include <OpenMS/CONCEPT/ProgressLogger.h>
00042
00043 #include <iostream>
00044 #include <vector>
00045 #include <cmath>
00046 #include <map>
00047
00048 namespace OpenMS
00049 {
00057 template <typename Container = MSSpectrum<> >
00058 class SignalToNoiseEstimator :
00059 public DefaultParamHandler, public ProgressLogger
00060 {
00061 public:
00062
00066 typedef typename Container::const_iterator PeakIterator;
00067 typedef typename PeakIterator::value_type PeakType;
00068
00069
00071
00073 inline SignalToNoiseEstimator() :
00074 DefaultParamHandler("SignalToNoiseEstimator"),
00075 ProgressLogger(),
00076 first_(),
00077 last_(),
00078 is_result_valid_(false)
00079 {
00080 }
00081
00083 inline SignalToNoiseEstimator(const SignalToNoiseEstimator & source) :
00084 DefaultParamHandler(source),
00085 ProgressLogger(source),
00086 stn_estimates_(source.stn_estimates_),
00087 first_(source.first_),
00088 last_(source.last_),
00089 is_result_valid_(source.is_result_valid_)
00090 {}
00091
00093 inline SignalToNoiseEstimator & operator=(const SignalToNoiseEstimator & source)
00094 {
00095 if (&source == this) return *this;
00096
00097 DefaultParamHandler::operator=(source);
00098 ProgressLogger::operator=(source);
00099 stn_estimates_ = source.stn_estimates_;
00100 first_ = source.first_;
00101 last_ = source.last_;
00102 return *this;
00103 }
00104
00106 virtual ~SignalToNoiseEstimator()
00107 {}
00108
00109
00111 virtual void init(const PeakIterator & it_begin, const PeakIterator & it_end)
00112 {
00113 first_ = it_begin;
00114 last_ = it_end;
00115 computeSTN_(first_, last_);
00116 is_result_valid_ = true;
00117 }
00118
00120 virtual void init(const Container & c)
00121 {
00122 init(c.begin(), c.end());
00123 }
00124
00130 virtual double getSignalToNoise(const PeakIterator & data_point)
00131 {
00132 if (!is_result_valid_)
00133 {
00134
00135 init(first_, last_);
00136 }
00137
00138 return stn_estimates_[*data_point];
00139 }
00140
00141 virtual double getSignalToNoise(const PeakType & data_point)
00142 {
00143 if (!is_result_valid_)
00144 {
00145
00146 init(first_, last_);
00147 }
00148
00149 return stn_estimates_[data_point];
00150 }
00151
00152 protected:
00153
00159 virtual void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) = 0;
00160
00161
00162
00168 struct GaussianEstimate
00169 {
00170 double mean;
00171 double variance;
00172 };
00173
00174
00176 inline GaussianEstimate estimate_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) const
00177 {
00178 int size = 0;
00179
00180 double v = 0;
00181 double m = 0;
00182 PeakIterator run = scan_first_;
00183 while (run != scan_last_)
00184 {
00185 m += (*run).getIntensity();
00186 ++size;
00187 ++run;
00188 }
00189
00190 m = m / size;
00191
00192
00193 run = scan_first_;
00194 while (run != scan_last_)
00195 {
00196 DoubleReal tmp(m - (*run).getIntensity());
00197 v += tmp * tmp;
00198 ++run;
00199 }
00200 v = v / ((double)size);
00201
00202 GaussianEstimate value = {m, v};
00203 return value;
00204 }
00205
00206
00207
00209 std::map<PeakType, double, typename PeakType::PositionLess> stn_estimates_;
00210
00212 PeakIterator first_;
00214 PeakIterator last_;
00216 mutable bool is_result_valid_;
00217 };
00218
00219 }
00220
00221 #endif //OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATOR_H