OpenMS
ComplementFilter.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: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
12 
13 #include <map>
14 #include <cmath>
15 
16 namespace OpenMS
17 {
25  class OPENMS_DLLAPI ComplementFilter :
26  public FilterFunctor
27  {
28 public:
29 
30  // @name Constructors and Destructors
34 
37 
39  ~ComplementFilter() override;
41 
42  // @name Operators
44  ComplementFilter & operator=(const ComplementFilter & source);
47 
48  // @name Accessors
50 
52  template <typename SpectrumType>
53  double apply(SpectrumType & spectrum)
54  {
55  if (spectrum.size() < 2)
56  {
57  return 0;
58  }
59  double tolerance = (double)param_.getValue("tolerance");
60  double parentmass = 0.0;
61  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
62  double result(0);
63 
64  spectrum.sortByPosition();
65 
67  Size j = spectrum.size() - 1;
68  for (Size i = 0; i < spectrum.size() && i <= j; /*++i*/)
69  {
70  double sum = spectrum[i].getPosition()[0] + spectrum[j].getPosition()[0];
71 
72  if (std::fabs(sum - parentmass) < tolerance)
73  {
74  result += spectrum[i].getIntensity() + spectrum[j].getIntensity();
75  }
76 
77  if (sum < parentmass)
78  {
79  ++i;
80  }
81  else
82  {
83  if (sum > parentmass)
84  {
85  --j;
86  }
87  }
88  }
89 
90  return result;
91  }
92 
94 
95  };
96 }
total intensity of peak pairs that could result from complementing fragments of charge state 1
Definition: ComplementFilter.h:27
ComplementFilter(const ComplementFilter &source)
copy constructor
~ComplementFilter() override
destructor
double apply(SpectrumType &spectrum)
returns the total intensity of peak pairs which could result from complementing fragments
Definition: ComplementFilter.h:53
A FilterFunctor extracts some spectrum characteristics for quality assessment.
Definition: FilterFunctor.h:20
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void sortByPosition()
Lexicographically sorts the peaks by their position.
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:81
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19