Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FeaFiModule.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-2013.
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: Clemens Groepl $
32 // $Authors: Marc Sturm, Clemens Groepl $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
37 
42 
43 namespace OpenMS
44 {
45 
46  class FeatureFinder;
47 
48  namespace Internal
49  {
50  //-------------------------------------------------------------------
51 
55  template <typename FeaFiModuleType>
56  struct IntensityLess :
57  std::binary_function<typename FeatureFinderDefs::IndexPair, typename FeatureFinderDefs::IndexPair, bool>
58  {
60  IntensityLess(const FeaFiModuleType & module) :
61  module_(module)
62  {
63  }
64 
67  module_(rhs.module_)
68  {
69  }
70 
72  inline bool operator()(const typename FeatureFinderDefs::IndexPair & left, const typename FeatureFinderDefs::IndexPair & right) const
73  {
74  return module_.getPeakIntensity(left) < module_.getPeakIntensity(right);
75  }
76 
77 private:
79  const FeaFiModuleType & module_;
81  IntensityLess();
82  }; // struct IntensityLess
83 
84  //-------------------------------------------------------------------
85 
87  template <typename FeaFiModuleType>
89  FeatureFinderDefs::IndexSet::const_iterator
90  {
91  IntensityIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
92  FeatureFinderDefs::IndexSet::const_iterator(iter),
93  module_(module)
94  {
95  }
96 
97  typename FeaFiModuleType::IntensityType operator*() const
98  {
99  return module_->getPeakIntensity(FeatureFinderDefs::IndexSet::const_iterator::operator*());
100  }
101 
102 protected:
103  const FeaFiModuleType * module_;
104  };
105 
106  //-------------------------------------------------------------------
107 
109  template <typename FeaFiModuleType>
110  struct MzIterator :
111  FeatureFinderDefs::IndexSet::const_iterator
112  {
113  MzIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
114  FeatureFinderDefs::IndexSet::const_iterator(iter),
115  module_(module)
116  {
117  }
118 
119  typename FeaFiModuleType::IntensityType operator*() const
120  {
121  return module_->getPeakMz(FeatureFinderDefs::IndexSet::const_iterator::operator*());
122  }
123 
124 protected:
125  const FeaFiModuleType * module_;
126  };
127 
128  //-------------------------------------------------------------------
129 
131  template <typename FeaFiModuleType>
132  struct RtIterator :
133  FeatureFinderDefs::IndexSet::const_iterator
134  {
135  RtIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
136  FeatureFinderDefs::IndexSet::const_iterator(iter),
137  module_(module)
138  {
139  }
140 
141  typename FeaFiModuleType::IntensityType operator*() const
142  {
143  return module_->getPeakRt(FeatureFinderDefs::IndexSet::const_iterator::operator*());
144  }
145 
146 protected:
147  const FeaFiModuleType * module_;
148  };
149 
150  //-------------------------------------------------------------------
151  } // namespace Internal
152 
156  template <class PeakType, class FeatureType>
157  class FeaFiModule :
158  public DefaultParamHandler
159  {
160 public:
171 
174  DefaultParamHandler("FeaFiModule"),
175  map_(0),
176  features_(0),
177  ff_(0)
178  {
179  map_ = map;
180  features_ = features;
181  ff_ = ff;
182  }
183 
185  virtual ~FeaFiModule()
186  {
187  }
188 
191  {
192  //Corrupt index
193  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
194  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
195 
196  return (*map_)[index.first][index.second].getIntensity();
197  }
198 
201  {
202  //Corrupt index
203  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
204  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
205 
206  return (*map_)[index.first][index.second].getMZ();
207  }
208 
211  {
212  //Corrupt index
213  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
214  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
215 
216  return (*map_)[index.first].getRT();
217  }
218 
225  inline void getNextMz(FeatureFinderDefs::IndexPair & index) const
226  {
227  //Corrupt index
228  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
229  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
230 
231  //At the last peak of this spectrum
232  if (index.second + 1 >= (*map_)[index.first].size())
233  {
234  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextMz", index);
235  }
236 
237  ++index.second;
238  }
239 
246  inline void getPrevMz(FeatureFinderDefs::IndexPair & index) const
247  {
248  //Corrupt index
249  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
250  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
251 
252  //begin of scan
253  if (index.second == 0)
254  {
255  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevMz", index);
256  }
257 
258  --index.second;
259  }
260 
268  {
269  //Corrupt index
270  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
271  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
272 
273  CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ(); // mz value we want to find
274  Size index_first_tmp = index.first;
275 
276  ++index.first;
277  while (index.first < map_->size() &&
278  (*map_)[index.first].empty())
279  {
280  ++index.first;
281  }
282  //last scan
283  if (index.first >= map_->size())
284  {
285  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextRt", index);
286  }
287  // now we have a spectrum with scans in it ...
288 
289  // perform binary search to find the neighbour in mz dimension
290  typename SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(), (*map_)[index.first].end(), (*map_)[index_first_tmp][index.second], typename PeakType::PositionLess());
291 
292  // if the found peak is at the end of the spectrum, there is not much we can do...
293  if (it == (*map_)[index.first].end())
294  {
295  index.second = (*map_)[index.first].size() - 1;
296  }
297  // if the found peak is at the beginning of the spectrum, there is also not much we can do !
298  else if (it == (*map_)[index.first].begin())
299  {
300  index.second = 0;
301  }
302  // see if the next smaller one fits better
303  else
304  {
305  // peak to the right is closer (in m/z dimension)
306  if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
307  {
308  index.second = it - (*map_)[index.first].begin();
309  }
310  else // left one is closer
311  {
312  index.second = --it - (*map_)[index.first].begin();
313  }
314  }
315  }
316 
324  {
325  //Corrupt index
326  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
327  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
328 
329  // TODO: this seems useless (at least for debug mode) given preconditions above... (and why not in getNextRt()??)
330  if (index.first >= map_->size())
331  {
332  std::cout << "Scan index outside of map!" << std::endl;
333  std::cout << index.first << " " << index.second << std::endl;
334  return;
335  }
336  if (index.second >= (*map_)[index.first].size())
337  {
338  std::cout << "Peak index outside of scan!" << std::endl;
339  std::cout << index.first << " " << index.second << std::endl;
340  return;
341  }
342 
343  CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ();
344  Size index_first_tmp = index.first;
345 
346  // first scan
347  if (index.first == 0)
348  {
349  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
350  }
351 
352  --index.first;
353  while ((index.first > 0) && ((*map_)[index.first].empty()))
354  {
355  --index.first;
356  }
357  // we only found an empty scan
358  if ((*map_)[index.first].empty()) throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
359 
360  // perform binary search to find the neighbour in mz dimension
361 
362  typename MapType::SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(),
363  (*map_)[index.first].end(),
364  (*map_)[index_first_tmp][index.second],
365  typename PeakType::PositionLess());
366 
367  // if the found peak is at the end of the spectrum, there is not much we can do.
368  if (it == (*map_)[index.first].end())
369  {
370  index.second = (*map_)[index.first].size() - 1;
371  }
372  // if the found peak is at the beginning of the spectrum, there is not much we can do.
373  else if (it == (*map_)[index.first].begin())
374  {
375  index.second = 0;
376  }
377  // see if the next smaller one fits better
378  else
379  {
380  // peak to the right is closer (in m/z dimension)
381  if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
382  {
383  index.second = it - (*map_)[index.first].begin();
384  }
385  else
386  {
387  index.second = --it - (*map_)[index.first].begin();
388  }
389  }
390  }
391 
393  void addConvexHull(const FeatureFinderDefs::IndexSet & set, Feature & feature) const
394  {
395  std::vector<DPosition<2> > points;
396  points.reserve(set.size());
397  DPosition<2> tmp;
398  for (FeatureFinderDefs::IndexSet::const_iterator it = set.begin(); it != set.end(); ++it)
399  {
400  tmp[Peak2D::MZ] = (*map_)[it->first][it->second].getMZ();
401  tmp[Peak2D::RT] = (*map_)[it->first].getRT();
402  points.push_back(tmp);
403  }
404  feature.getConvexHulls().resize(feature.getConvexHulls().size() + 1);
405  // computes convex hull
406  feature.getConvexHulls().back().addPoints(points);
407  }
408 
409 protected:
411  const MapType * map_;
416 
417 private:
419  FeaFiModule();
421  FeaFiModule & operator=(const FeaFiModule &);
423  FeaFiModule(const FeaFiModule &);
424 
425  }; // class FeaFiModule
426 
427 } // namespace OpenMS
428 
429 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
Implements a module of the FeatureFinder algorithm.
Definition: FeaFiModule.h:157
Real IntensityType
Intensity type.
Definition: Peak2D.h:63
IsotopeCluster::IndexPair IndexPair
Index to peak consisting of two UInts (scan index / peak index)
Definition: FeatureFinderDefs.h:54
void getNextMz(FeatureFinderDefs::IndexPair &index) const
fills index with the index of next peak in m/z dimension
Definition: FeaFiModule.h:225
CoordinateType getPeakRt(const FeatureFinderDefs::IndexPair &index) const
Returns the retention time of a peak.
Definition: FeaFiModule.h:210
IntensityIterator(const FeatureFinderDefs::IndexSet::const_iterator &iter, const FeaFiModuleType *module)
Definition: FeaFiModule.h:91
Size size() const
Definition: MSExperiment.h:117
IntensityType getPeakIntensity(const FeatureFinderDefs::IndexPair &index) const
Returns the intensity of a peak.
Definition: FeaFiModule.h:190
IntensityLess(const IntensityLess &rhs)
Copy ctor.
Definition: FeaFiModule.h:66
FeatureMapType * features_
Output data pointer.
Definition: FeaFiModule.h:413
Retention time dimension id (0 if used as a const int)
Definition: Peak2D.h:76
void getNextRt(FeatureFinderDefs::IndexPair &index)
fills index with the index of the nearest peak in the next scan
Definition: FeaFiModule.h:267
PeakType::IntensityType IntensityType
Input intensity type.
Definition: FeaFiModule.h:168
A container for features.
Definition: FeatureMap.h:111
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: Macros.h:107
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:125
IntensityLess()
Default ctor undefined since we cannot compare without a FeaFiModule.
Mass-to-charge dimension id (1 if used as a const int)
Definition: Peak2D.h:77
FeaFiModuleType::IntensityType operator*() const
Definition: FeaFiModule.h:141
void getPrevMz(FeatureFinderDefs::IndexPair &index) const
fills index with the index of previous peak in m/z dimension
Definition: FeaFiModule.h:246
FeatureFinder * ff_
Pointer to the calling FeatureFinder that is used to access the feature flags and report progress...
Definition: FeaFiModule.h:415
The purpose of this struct is to provide definitions of classes and typedefs which are used throughou...
Definition: FeatureFinderDefs.h:51
const MapType * map_
Input data pointer.
Definition: FeaFiModule.h:411
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition: Peak2D.h:324
FeaFiModule & operator=(const FeaFiModule &)
Not implemented.
RtIterator(const FeatureFinderDefs::IndexSet::const_iterator &iter, const FeaFiModuleType *module)
Definition: FeaFiModule.h:135
FeaFiModuleType::IntensityType operator*() const
Definition: FeaFiModule.h:119
CoordinateType getPeakMz(const FeatureFinderDefs::IndexPair &index) const
Returns the m/z of a peak.
Definition: FeaFiModule.h:200
void getPrevRt(FeatureFinderDefs::IndexPair &index)
fills index with the index of the nearest peak in the previous scan
Definition: FeaFiModule.h:323
const FeaFiModuleType & module_
Reference to the FeaFiModule.
Definition: FeaFiModule.h:79
const std::vector< ConvexHull2D > & getConvexHulls() const
Non-mutable access to the convex hulls.
IsotopeCluster::IndexSet IndexSet
A set of peak indices.
Definition: FeatureFinderDefs.h:60
void addConvexHull(const FeatureFinderDefs::IndexSet &set, Feature &feature) const
Calculates the convex hull of a index set and adds it to the feature.
Definition: FeaFiModule.h:393
const FeaFiModuleType * module_
Definition: FeaFiModule.h:125
Retention time iterator for a FeatureFinderDefs::IndexSet.
Definition: FeaFiModule.h:132
Comparator that allows to compare the indices of two peaks by their intensity.
Definition: FeaFiModule.h:56
FeaFiModuleType::IntensityType operator*() const
Definition: FeaFiModule.h:97
Exception that is thrown if a method an invalid IndexPair is given.
Definition: FeatureFinderDefs.h:66
An LC-MS feature.
Definition: Feature.h:66
MzIterator(const FeatureFinderDefs::IndexSet::const_iterator &iter, const FeaFiModuleType *module)
Definition: FeaFiModule.h:113
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
m/z iterator for a FeatureFinderDefs::IndexSet
Definition: FeaFiModule.h:110
PeakType::CoordinateType CoordinateType
Input coordinate type.
Definition: FeaFiModule.h:170
Intensity iterator for a FeatureFinderDefs::IndexSet.
Definition: FeaFiModule.h:88
std::vector< SpectrumType >::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSExperiment.h:103
FeaFiModule()
Not implemented.
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
IntensityLess(const FeaFiModuleType &module)
Constructor that takes a FeaFiModule reference.
Definition: FeaFiModule.h:60
The main feature finder class.
Definition: FeatureFinder.h:57
virtual ~FeaFiModule()
destructor
Definition: FeaFiModule.h:185
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:90
MSExperiment< PeakType > MapType
Input map type.
Definition: FeaFiModule.h:164
MapType::SpectrumType SpectrumType
Input spectrum type.
Definition: FeaFiModule.h:166
const FeaFiModuleType * module_
Definition: FeaFiModule.h:147
FeatureMap< FeatureType > FeatureMapType
Output feature map type.
Definition: FeaFiModule.h:162
const FeaFiModuleType * module_
Definition: FeaFiModule.h:103
bool operator()(const typename FeatureFinderDefs::IndexPair &left, const typename FeatureFinderDefs::IndexPair &right) const
Compare with respect to intensity.
Definition: FeaFiModule.h:72
FeaFiModule(const MSExperiment< PeakType > *map, FeatureMap< FeatureType > *features, FeatureFinder *ff)
Constructor.
Definition: FeaFiModule.h:173

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:13 using doxygen 1.8.5