OpenMS
IsotopeMarker.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 
13 
14 #include <map>
15 #include <vector>
16 #include <cmath>
17 #include <utility>
18 
19 namespace OpenMS
20 {
21 
31  class OPENMS_DLLAPI IsotopeMarker :
32  public PeakMarker
33  {
34 public:
35 
36  // @name Constructors and Destructors
37  // @{
40 
42  IsotopeMarker(const IsotopeMarker & source);
43 
45  ~IsotopeMarker() override;
46  // @}
47 
48  // @name Operators
49  // @{
52  // @}
53 
54  // @name Accessors
55  // @{
57  static PeakMarker * create() { return new IsotopeMarker(); }
58 
60  template <typename SpectrumType>
61  void apply(std::map<double, bool> & marked, SpectrumType & spectrum)
62  {
63  double mzvariation = (double)param_.getValue("mz_variation");
64  double invariation = (double)param_.getValue("in_variation");
65  Size marks = param_.getValue("marks");
66 
67  spectrum.sortByPosition();
68 
69  std::map<double, Size> isotopemarks; // possible isotopes
70 
71  for (Size i = 0; i < spectrum.size(); ++i)
72  {
73  double mz = spectrum[i].getPosition()[0];
74  double intensity = spectrum[i].getIntensity();
75  Size j = i + 1;
76 
77  //std::vector<std::pair<double, double> > isotopes = SpectrumGenerator::instance()->isotopepeaks(mz, intensity);
79  auto id = solver.estimateFromPeptideWeight(mz);
80 
81  while (j < spectrum.size() && spectrum[j].getPosition()[0] <= mz + 3 + mzvariation)
82  {
83  double curmz = spectrum[j].getPosition()[0];
84  double curIntensity = spectrum[j].getIntensity();
85  UInt iso = (UInt)(curmz - mz + 0.499999);
86  if (iso > 0 && curmz - mz - iso > mzvariation)
87  {
88  ++j;
89  continue;
90  }
91  if (std::fabs(id.begin()->getIntensity() * intensity - curIntensity) < invariation * id.begin()->getIntensity() * intensity)
92  {
93  isotopemarks[mz]++;
94  isotopemarks[curmz]++;
95  }
96  ++j;
97  }
98  }
99 
100  for (std::map<double, Size>::const_iterator cmit = isotopemarks.begin(); cmit != isotopemarks.end(); ++cmit)
101  {
102  if (cmit->second >= marks)
103  {
104  marked.insert(std::pair<double, bool>(cmit->first, true));
105  }
106  }
107  return;
108  }
109 
111  static const String getProductName()
112  {
113  return "IsotopeMarker";
114  }
115 
116  // @}
117 
118  };
119 
120 }
121 
Isotope pattern generator for coarse isotope distributions.
Definition: CoarseIsotopePatternGenerator.h:79
IsotopeDistribution estimateFromPeptideWeight(double average_weight)
Estimate Peptide Isotopedistribution from weight and number of isotopes that should be reported.
IsotopeMarker marks peak pairs which could represent an ion and its isotope.
Definition: IsotopeMarker.h:33
IsotopeMarker()
default constructor
IsotopeMarker(const IsotopeMarker &source)
copy constructor
static PeakMarker * create()
Definition: IsotopeMarker.h:57
void apply(std::map< double, bool > &marked, SpectrumType &spectrum)
Definition: IsotopeMarker.h:61
~IsotopeMarker() override
destructor
IsotopeMarker & operator=(const IsotopeMarker &source)
assignment operator
static const String getProductName()
Definition: IsotopeMarker.h:111
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
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
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