OpenMS
NeutralLossMarker.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 NeutralLossMarker :
26  public PeakMarker
27  {
28 public:
29 
30  // @name Constructors and Destructors
31  // @{
34 
37 
39  ~NeutralLossMarker() override;
40  // @}
41 
42  // @name Operators
43  // @{
46  // @}
47 
48  // @name Accessors
49  // @{
50 
52  template <typename SpectrumType>
53  void apply(std::map<double, bool> & marked, SpectrumType & spectrum)
54  {
55  // how often a peak needs to be marked to be returned
56  double marks = (double)param_.getValue("marks");
57  double tolerance = (double)param_.getValue("tolerance");
58  std::map<double, SignedSize> ions_w_neutrallosses;
59  spectrum.sortByPosition();
60  for (Size i = 0; i < spectrum.size(); ++i)
61  {
62  double mz = spectrum[i].getPosition()[0];
63  double intensity = spectrum[i].getIntensity();
64  SignedSize j = i - 1;
65  while (j >= 0)
66  {
67  double curmz = spectrum[j].getPosition()[0];
68  double curIntensity = spectrum[j].getIntensity();
69 
70  // check for peak that's a water or ammonia away
71  if (std::fabs(mz - curmz - 17) < tolerance || std::fabs(mz - curmz - 18) < tolerance)
72  {
73  // neutral loss peak should be smaller
74  if (curIntensity < intensity)
75  {
76  ions_w_neutrallosses[mz]++;
77  // neutral loss peak not marked
78  //ions_w_neutrallosses[curmz]++;
79  }
80  }
81  else
82  {
83  if (mz - curmz > 18.3)
84  {
85  break;
86  }
87  }
88  --j;
89  }
90  }
91 
92  for (std::map<double, SignedSize>::const_iterator cmit = ions_w_neutrallosses.begin(); cmit != ions_w_neutrallosses.end(); ++cmit)
93  {
94  if (cmit->second >= marks)
95  {
96  marked.insert(std::pair<double, bool>(cmit->first, true));
97  }
98  }
99  return;
100  }
101 
102  // @}
103 
104  };
105 
106 }
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
void sortByPosition()
Lexicographically sorts the peaks by their position.
NeutralLossMarker marks peak pairs which could represent an ion an its neutral loss (water,...
Definition: NeutralLossMarker.h:27
NeutralLossMarker(const NeutralLossMarker &source)
copy constructor
NeutralLossMarker()
default constructor
NeutralLossMarker & operator=(const NeutralLossMarker &source)
assignment operator
void apply(std::map< double, bool > &marked, SpectrumType &spectrum)
Definition: NeutralLossMarker.h:53
~NeutralLossMarker() override
destructor
PeakMarker marks peaks that seem to fulfill some criterion.
Definition: PeakMarker.h:23
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