OpenMS  2.8.0
PeakPickerSH.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-2021.
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: Timo Sachsenberg $
32 // $Authors: Florian Zeller $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
41 
42 // TODO: Check if I need this # PeakPickerSH.h
43 #define DEBUG_PEAK_PICKING
44 #undef DEBUG_PEAK_PICKING
45 
46 namespace OpenMS
47 {
48  class OPENMS_DLLAPI PeakPickerSH :
49  public DefaultParamHandler,
50  public ProgressLogger
51  {
52 public:
54 
55  ~PeakPickerSH() override;
56 
60  void pick(const MSSpectrum & input, MSSpectrum & output, float fWindowWidth)
61  {
62  int i, hw, j;
63  double cm, toti, min_dh;
64 
65  // Hack: Prepare data structures for Lukas' algorithm
66  std::vector<double> masses, intens;
67  // TODO: Probably we could save some time when we resize the vectors... # PeakPickerSH.cpp
68  //masses.resize(input.size());
69  //intens.resize(input.size());
70  for (Size k = 0; k < input.size() - 1; ++k)
71  {
72  // Lukas requires a minimum of intensity (=50). His vectors do not contain
73  // other data, so I strip the low ones out right here.
74  // TODO: Read 50.0 from parameters # PeakPickerSH.cpp
75  if (input[k].getIntensity() >= 50.0)
76  {
77  masses.push_back(input[k].getMZ());
78  intens.push_back(input[k].getIntensity());
79  }
80  }
81 
82  min_dh = 50.0; // min height
83  hw = fWindowWidth / 2;
84 
85  for (i = 2; i < (int)masses.size() - 2; i++)
86  {
87 
88  // Peak must be concave in the interval [i-2 .. i+2]
89  if (intens[i] > min_dh && intens[i] > intens[i - 1] + min_dh && intens[i] >= intens[i + 1] && intens[i - 1] > intens[i - 2] + min_dh && intens[i + 1] >= intens[i + 2])
90  {
91 
92  cm = 0.0; // centroid mass:
93  toti = 0.0; // total intensity:
94 
95  for (j = -hw; j <= hw; j++)
96  {
97  double inte = intens[i - j];
98  double mz = masses[i - j];
99 
100  cm += inte * mz;
101  toti += (double) intens[i - j];
102  }
103  cm = cm / toti; // Centre of gravity = centroid
104 
105  Peak1D peak;
106  peak.setMZ(cm);
107  peak.setIntensity(intens[i]);
108  output.push_back(peak);
109  }
110  }
111  }
112 
119  void pickExperiment(const PeakMap & input, PeakMap & output);
120  };
121 }
122 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:104
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:113
Definition: PeakPickerSH.h:51
~PeakPickerSH() override
void pickExperiment(const PeakMap &input, PeakMap &output)
Applies the peak-picking algorithm to a map (MSExperiment).
void pick(const MSSpectrum &input, MSSpectrum &output, float fWindowWidth)
Picks peaks in one spectrum.
Definition: PeakPickerSH.h:60
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:53
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
const double k
Definition: Constants.h:153
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47