OpenMS
ComplementMarker.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 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  static PeakMarker * create() { return new ComplementMarker(); }
52 
54  template <typename SpectrumType>
55  void apply(std::map<double, bool> marked, SpectrumType & spectrum)
56  {
57  if (spectrum.size() < 2)
58  {
59  return;
60  }
61 
62  // how often a peak needs to be marked to be returned
63  double marks = (double)param_.getValue("marks");
64  double parentmass = 0.0;
65  if (!spectrum.getPrecursors().empty()) parentmass = spectrum.getPrecursors()[0].getMZ();
66  double tolerance = (double)param_.getValue("tolerance");
67  std::map<double, int> matching_b_y_ions;
68 
69  spectrum.sortByPosition();
70 
71  SignedSize j = spectrum.size() - 1;
72  for (Size i = 0; i < spectrum.size(); ++i)
73  {
74  while (j >= 0 && spectrum[j].getPosition()[0] > (parentmass - spectrum[i].getPosition()[0]) + tolerance)
75  {
76  j--;
77  }
78 
79  // just takes the first matching ion; todo take all
80  if (j >= 0 && std::fabs(spectrum[i].getPosition()[0] + spectrum[j].getPosition()[0] - parentmass) < tolerance)
81  {
82  matching_b_y_ions[spectrum[i].getPosition()[0]]++;
83  matching_b_y_ions[spectrum[j].getPosition()[0]]++;
84  j--;
85  }
86  }
87 
88  for (std::map<double, int>::const_iterator cmit = matching_b_y_ions.begin(); cmit != matching_b_y_ions.end(); ++cmit)
89  {
90  if (cmit->second >= marks)
91  {
92  marked.insert(std::pair<double, bool>(cmit->first, true));
93  }
94  }
95  }
96 
98  static const String getProductName()
99  {
100  return "ComplementMarker";
101  }
102 
104 
105  };
106 
107 }
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:55
~ComplementMarker() override
destructor
static const String getProductName()
returns the name to register at the factory
Definition: ComplementMarker.h:98
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
A more convenient string class.
Definition: String.h:34
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
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