OpenMS  2.4.0
PeakIntegrator.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-2018.
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: Douglas McCloskey, Pasquale Domenico Colaianni $
32 // $Authors: Douglas McCloskey, Pasquale Domenico Colaianni $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/config.h> // OPENMS_DLLAPI
45 
46 namespace OpenMS
47 {
68  class OPENMS_DLLAPI PeakIntegrator :
69  public DefaultParamHandler
70  {
71 public:
75  virtual ~PeakIntegrator();
76 
80  struct PeakArea
82  {
86  double area = 0.0;
90  double height = 0.0;
94  double apex_pos = 0.0;
99  };
101 
105  struct PeakBackground
107  {
111  double area = 0.0;
115  double height = 0.0;
116  };
118 
123  struct PeakShapeMetrics
125  {
129  double width_at_5 = 0.0;
133  double width_at_10 = 0.0;
137  double width_at_50 = 0.0;
141  double start_position_at_5 = 0.0;
145  double start_position_at_10 = 0.0;
149  double start_position_at_50 = 0.0;
153  double end_position_at_5 = 0.0;
157  double end_position_at_10 = 0.0;
161  double end_position_at_50 = 0.0;
165  double total_width = 0.0;
179  double tailing_factor = 0.0;
189  double asymmetry_factor = 0.0;
194  double slope_of_baseline = 0.0;
199  double baseline_delta_2_height = 0.0;
203  Int points_across_baseline = 0;
207  Int points_across_half_height = 0;
208  };
210 
216  static constexpr const char* INTEGRATION_TYPE_INTENSITYSUM = "intensity_sum";
220  static constexpr const char* INTEGRATION_TYPE_TRAPEZOID = "trapezoid";
222  static constexpr const char* INTEGRATION_TYPE_SIMPSON = "simpson";
224  static constexpr const char* BASELINE_TYPE_BASETOBASE = "base_to_base";
226  static constexpr const char* BASELINE_TYPE_VERTICALDIVISION = "vertical_division";
228  static constexpr const char* BASELINE_TYPE_VERTICALDIVISION_MIN = "vertical_division_min";
230  static constexpr const char* BASELINE_TYPE_VERTICALDIVISION_MAX = "vertical_division_max";
232 
251  PeakArea integratePeak(
252  const MSChromatogram& chromatogram, const double left, const double right
253  ) const;
254 
273  PeakArea integratePeak(
275  ) const;
276 
295  PeakArea integratePeak(
296  const MSSpectrum& spectrum, const double left, const double right
297  ) const;
298 
317  PeakArea integratePeak(
318  const MSSpectrum& spectrum, MSSpectrum::ConstIterator& left, MSSpectrum::ConstIterator& right
319  ) const;
320 
345  PeakBackground estimateBackground(
346  const MSChromatogram& chromatogram, const double left, const double right,
347  const double peak_apex_pos
348  ) const;
349 
374  PeakBackground estimateBackground(
376  const double peak_apex_pos
377  ) const;
378 
403  PeakBackground estimateBackground(
404  const MSSpectrum& spectrum, const double left, const double right,
405  const double peak_apex_pos
406  ) const;
407 
432  PeakBackground estimateBackground(
433  const MSSpectrum& spectrum, MSSpectrum::ConstIterator& left, MSSpectrum::ConstIterator& right,
434  const double peak_apex_pos
435  ) const;
436 
456  PeakShapeMetrics calculatePeakShapeMetrics(
457  const MSChromatogram& chromatogram, const double left, const double right,
458  const double peak_height, const double peak_apex_pos
459  ) const;
460 
480  PeakShapeMetrics calculatePeakShapeMetrics(
482  const double peak_height, const double peak_apex_pos
483  ) const;
484 
504  PeakShapeMetrics calculatePeakShapeMetrics(
505  const MSSpectrum& spectrum, const double left, const double right,
506  const double peak_height, const double peak_apex_pos
507  ) const;
508 
528  PeakShapeMetrics calculatePeakShapeMetrics(
529  const MSSpectrum& spectrum, MSSpectrum::ConstIterator& left, MSSpectrum::ConstIterator& right,
530  const double peak_height, const double peak_apex_pos
531  ) const;
532 
533  void getDefaultParameters(Param& params);
534 
535 protected:
536  void updateMembers_();
537 
538  template <typename PeakContainerT>
539  PeakArea integratePeak_(
540  const PeakContainerT& pc, double left, double right
541  ) const;
542 
543  template <typename PeakContainerT>
544  PeakBackground estimateBackground_(
545  const PeakContainerT& pc, double left, double right,
546  const double peak_apex_pos
547  ) const;
548 
549  template <typename PeakContainerConstIteratorT>
550  double simpson_(PeakContainerConstIteratorT it_begin, PeakContainerConstIteratorT it_end) const;
551 
552  template <typename PeakContainerT>
553  PeakShapeMetrics calculatePeakShapeMetrics_(
554  const PeakContainerT& pc, double left, double right,
555  const double peak_height, const double peak_apex_pos
556  ) const;
557 
577  template <typename PeakContainerConstIteratorT>
578  double findPosAtPeakHeightPercent_(
579  PeakContainerConstIteratorT it_begin,
580  PeakContainerConstIteratorT it_end,
581  const double peak_height,
582  const double percent,
583  const bool is_left_half
584  ) const;
585 
586 private:
591 
596  String integration_type_ = INTEGRATION_TYPE_INTENSITYSUM;
601  String baseline_type_ = BASELINE_TYPE_BASETOBASE;
603 
605  bool fit_EMG_;
607 
611 
627  double simpson(MSChromatogram::ConstIterator it_begin, MSChromatogram::ConstIterator it_end) const;
628 
643  double simpson(MSSpectrum::ConstIterator it_begin, MSSpectrum::ConstIterator it_end) const;
645 
659  template <typename PeakContainerT>
660  const PeakContainerT& EMGPreProcess_(
661  const PeakContainerT& pc,
662  PeakContainerT& emg_pc,
663  double& left,
664  double& right
665  ) const;
666  };
667 }
A more convenient string class.
Definition: String.h:57
The representation of a chromatogram.
Definition: MSChromatogram.h:54
Compute the area, background and shape metrics of a peak.
Definition: EmgGradientDescent.h:64
std::vector< PointType > PointArrayType
Definition: ConvexHull2D.h:76
Definition: PeakIntegrator.h:106
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:103
EmgGradientDescent emg_
Definition: PeakIntegrator.h:606
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSChromatogram.h:93
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
ConvexHull2D::PointArrayType hull_points
Definition: PeakIntegrator.h:98
Management and storage of parameters / INI files.
Definition: Param.h:74
Definition: PeakIntegrator.h:124
Compute the area, background and shape metrics of a peak.
Definition: PeakIntegrator.h:68
Definition: PeakIntegrator.h:81
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
int Int
Signed integer type.
Definition: Types.h:102
bool fit_EMG_
Enable/disable EMG peak model fitting.
Definition: PeakIntegrator.h:605