OpenMS
Normalizer.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Mathias Walzer $
6 // $Authors: Andreas Bertsch $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
12 
14 
17 
18 #include <vector>
19 
20 namespace OpenMS
21 {
31  class OPENMS_DLLAPI Normalizer :
32  public DefaultParamHandler
33  {
34 public:
35 
36  // @name Constructors and Destructors
37  // @{
41  ~Normalizer() override;
42 
44  Normalizer & operator=(const Normalizer & source);
46  Normalizer(const Normalizer & source);
47 
48  // @}
49 
50  // @name Accessors
51  // @{
52 
59  template <typename SpectrumType>
60  void filterSpectrum(SpectrumType& spectrum) const
61  {
62  if (spectrum.empty()) return;
63 
64  typedef typename SpectrumType::Iterator Iterator;
65  typedef typename SpectrumType::ConstIterator ConstIterator;
66 
67  double divisor(0);
68  // find divisor
69  if (method_ == "to_one")
70  { // normalizes the max peak to 1 and the remaining peaks to values relative to max
71  divisor = spectrum.begin()->getIntensity(); // safety measure: if all intensities are negative, divisor would stay 0 (as constructed)
72  for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
73  {
74  if (divisor < it->getIntensity()) divisor = it->getIntensity();
75  }
76  }
77  else if (method_ == "to_TIC")
78  { // normalizes the peak intensities to the TIC
79  for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
80  {
81  divisor += it->getIntensity();
82  }
83  }
84  // method unknown
85  else
86  {
87  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Method not known", method_);
88  }
89 
90  // normalize
91  for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
92  {
93  it->setIntensity(it->getIntensity() / divisor);
94  }
95 
96  return;
97 
98  }
99 
101  void filterPeakSpectrum(PeakSpectrum & spectrum) const;
103  void filterPeakMap(PeakMap & exp) const;
104 
105  void updateMembers_() override;
106 
107  // @}
108 
109 private:
111  };
112 
113 
114 }
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
Invalid value exception.
Definition: Exception.h:305
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:110
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:108
Normalizes the peak intensities spectrum-wise.
Definition: Normalizer.h:33
~Normalizer() override
destructor
Normalizer(const Normalizer &source)
copy constructor
Normalizer()
default constructor
String method_
Definition: Normalizer.h:110
void filterPeakMap(PeakMap &exp) const
void filterPeakSpectrum(PeakSpectrum &spectrum) const
Normalizer & operator=(const Normalizer &source)
assignment operator
void filterSpectrum(SpectrumType &spectrum) const
Workhorse of this class.
Definition: Normalizer.h:60
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
A more convenient string class.
Definition: String.h:34
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19