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