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

OpenMS / TOPP release 2.0.0 Documentation generated on Wed Mar 30 2016 12:49:24 using doxygen 1.8.11