OpenMS
NeutralLossMarker.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 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  // @{
51  static PeakMarker * create() { return new NeutralLossMarker(); }
52 
54  template <typename SpectrumType>
55  void apply(std::map<double, bool> & marked, SpectrumType & spectrum)
56  {
57  // how often a peak needs to be marked to be returned
58  double marks = (double)param_.getValue("marks");
59  double tolerance = (double)param_.getValue("tolerance");
60  std::map<double, SignedSize> ions_w_neutrallosses;
61  spectrum.sortByPosition();
62  for (Size i = 0; i < spectrum.size(); ++i)
63  {
64  double mz = spectrum[i].getPosition()[0];
65  double intensity = spectrum[i].getIntensity();
66  SignedSize j = i - 1;
67  while (j >= 0)
68  {
69  double curmz = spectrum[j].getPosition()[0];
70  double curIntensity = spectrum[j].getIntensity();
71 
72  // check for peak that's a water or ammonia away
73  if (std::fabs(mz - curmz - 17) < tolerance || std::fabs(mz - curmz - 18) < tolerance)
74  {
75  // neutral loss peak should be smaller
76  if (curIntensity < intensity)
77  {
78  ions_w_neutrallosses[mz]++;
79  // neutral loss peak not marked
80  //ions_w_neutrallosses[curmz]++;
81  }
82  }
83  else
84  {
85  if (mz - curmz > 18.3)
86  {
87  break;
88  }
89  }
90  --j;
91  }
92  }
93 
94  for (std::map<double, SignedSize>::const_iterator cmit = ions_w_neutrallosses.begin(); cmit != ions_w_neutrallosses.end(); ++cmit)
95  {
96  if (cmit->second >= marks)
97  {
98  marked.insert(std::pair<double, bool>(cmit->first, true));
99  }
100  }
101  return;
102  }
103 
105  static const String getProductName()
106  {
107  return "NeutralLossMarker";
108  }
109 
110  // @}
111 
112  };
113 
114 }
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
static PeakMarker * create()
Definition: NeutralLossMarker.h:51
void apply(std::map< double, bool > &marked, SpectrumType &spectrum)
Definition: NeutralLossMarker.h:55
~NeutralLossMarker() override
destructor
static const String getProductName()
Definition: NeutralLossMarker.h:105
PeakMarker marks peaks that seem to fulfill some criterion.
Definition: PeakMarker.h:23
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