OpenMS  2.5.0
IsotopeMarker.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 #pragma once
36 
39 
40 #include <map>
41 #include <vector>
42 #include <cmath>
43 #include <utility>
44 
45 namespace OpenMS
46 {
47 
57  class OPENMS_DLLAPI IsotopeMarker :
58  public PeakMarker
59  {
60 public:
61 
62  // @name Constructors and Destructors
63  // @{
65  IsotopeMarker();
66 
68  IsotopeMarker(const IsotopeMarker & source);
69 
71  ~IsotopeMarker() override;
72  // @}
73 
74  // @name Operators
75  // @{
77  IsotopeMarker & operator=(const IsotopeMarker & source);
78  // @}
79 
80  // @name Accessors
81  // @{
83  static PeakMarker * create() { return new IsotopeMarker(); }
84 
86  template <typename SpectrumType>
87  void apply(std::map<double, bool> & marked, SpectrumType & spectrum)
88  {
89  double mzvariation = (double)param_.getValue("mz_variation");
90  double invariation = (double)param_.getValue("in_variation");
91  Size marks = param_.getValue("marks");
92 
93  spectrum.sortByPosition();
94 
95  std::map<double, Size> isotopemarks; // possible isotopes
96 
97  for (Size i = 0; i < spectrum.size(); ++i)
98  {
99  double mz = spectrum[i].getPosition()[0];
100  double intensity = spectrum[i].getIntensity();
101  Size j = i + 1;
102 
103  //std::vector<std::pair<double, double> > isotopes = SpectrumGenerator::instance()->isotopepeaks(mz, intensity);
105  auto id = solver.estimateFromPeptideWeight(mz);
106 
107  while (j < spectrum.size() && spectrum[j].getPosition()[0] <= mz + 3 + mzvariation)
108  {
109  double curmz = spectrum[j].getPosition()[0];
110  double curIntensity = spectrum[j].getIntensity();
111  UInt iso = (UInt)(curmz - mz + 0.499999);
112  if (iso > 0 && curmz - mz - iso > mzvariation)
113  {
114  ++j;
115  continue;
116  }
117  if (std::fabs(id.begin()->getIntensity() * intensity - curIntensity) < invariation * id.begin()->getIntensity() * intensity)
118  {
119  isotopemarks[mz]++;
120  isotopemarks[curmz]++;
121  }
122  ++j;
123  }
124  }
125 
126  for (std::map<double, Size>::const_iterator cmit = isotopemarks.begin(); cmit != isotopemarks.end(); ++cmit)
127  {
128  if (cmit->second >= marks)
129  {
130  marked.insert(std::pair<double, bool>(cmit->first, true));
131  }
132  }
133  return;
134  }
135 
137  static const String getProductName()
138  {
139  return "IsotopeMarker";
140  }
141 
142  // @}
143 
144  };
145 
146 }
147 
OpenMS::IsotopeMarker::getProductName
static const String getProductName()
Definition: IsotopeMarker.h:137
OpenMS::IsotopeMarker
IsotopeMarker marks peak pairs which could represent an ion and its isotope.
Definition: IsotopeMarker.h:57
double
PeakMarker.h
OpenMS::CoarseIsotopePatternGenerator::estimateFromPeptideWeight
IsotopeDistribution estimateFromPeptideWeight(double average_weight)
Estimate Peptide Isotopedistribution from weight and number of isotopes that should be reported.
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::CoarseIsotopePatternGenerator
Isotope pattern generator for coarse isotope distributions.
Definition: CoarseIsotopePatternGenerator.h:96
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::IsotopeMarker::create
static PeakMarker * create()
Definition: IsotopeMarker.h:83
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
CoarseIsotopePatternGenerator.h
OpenMS::MSSpectrum::sortByPosition
void sortByPosition()
Lexicographically sorts the peaks by their position.
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::PeakMarker
PeakMarker marks peaks that seem to fulfill some criterion.
Definition: PeakMarker.h:47
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::IsotopeMarker::apply
void apply(std::map< double, bool > &marked, SpectrumType &spectrum)
Definition: IsotopeMarker.h:87