OpenMS
ParentPeakMower.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: Mathias Walzer $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
16 #include <vector>
17 
18 namespace OpenMS
19 {
20 
28  class OPENMS_DLLAPI ParentPeakMower :
29  public DefaultParamHandler
30  {
31 public:
32 
33  // @name Constructors and Destructors
34  // @{
37 
40 
42  ~ParentPeakMower() override;
43  // @}
44 
45  // @name Operators
46  // @{
49  // @}
50 
51  // @name Accessors
52  // @{
54 
56  template <typename SpectrumType>
57  void filterSpectrum(SpectrumType& spectrum)
58  {
59  typedef typename SpectrumType::Iterator Iterator;
60 
61  clean_all_charge_states_ = (Int)param_.getValue("clean_all_charge_states");
62  consider_NH3_loss_ = (Int)param_.getValue("consider_NH3_loss");
63  consider_H2O_loss_ = (Int)param_.getValue("consider_H2O_loss");
64  window_size_ = (double)param_.getValue("window_size");
65  reduce_by_factor_ = (Int)param_.getValue("reduce_by_factor");
66  factor_ = (double)param_.getValue("factor");
67  set_to_zero_ = (Int)param_.getValue("set_to_zero");
68 
69  if (spectrum.getMSLevel() == 1)
70  {
71  std::cerr << "Error: ParentPeakMower cannot be applied to MS level 1" << std::endl;
72  return;
73  }
74 
75  //get precursor peak position precursor peak
76  double pre_pos = 0.0;
77  if (!spectrum.getPrecursors().empty()) pre_pos = spectrum.getPrecursors()[0].getMZ();
78 
79  if (pre_pos == 0)
80  {
81  std::cerr << "ParentPeakMower: Warning, Precursor Position not set" << std::endl;
82  return;
83  }
84 
85  Size pre_charge = spectrum.getPrecursors()[0].getCharge();
86  if (pre_charge == 0)
87  {
88  default_charge_ = (Size)param_.getValue("default_charge");
89  std::cerr << "ParentPeakMower: Warning, Precursor charge not set, assuming default charge (" << default_charge_ << ")" << std::endl;
90  pre_charge = default_charge_;
91  }
92 
93  pre_pos *= pre_charge;
94 
95  // identify the ranges which are to be considered
96  std::vector<DRange<1> > ranges;
97  for (Size z = 1; z <= pre_charge; ++z)
98  {
99  if (clean_all_charge_states_ || z == pre_charge)
100  {
101  // no adjusting needed for this charge
102  DPosition<1> pre_z_pos, pos;
103  DRange<1> range;
104 
105  // adjust the m/z by weight of precursor and charge
106  pre_z_pos = DPosition<1>(pre_pos / double(z));
107  range = DRange<1>(pre_z_pos - window_size_, pre_z_pos + window_size_);
108  ranges.push_back(range);
109 
110  if (consider_NH3_loss_)
111  {
112  pos = DPosition<1>(pre_z_pos - 17.0 / double(z));
113  range = DRange<1>(pos - window_size_, pos + window_size_);
114  ranges.push_back(range);
115  }
116  if (consider_H2O_loss_)
117  {
118  pos = DPosition<1>(pre_z_pos - 18.0 / double(z));
119  range = DRange<1>(pos - window_size_, pos + window_size_);
120  ranges.push_back(range);
121  }
122  }
123  }
124 
125 //for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
126 //{
127 //std::cerr << *rit << std::endl;
128 //}
129 
130  // apply the intensity reduction to the collected ranges
131  for (Iterator it = spectrum.begin(); it != spectrum.end(); ++it)
132  {
133  for (std::vector<DRange<1> >::const_iterator rit = ranges.begin(); rit != ranges.end(); ++rit)
134  {
135  if (rit->encloses(it->getPosition()))
136  {
137  if (reduce_by_factor_)
138  {
139  it->setIntensity(it->getIntensity() / factor_);
140  break;
141  }
142 
143  if (set_to_zero_)
144  {
145  it->setIntensity(0.0);
146  break;
147  }
148  }
149  }
150  }
151 
152  return;
153  }
154 
156 
157  void filterPeakMap(PeakMap& exp);
158 
159  //TODO reimplement DefaultParamHandler::updateMembers_()
160 
162 
163 private:
168  double window_size_;
170  double factor_;
172 
173  };
174 
175 }
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:108
UInt getMSLevel() const
Returns the MS level.
ParentPeakMower gets rid of high peaks that could stem from unfragmented precursor ions.
Definition: ParentPeakMower.h:30
ParentPeakMower(const ParentPeakMower &source)
copy constructor
bool reduce_by_factor_
Definition: ParentPeakMower.h:169
double window_size_
Definition: ParentPeakMower.h:168
ParentPeakMower()
default constructor
bool consider_H2O_loss_
Definition: ParentPeakMower.h:167
void filterPeakSpectrum(PeakSpectrum &spectrum)
void filterPeakMap(PeakMap &exp)
bool consider_NH3_loss_
Definition: ParentPeakMower.h:166
ParentPeakMower & operator=(const ParentPeakMower &source)
assignment operator
void filterSpectrum(SpectrumType &spectrum)
Definition: ParentPeakMower.h:57
bool set_to_zero_
Definition: ParentPeakMower.h:171
double factor_
Definition: ParentPeakMower.h:170
~ParentPeakMower() override
destructor
Size default_charge_
Definition: ParentPeakMower.h:164
bool clean_all_charge_states_
Definition: ParentPeakMower.h:165
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
int Int
Signed integer type.
Definition: Types.h:76
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