Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SignalToNoiseEstimatorMedianRapid.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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATORMEDIANRAPID_H
36 #define OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATORMEDIANRAPID_H
37 
40 #include <assert.h>
41 #include <vector>
42 
43 namespace OpenMS
44 {
45 
72  {
75 
76 public:
77 
90  struct OPENMS_DLLAPI NoiseEstimator
91  {
95  double mz_start;
97  double window_length;
99  std::vector<double> result_windows_even;
101  std::vector<double> result_windows_odd;
102 
105 
107  NoiseEstimator(double nr_windows_, double mz_start_, double win_len_) :
108  nr_windows(nr_windows_),
109  mz_start(mz_start_),
110  window_length(win_len_),
111  result_windows_even(nr_windows_),
112  result_windows_odd(nr_windows_+1)
113  {}
114 
122  double get_noise_value (double mz)
123  {
124  // Take the average of the two stored values
125  // Avoid division by 0 (since most clients will divide by the noise value)
126  return std::max(1.0, (get_noise_even(mz)+get_noise_odd(mz))/2.0 );
127  }
128 
129  double get_noise_even (double mz)
130  {
131  // PRECONDITION
132  int window_nr = (int)((mz - mz_start)/window_length);
133  assert(window_nr >= 0);
134  assert(window_nr < (int)result_windows_even.size());
135 
136  double noise = result_windows_even[window_nr];
137  return noise;
138  }
139 
140  double get_noise_odd (double mz)
141  {
142  // PRECONDITION
143  int window_nr = (int)((mz - mz_start + window_length/2.0)/window_length);
144  assert(window_nr >= 0);
145  assert(window_nr < (int)result_windows_odd.size());
146 
147  double noise = result_windows_odd[window_nr];
148  return noise;
149  }
150  };
151 
153  SignalToNoiseEstimatorMedianRapid(double window_length) :
154  window_length_(window_length)
155  {
156  }
157 
163  {
164  return estimateNoise(spectrum->getMZArray()->data, spectrum->getIntensityArray()->data);
165  }
166 
172  {
173  return estimateNoise(chrom->getTimeArray()->data, chrom->getIntensityArray()->data);
174  }
175 
180  NoiseEstimator estimateNoise(const std::vector<double>& mz_array, const std::vector<double>& int_array)
181  {
182  // PRECONDITION
183  assert(mz_array.size() == int_array.size());
184  assert(mz_array.size() > 2);
185 
186  int nr_windows = (int)((mz_array[mz_array.size()-1] - mz_array[0])/window_length_) + 1;
187  NoiseEstimator eval(nr_windows, mz_array[0], window_length_);
188 
189  // Compute even windows
190  computeNoiseInWindows_(mz_array, int_array, eval.result_windows_even, mz_array[0]);
191  // Compute odd windows
192  computeNoiseInWindows_(mz_array, int_array, eval.result_windows_odd, mz_array[0] - window_length_/2.0);
193 
194  return eval;
195  }
196 
197 private:
198 
204  void computeNoiseInWindows_(const std::vector<double>& mz_array, std::vector<double> int_array, std::vector<double> & result, double mz_start);
205 
212  double computeMedian_(std::vector<double>::iterator & first, std::vector<double>::iterator & last);
213 
214  };
215 
216 } // namespace OpenMS
217 
218 #endif // OPENMS_FILTERING_NOISEESTIMATION_SIGNALTONOISEESTIMATORMEDIANRAPID_H
219 
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:237
NoiseEstimator estimateNoise(const std::vector< double > &mz_array, const std::vector< double > &int_array)
Compute noise estimator for an m/z and intensity array using windows.
Definition: SignalToNoiseEstimatorMedianRapid.h:180
SignalToNoiseEstimatorMedianRapid(double window_length)
default constructor
Definition: SignalToNoiseEstimatorMedianRapid.h:153
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:157
std::vector< double > result_windows_odd
Noise values for window starting at mz_start - 0.5 * window_length (length = nr_windows + 1) ...
Definition: SignalToNoiseEstimatorMedianRapid.h:101
NoiseEstimator estimateNoise(OpenMS::Interfaces::ChromatogramPtr chrom)
Compute noise estimator for an m/z and intensity array using windows.
Definition: SignalToNoiseEstimatorMedianRapid.h:171
double get_noise_even(double mz)
Definition: SignalToNoiseEstimatorMedianRapid.h:129
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Estimates the signal/noise (S/N) ratio of each data point in a scan by using the median (window based...
Definition: SignalToNoiseEstimatorMedianRapid.h:71
Class to compute the noise value at a given position.
Definition: SignalToNoiseEstimatorMedianRapid.h:90
NoiseEstimator()
Constructor.
Definition: SignalToNoiseEstimatorMedianRapid.h:104
NoiseEstimator estimateNoise(OpenMS::Interfaces::SpectrumPtr spectrum)
Compute noise estimator for an m/z and intensity array using windows.
Definition: SignalToNoiseEstimatorMedianRapid.h:162
double get_noise_value(double mz)
Return the noise value at a given m/z position.
Definition: SignalToNoiseEstimatorMedianRapid.h:122
int nr_windows
Number of windows in m/z direction for which noise values are stored.
Definition: SignalToNoiseEstimatorMedianRapid.h:93
std::vector< double > result_windows_even
Noise values for window starting at mz_start (length = nr_windows)
Definition: SignalToNoiseEstimatorMedianRapid.h:99
double mz_start
Start of m/z domain.
Definition: SignalToNoiseEstimatorMedianRapid.h:95
double window_length
Length of the window in m/z direction.
Definition: SignalToNoiseEstimatorMedianRapid.h:97
double window_length_
Window length parameter.
Definition: SignalToNoiseEstimatorMedianRapid.h:74
double get_noise_odd(double mz)
Definition: SignalToNoiseEstimatorMedianRapid.h:140
NoiseEstimator(double nr_windows_, double mz_start_, double win_len_)
Constructor.
Definition: SignalToNoiseEstimatorMedianRapid.h:107

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