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

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:03 using doxygen 1.8.13