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-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: 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>
157  class FeaFiModule :
158  public DefaultParamHandler
159  {
160 public:
169 
172  DefaultParamHandler("FeaFiModule"),
173  map_(0),
174  features_(0),
175  ff_(0)
176  {
177  map_ = map;
178  features_ = features;
179  ff_ = ff;
180  }
181 
183  virtual ~FeaFiModule()
184  {
185  }
186 
188  inline IntensityType getPeakIntensity(const FeatureFinderDefs::IndexPair & index) const
189  {
190  //Corrupt index
191  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
192  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
193 
194  return (*map_)[index.first][index.second].getIntensity();
195  }
196 
198  inline CoordinateType getPeakMz(const FeatureFinderDefs::IndexPair & index) const
199  {
200  //Corrupt index
201  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
202  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
203 
204  return (*map_)[index.first][index.second].getMZ();
205  }
206 
208  inline CoordinateType getPeakRt(const FeatureFinderDefs::IndexPair & index) const
209  {
210  //Corrupt index
211  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
212  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
213 
214  return (*map_)[index.first].getRT();
215  }
216 
223  inline void getNextMz(FeatureFinderDefs::IndexPair & index) const
224  {
225  //Corrupt index
226  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
227  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
228 
229  //At the last peak of this spectrum
230  if (index.second + 1 >= (*map_)[index.first].size())
231  {
232  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextMz", index);
233  }
234 
235  ++index.second;
236  }
237 
244  inline void getPrevMz(FeatureFinderDefs::IndexPair & index) const
245  {
246  //Corrupt index
247  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
248  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
249 
250  //begin of scan
251  if (index.second == 0)
252  {
253  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevMz", index);
254  }
255 
256  --index.second;
257  }
258 
266  {
267  //Corrupt index
268  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
269  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
270 
271  CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ(); // mz value we want to find
272  Size index_first_tmp = index.first;
273 
274  ++index.first;
275  while (index.first < map_->size() &&
276  (*map_)[index.first].empty())
277  {
278  ++index.first;
279  }
280  //last scan
281  if (index.first >= map_->size())
282  {
283  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextRt", index);
284  }
285  // now we have a spectrum with scans in it ...
286 
287  // perform binary search to find the neighbour in mz dimension
288  typename SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(), (*map_)[index.first].end(), (*map_)[index_first_tmp][index.second], typename PeakType::PositionLess());
289 
290  // if the found peak is at the end of the spectrum, there is not much we can do...
291  if (it == (*map_)[index.first].end())
292  {
293  index.second = (*map_)[index.first].size() - 1;
294  }
295  // if the found peak is at the beginning of the spectrum, there is also not much we can do !
296  else if (it == (*map_)[index.first].begin())
297  {
298  index.second = 0;
299  }
300  // see if the next smaller one fits better
301  else
302  {
303  // peak to the right is closer (in m/z dimension)
304  if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
305  {
306  index.second = it - (*map_)[index.first].begin();
307  }
308  else // left one is closer
309  {
310  index.second = --it - (*map_)[index.first].begin();
311  }
312  }
313  }
314 
322  {
323  //Corrupt index
324  OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
325  OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
326 
327  // TODO: this seems useless (at least for debug mode) given preconditions above... (and why not in getNextRt()??)
328  if (index.first >= map_->size())
329  {
330  std::cout << "Scan index outside of map!" << std::endl;
331  std::cout << index.first << " " << index.second << std::endl;
332  return;
333  }
334  if (index.second >= (*map_)[index.first].size())
335  {
336  std::cout << "Peak index outside of scan!" << std::endl;
337  std::cout << index.first << " " << index.second << std::endl;
338  return;
339  }
340 
341  CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ();
342  Size index_first_tmp = index.first;
343 
344  // first scan
345  if (index.first == 0)
346  {
347  throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
348  }
349 
350  --index.first;
351  while ((index.first > 0) && ((*map_)[index.first].empty()))
352  {
353  --index.first;
354  }
355  // we only found an empty scan
356  if ((*map_)[index.first].empty()) throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
357 
358  // perform binary search to find the neighbour in mz dimension
359 
360  typename MapType::SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(),
361  (*map_)[index.first].end(),
362  (*map_)[index_first_tmp][index.second],
363  typename PeakType::PositionLess());
364 
365  // if the found peak is at the end of the spectrum, there is not much we can do.
366  if (it == (*map_)[index.first].end())
367  {
368  index.second = (*map_)[index.first].size() - 1;
369  }
370  // if the found peak is at the beginning of the spectrum, there is not much we can do.
371  else if (it == (*map_)[index.first].begin())
372  {
373  index.second = 0;
374  }
375  // see if the next smaller one fits better
376  else
377  {
378  // peak to the right is closer (in m/z dimension)
379  if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
380  {
381  index.second = it - (*map_)[index.first].begin();
382  }
383  else
384  {
385  index.second = --it - (*map_)[index.first].begin();
386  }
387  }
388  }
389 
391  void addConvexHull(const FeatureFinderDefs::IndexSet & set, Feature & feature) const
392  {
393  std::vector<DPosition<2> > points;
394  points.reserve(set.size());
395  DPosition<2> tmp;
396  for (FeatureFinderDefs::IndexSet::const_iterator it = set.begin(); it != set.end(); ++it)
397  {
398  tmp[Peak2D::MZ] = (*map_)[it->first][it->second].getMZ();
399  tmp[Peak2D::RT] = (*map_)[it->first].getRT();
400  points.push_back(tmp);
401  }
402  feature.getConvexHulls().resize(feature.getConvexHulls().size() + 1);
403  // computes convex hull
404  feature.getConvexHulls().back().addPoints(points);
405  }
406 
407 protected:
409  const MapType * map_;
414 
415 private:
417  FeaFiModule();
419  FeaFiModule & operator=(const FeaFiModule &);
421  FeaFiModule(const FeaFiModule &);
422 
423  }; // class FeaFiModule
424 
425 } // namespace OpenMS
426 
427 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
Implements a module of the FeatureFinder algorithm.
Definition: FeaFiModule.h:157
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:223
CoordinateType getPeakRt(const FeatureFinderDefs::IndexPair &index) const
Returns the retention time of a peak.
Definition: FeaFiModule.h:208
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:188
IntensityLess(const IntensityLess &rhs)
Copy ctor.
Definition: FeaFiModule.h:66
void getNextRt(FeatureFinderDefs::IndexPair &index)
fills index with the index of the nearest peak in the next scan
Definition: FeaFiModule.h:265
PeakType::IntensityType IntensityType
Input intensity type.
Definition: FeaFiModule.h:166
A container for features.
Definition: FeatureMap.h:93
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:123
IntensityLess()
Default ctor undefined since we cannot compare without a FeaFiModule.
FeaFiModuleType::IntensityType operator*() const
Definition: FeaFiModule.h:141
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void getPrevMz(FeatureFinderDefs::IndexPair &index) const
fills index with the index of previous peak in m/z dimension
Definition: FeaFiModule.h:244
FeatureFinder * ff_
Pointer to the calling FeatureFinder that is used to access the feature flags and report progress...
Definition: FeaFiModule.h:413
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:409
Comparator by position. Lexicographical comparison (first RT then m/z) is done.
Definition: Peak2D.h:327
Mass-to-charge dimension id (1 if used as a const int)
Definition: Peak2D.h:77
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:198
FeatureMap * features_
Output data pointer.
Definition: FeaFiModule.h:411
void getPrevRt(FeatureFinderDefs::IndexPair &index)
fills index with the index of the nearest peak in the previous scan
Definition: FeaFiModule.h:321
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:391
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:70
FeaFiModule(const MSExperiment< PeakType > *map, FeatureMap *features, FeatureFinder *ff)
Constructor.
Definition: FeaFiModule.h:171
MzIterator(const FeatureFinderDefs::IndexSet::const_iterator &iter, const FeaFiModuleType *module)
Definition: FeaFiModule.h:113
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:69
m/z iterator for a FeatureFinderDefs::IndexSet
Definition: FeaFiModule.h:110
PeakType::CoordinateType CoordinateType
Input coordinate type.
Definition: FeaFiModule.h:168
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.
Retention time dimension id (0 if used as a const int)
Definition: Peak2D.h:76
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:183
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
MSExperiment< PeakType > MapType
Input map type.
Definition: FeaFiModule.h:162
MapType::SpectrumType SpectrumType
Input spectrum type.
Definition: FeaFiModule.h:164
const FeaFiModuleType * module_
Definition: FeaFiModule.h:147
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

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Aug 25 2015 05:53:45 using doxygen 1.8.9.1