Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
GaussFilter.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-2015.
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: Alexandra Zerck $
32 // $Authors: Eva Lange $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FILTERING_SMOOTHING_GAUSSFILTER_H
36 #define OPENMS_FILTERING_SMOOTHING_GAUSSFILTER_H
37 
43 
44 #include <cmath>
45 
46 namespace OpenMS
47 {
71 //#define DEBUG_FILTERING
72 
73  class OPENMS_DLLAPI GaussFilter :
74  public ProgressLogger,
75  public DefaultParamHandler
76  {
77 public:
79  GaussFilter();
80 
82  virtual ~GaussFilter();
83 
91  template <typename PeakType>
92  void filter(MSSpectrum<PeakType> & spectrum)
93  {
94  typedef std::vector<double> ContainerT;
95 
96  // make sure the right data type is set
98  bool found_signal = false;
99  Size data_size = spectrum.size();
100  ContainerT mz_in(data_size), int_in(data_size), mz_out(data_size), int_out(data_size);
101 
102  // copy spectrum to container
103  for (Size p = 0; p < spectrum.size(); ++p)
104  {
105  mz_in[p] = spectrum[p].getMZ();
106  int_in[p] = spectrum[p].getIntensity();
107  }
108 
109  // apply filter
110  ContainerT::iterator mz_out_it = mz_out.begin();
111  ContainerT::iterator int_out_it = int_out.begin();
112  found_signal = gauss_algo_.filter(mz_in.begin(), mz_in.end(), int_in.begin(), mz_out_it, int_out_it);
113 
114  // If all intensities are zero in the scan and the scan has a reasonable size, throw an exception.
115  // This is the case if the gaussian filter is smaller than the spacing of raw data
116  if (!found_signal && spectrum.size() >= 3)
117  {
118  String error_message = "Found no signal. The gaussian width is probably smaller than the spacing in your profile data. Try to use a bigger width.";
119  if (spectrum.getRT() > 0.0)
120  {
121  error_message += String(" The error occured in the spectrum with retention time ") + spectrum.getRT() + ".\n";
122  }
123  std::cerr << error_message;
124  }
125  else
126  {
127  // copy the new data into the spectrum
128  ContainerT::iterator mz_it = mz_out.begin();
129  ContainerT::iterator int_it = int_out.begin();
130  for (Size p = 0; mz_it != mz_out.end(); mz_it++, int_it++, p++)
131  {
132  spectrum[p].setIntensity(*int_it);
133  spectrum[p].setMZ(*mz_it);
134  }
135  }
136  }
137 
138  template <typename PeakType>
139  void filter(MSChromatogram<PeakType> & chromatogram)
140  {
141 
142  if (param_.getValue("use_ppm_tolerance").toBool())
143  {
144  throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__,
145  "GaussFilter: Cannot use ppm tolerance on chromatograms");
146  }
147 
148  MSSpectrum<PeakType> filter_spectra;
149  for (typename MSChromatogram<PeakType>::const_iterator it = chromatogram.begin(); it != chromatogram.end(); ++it)
150  {
151  filter_spectra.push_back(*it);
152  }
153  filter(filter_spectra);
154  chromatogram.clear(false);
155  for (typename MSSpectrum<PeakType>::const_iterator it = filter_spectra.begin(); it != filter_spectra.end(); ++it)
156  {
157  chromatogram.push_back(*it);
158  }
159 
160  }
161 
167  template <typename PeakType>
169  {
170  Size progress = 0;
171  startProgress(0, map.size() + map.getChromatograms().size(), "smoothing data");
172  for (Size i = 0; i < map.size(); ++i)
173  {
174  filter(map[i]);
175  setProgress(++progress);
176  }
177  for (Size i = 0; i < map.getChromatograms().size(); ++i)
178  {
179  filter(map.getChromatogram(i));
180  setProgress(++progress);
181  }
182  endProgress();
183  }
184 
185 protected:
186 
188 
190  double spacing_;
191 
192  // Docu in base class
193  virtual void updateMembers_();
194  };
195 
196 } // namespace OpenMS
197 #endif
A more convenient string class.
Definition: String.h:57
double spacing_
The spacing of the pre-tabulated kernel coefficients.
Definition: GaussFilter.h:190
Size size() const
Definition: MSExperiment.h:117
The representation of a chromatogram.
Definition: MSChromatogram.h:52
void filter(MSChromatogram< PeakType > &chromatogram)
Definition: GaussFilter.h:139
Raw data (also called profile data)
Definition: SpectrumSettings.h:75
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
MSChromatogram< ChromatogramPeakType > & getChromatogram(Size id)
returns a single chromatogram
Definition: MSExperiment.h:796
GaussFilterAlgorithm gauss_algo_
Definition: GaussFilter.h:187
double getRT() const
Definition: MSSpectrum.h:243
This class represents a Gaussian lowpass-filter which works on uniform as well as on non-uniform prof...
Definition: GaussFilterAlgorithm.h:70
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:69
This class represents a Gaussian lowpass-filter which works on uniform as well as on non-uniform prof...
Definition: GaussFilter.h:73
void setType(SpectrumType type)
sets the spectrum type
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
void filterExperiment(MSExperiment< PeakType > &map)
Smoothes an MSExperiment containing profile data.
Definition: GaussFilter.h:168
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSChromatogram.h:587
void filter(MSSpectrum< PeakType > &spectrum)
Smoothes an MSSpectrum containing profile data.
Definition: GaussFilter.h:92
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:788

OpenMS / TOPP release 2.0.0 Documentation generated on Fri May 29 2015 17:20:24 using doxygen 1.8.9.1