OpenMS
ComplementMarker.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 ComplementMarker :
26  public PeakMarker
27  {
28 public:
29 
30  // @name Constructors and Destructors
34 
37 
39  ~ComplementMarker() override;
41 
42  // @name Operators
44  ComplementMarker & operator=(const ComplementMarker & source);
47 
48  // @name Accessors
50 
52  template <typename SpectrumType>
53  void apply(std::map<double, bool> marked, SpectrumType & spectrum)
54  {
55  if (spectrum.size() < 2)
56  {
57  return;
58  }
59 
60  // how often a peak needs to be marked to be returned
61  double marks = (double)param_.getValue("marks");
62  double parentmass = 0.0;
63  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
64  double tolerance = (double)param_.getValue("tolerance");
65  std::map<double, int> matching_b_y_ions;
66 
67  spectrum.sortByPosition();
68 
69  SignedSize j = spectrum.size() - 1;
70  for (Size i = 0; i < spectrum.size(); ++i)
71  {
72  while (j >= 0 && spectrum[j].getPosition()[0] > (parentmass - spectrum[i].getPosition()[0]) + tolerance)
73  {
74  j--;
75  }
76 
77  // just takes the first matching ion; todo take all
78  if (j >= 0 && std::fabs(spectrum[i].getPosition()[0] + spectrum[j].getPosition()[0] - parentmass) < tolerance)
79  {
80  matching_b_y_ions[spectrum[i].getPosition()[0]]++;
81  matching_b_y_ions[spectrum[j].getPosition()[0]]++;
82  j--;
83  }
84  }
85 
86  for (std::map<double, int>::const_iterator cmit = matching_b_y_ions.begin(); cmit != matching_b_y_ions.end(); ++cmit)
87  {
88  if (cmit->second >= marks)
89  {
90  marked.insert(std::pair<double, bool>(cmit->first, true));
91  }
92  }
93  }
94 
96 
97  };
98 
99 }
ComplementMarker marks peak pairs which could represent y - b ion pairs.
Definition: ComplementMarker.h:27
ComplementMarker(const ComplementMarker &source)
copy constructor
void apply(std::map< double, bool > marked, SpectrumType &spectrum)
Definition: ComplementMarker.h:53
~ComplementMarker() override
destructor
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void sortByPosition()
Lexicographically sorts the peaks by their position.
PeakMarker marks peaks that seem to fulfill some criterion.
Definition: PeakMarker.h:23
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:104
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