OpenMS
GoodDiffFilter.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 
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  // @{
52 
54  template <typename SpectrumType>
55  double apply(SpectrumType & spectrum)
56  {
57  double tolerance = (double)param_.getValue("tolerance");
58  double gooddiff = 0;
59  //iterate over all peaks
60  double totaldiff = 0;
61  for (Size i = 0; i < spectrum.size(); ++i)
62  {
63  //look for each peakdifference that is in range of aa residuemasses (56/187), if it could be a aa (aamass)
64  for (Size j = i; i + j < spectrum.size(); ++j)
65  {
66  double diff = spectrum[i + j].getPosition()[0] - spectrum[i].getPosition()[0];
67  if (diff < 56)
68  {
69  continue;
70  }
71 
72  if (diff > 187)
73  {
74  j = spectrum.size();
75  }
76  else
77  {
78  totaldiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
79  std::map<double, char>::const_iterator aait = aamass_.lower_bound(diff);
80  if (aait == aamass_.end())
81  {
82  continue;
83  }
84  //look for aamasses that fit diff
85  if (fabs(aait->first - diff) <= tolerance)
86  {
87  gooddiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
88  }
89  else
90  {
91  ++aait;
92  if ((aait) != aamass_.end() && fabs((aait)->first - diff) <= tolerance)
93  {
94  gooddiff += spectrum[i + j].getIntensity() + spectrum[i].getIntensity();
95  }
96  }
97  }
98  }
99  }
100 
101  return gooddiff / totaldiff;
102  }
103 
104  // @}
105 
106 
107 private:
108 
110  std::map<double, char> aamass_;
111  };
112 }
113 
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
GoodDiffFilter & operator=(const GoodDiffFilter &source)
assignment operator
std::map< double, char > aamass_
list of unique amino acid masses
Definition: GoodDiffFilter.h:110
double apply(SpectrumType &spectrum)
Definition: GoodDiffFilter.h:55
GoodDiffFilter(const GoodDiffFilter &source)
copy constructor
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19