OpenMS
GoodDiffFilter.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 
10 #pragma once
11 
13 
14 #include <map>
15 #include <string>
16 #include <cmath>
17 
18 namespace OpenMS
19 {
27  class OPENMS_DLLAPI GoodDiffFilter :
28  public FilterFunctor
29  {
30 public:
31 
32  // @name Constructors and Destructors
33  // @{
36 
38  GoodDiffFilter(const GoodDiffFilter & source);
39 
41  ~GoodDiffFilter() override;
42  // @}
43 
44  // @name Operators
45  // @{
48  // @}
49 
50  // @name Accessors
51  // @{
53  static FilterFunctor * create() { return new GoodDiffFilter(); }
54 
56  template <typename SpectrumType>
57  double apply(SpectrumType & spectrum)
58  {
59  double tolerance = (double)param_.getValue("tolerance");
60  double gooddiff = 0;
61  //iterate over all peaks
62  double totaldiff = 0;
63  for (Size i = 0; i < spectrum.size(); ++i)
64  {
65  //look for each peakdifference that is in range of aa residuemasses (56/187), if it could be a aa (aamass)
66  for (Size j = i; i + j < spectrum.size(); ++j)
67  {
68  double diff = spectrum[i + j].getPosition()[0] - spectrum[i].getPosition()[0];
69  if (diff < 56)
70  {
71  continue;
72  }
73 
74  if (diff > 187)
75  {
76  j = spectrum.size();
77  }
78  else
79  {
80  totaldiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
81  std::map<double, char>::const_iterator aait = aamass_.lower_bound(diff);
82  if (aait == aamass_.end())
83  {
84  continue;
85  }
86  //look for aamasses that fit diff
87  if (fabs(aait->first - diff) <= tolerance)
88  {
89  gooddiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
90  }
91  else
92  {
93  ++aait;
94  if ((aait) != aamass_.end() && fabs((aait)->first - diff) <= tolerance)
95  {
96  gooddiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
97  }
98  }
99  }
100  }
101  }
102 
103  return gooddiff / totaldiff;
104  }
105 
107  static const String getProductName()
108  {
109  return "GoodDiffFilter";
110  }
111 
112  // @}
113 
114 
115 private:
116 
118  std::map<double, char> aamass_;
119  };
120 }
121 
A FilterFunctor extracts some spectrum characteristics for quality assessment.
Definition: FilterFunctor.h:20
GoodDiffFilter counts the number ob peak pairs whose m/z difference can be explained by a amino acid ...
Definition: GoodDiffFilter.h:29
~GoodDiffFilter() override
destructor
GoodDiffFilter()
default constructor
static FilterFunctor * create()
Definition: GoodDiffFilter.h:53
GoodDiffFilter & operator=(const GoodDiffFilter &source)
assignment operator
std::map< double, char > aamass_
list of unique amino acid masses
Definition: GoodDiffFilter.h:118
double apply(SpectrumType &spectrum)
Definition: GoodDiffFilter.h:57
GoodDiffFilter(const GoodDiffFilter &source)
copy constructor
static const String getProductName()
Definition: GoodDiffFilter.h:107
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
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
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22