OpenMS
ComplementFilter.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, 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  static FilterFunctor * create() { return new ComplementFilter(); }
51 
53  template <typename SpectrumType>
54  double apply(SpectrumType & spectrum)
55  {
56  if (spectrum.size() < 2)
57  {
58  return 0;
59  }
60  double tolerance = (double)param_.getValue("tolerance");
61  double parentmass = 0.0;
62  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
63  double result(0);
64 
65  spectrum.sortByPosition();
66 
68  Size j = spectrum.size() - 1;
69  for (Size i = 0; i < spectrum.size() && i <= j; /*++i*/)
70  {
71  double sum = spectrum[i].getPosition()[0] + spectrum[j].getPosition()[0];
72 
73  if (std::fabs(sum - parentmass) < tolerance)
74  {
75  result += spectrum[i].getIntensity() + spectrum[j].getIntensity();
76  }
77 
78  if (sum < parentmass)
79  {
80  ++i;
81  }
82  else
83  {
84  if (sum > parentmass)
85  {
86  --j;
87  }
88  }
89  }
90 
91  return result;
92  }
93 
95  static const String getProductName()
96  {
97  return "ComplementFilter";
98  }
99 
101 
102  };
103 }
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
static FilterFunctor * create()
Definition: ComplementFilter.h:50
~ComplementFilter() override
destructor
double apply(SpectrumType &spectrum)
returns the total intensity of peak pairs which could result from complementing fragments
Definition: ComplementFilter.h:54
static const String getProductName()
returns the name for registration at the factory
Definition: ComplementFilter.h:95
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
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:81
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22