OpenMS
IsotopeMarker.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 
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  // @{
56 
58  template <typename SpectrumType>
59  void apply(std::map<double, bool> & marked, SpectrumType & spectrum)
60  {
61  double mzvariation = (double)param_.getValue("mz_variation");
62  double invariation = (double)param_.getValue("in_variation");
63  Size marks = param_.getValue("marks");
64 
65  spectrum.sortByPosition();
66 
67  std::map<double, Size> isotopemarks; // possible isotopes
68 
69  for (Size i = 0; i < spectrum.size(); ++i)
70  {
71  double mz = spectrum[i].getPosition()[0];
72  double intensity = spectrum[i].getIntensity();
73  Size j = i + 1;
74 
75  //std::vector<std::pair<double, double> > isotopes = SpectrumGenerator::instance()->isotopepeaks(mz, intensity);
77  auto id = solver.estimateFromPeptideWeight(mz);
78 
79  while (j < spectrum.size() && spectrum[j].getPosition()[0] <= mz + 3 + mzvariation)
80  {
81  double curmz = spectrum[j].getPosition()[0];
82  double curIntensity = spectrum[j].getIntensity();
83  UInt iso = (UInt)(curmz - mz + 0.499999);
84  if (iso > 0 && curmz - mz - iso > mzvariation)
85  {
86  ++j;
87  continue;
88  }
89  if (std::fabs(id.begin()->getIntensity() * intensity - curIntensity) < invariation * id.begin()->getIntensity() * intensity)
90  {
91  isotopemarks[mz]++;
92  isotopemarks[curmz]++;
93  }
94  ++j;
95  }
96  }
97 
98  for (std::map<double, Size>::const_iterator cmit = isotopemarks.begin(); cmit != isotopemarks.end(); ++cmit)
99  {
100  if (cmit->second >= marks)
101  {
102  marked.insert(std::pair<double, bool>(cmit->first, true));
103  }
104  }
105  return;
106  }
107 
108  // @}
109 
110  };
111 
112 }
113 
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
void apply(std::map< double, bool > &marked, SpectrumType &spectrum)
Definition: IsotopeMarker.h:59
~IsotopeMarker() override
destructor
IsotopeMarker & operator=(const IsotopeMarker &source)
assignment operator
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
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
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