| OpenMS 2.5.0

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
MatchedIterator< CONT_T, TRAIT, CONST_T > Class Template Reference

For each element in the reference container the closest peak in the target will be searched. If no match is found within the tolerance window, the peak will be skipped over. More...

`#include <OpenMS/DATASTRUCTURES/MatchedIterator.h>`

## Public Types

using | iterator_category = std::forward_iterator_tag
using | value_type = typename CONT_T::value_type
using | difference_type = std::ptrdiff_t
using | pointer = typename std::conditional< CONST_T, typename CONT_T::value_type const *, typename CONT_T::value_type * >::type
using | reference = typename std::conditional< CONST_T, typename CONT_T::value_type const &, typename CONT_T::value_type & >::type
using | CONT_IT = typename std::conditional< CONST_T, typename CONT_T::const_iterator, typename CONT_T::iterator >::type
using | CONST_CONT_IT = typename CONT_T::const_iterator

## Public Member Functions

| MatchedIterator (const CONT_T &ref, const CONT_T &target, float tolerance)
| Constructs a MatchedIterator on two containers. The way a match is found, depends on the TRAIT type (ppm or Da tolerance) More...
| MatchedIterator (const CONST_CONT_IT ref_begin, const CONST_CONT_IT ref_end, const CONST_CONT_IT tgt_begin, const CONST_CONT_IT tgt_end, float tolerance)
| Constructs a MatchedIterator on two containers. The way a match is found, depends on the TRAIT type (ppm or Da tolerance) More...
| MatchedIterator ()
| Default CTor; do not use this for anything other than assigning to it;. More...
| MatchedIterator (const MatchedIterator &rhs)=default
| Copy CTor (default) More...
MatchedIterator & | operator= (const MatchedIterator &rhs)=default
| Assignment operator (default) More...
bool | operator== (const MatchedIterator &rhs) const
bool | operator!= (const MatchedIterator &rhs) const
template<bool _CONST = CONST_T>
std::enable_if< _CONST, reference >::type | operator* () const
| dereference current target element More...
template<bool _CONST = CONST_T>
std::enable_if< !_CONST, reference >::type | operator* ()
template<bool _CONST = CONST_T>
std::enable_if< _CONST, pointer >::type | operator-> () const
| pointer to current target element More...
template<bool _CONST = CONST_T>
std::enable_if< !_CONST, pointer >::type | operator-> ()
const value_type & | ref () const
| current element in reference container More...
size_t | refIdx () const
| index into reference container More...
size_t | tgtIdx () const
| index into target container More...
MatchedIterator & | operator++ ()
| Advances to the next valid pair. More...
MatchedIterator | operator++ (int)
| post-increment More...

## Static Public Member Functions

static MatchedIterator | end ()
| the end iterator More...

## Protected Member Functions

| MatchedIterator (bool)
void | setToEnd_ ()
bool | isEnd_ () const
void | advanceTarget_ ()

## Protected Attributes

CONST_CONT_IT | ref_begin_
CONST_CONT_IT | ref_end_
CONST_CONT_IT | tgt_begin_
CONST_CONT_IT | tgt_end_
CONT_IT | it_ref_
CONT_IT | it_tgt_
float | tol_
bool | is_end_ = false

## Detailed Description

### template<typename CONT_T, typename TRAIT, bool CONST_T = true>
class OpenMS::MatchedIterator< CONT_T, TRAIT, CONST_T >

For each element in the reference container the closest peak in the target will be searched. If no match is found within the tolerance window, the peak will be skipped over.

This class can be used for example to iterate through the matching peaks in two spectra (e.g. experimental spectrum and reference spectrum) that are within a given tolerance (in m/z, RT, or something user-defined).

The iterator always choses the closest matching peak in the target container, if more than one candidate is found in the match-window. If two peaks have equal distance, the smaller value is preferred. If no peak is found within the given tolerance (distance), the reference peak does not yield a result and the next reference peak is tested. This means the operator++ can be called at most(!) ref.size()-1 times before it == is.end().

The TRAIT template argument (e.g., ValueTrait, DaTrait or PpmTrait) encodes the distance metric (on the value directly, or a member of the value_type, e.g. ppm or Da for m/z, or RT or any other metric you like). The simplest use case would be a vector<float> or similar. The TRAIT struct just defines two functions which return some distance metrics and accept elements of the container CONT_T as arguments. Both containers must be sorted with respect to the comparator used in TRAIT.

The CONST_T template argument switches between a 'const_iterator' and an 'iterator'.

This iterator is much more efficient than iterating over the reference container and calling findNearest(), i.e. binary search on the target container, i.e. O(n+m) vs. O(n*log(m)). Since this container is much more cache-friendly, the actual speedups are even larger.

## Member Typedef Documentation

## ◆ CONST_CONT_IT

using CONST_CONT_IT = typename CONT_T::const_iterator

## ◆ CONT_IT

using CONT_IT = typename std::conditional<CONST_T, typename CONT_T::const_iterator, typename CONT_T::iterator>::type

## ◆ difference_type

using difference_type = std::ptrdiff_t

## ◆ iterator_category

using iterator_category = std::forward_iterator_tag

## ◆ pointer

using pointer = typename std::conditional<CONST_T, typename CONT_T::value_type const*, typename CONT_T::value_type*>::type

## ◆ reference

using reference = typename std::conditional<CONST_T, typename CONT_T::value_type const&, typename CONT_T::value_type&>::type

## ◆ value_type

using value_type = typename CONT_T::value_type

## Constructor & Destructor Documentation

## ◆ MatchedIterator() [1/5]

MatchedIterator | ( | const CONT_T & | ref,
|  | const CONT_T & | target,
|  | float | tolerance
| ) |  |

inline explicit

Constructs a MatchedIterator on two containers. The way a match is found, depends on the TRAIT type (ppm or Da tolerance)

For each element in the reference container the closest peak in the target will be searched. If no match is found within the tolerance window, the peak will be skipped over.

Parameters

  ref | For each element in this reference container the closest peak in the target will be searched
  target | Target container
  tolerance | Maximal distance between a valid matching pair in reference and target (unit is according to TRAIT::getDiffAbsolute(), i.e. could be ppm, Da, seconds, ...)

## ◆ MatchedIterator() [2/5]

MatchedIterator | ( | const CONST_CONT_IT | ref_begin,
|  | const CONST_CONT_IT | ref_end,
|  | const CONST_CONT_IT | tgt_begin,
|  | const CONST_CONT_IT | tgt_end,
|  | float | tolerance
| ) |  |

inline explicit

Constructs a MatchedIterator on two containers. The way a match is found, depends on the TRAIT type (ppm or Da tolerance)

For each element in the reference container the closest peak in the target will be searched. If no match is found within the tolerance window, the peak will be skipped over.

Parameters

  ref_begin | Begin range of reference container
  ref_end | End range of reference container
  tgt_begin | Begin range of reference container
  tgt_end | End range of reference container
  tolerance | Maximal distance between a valid matching pair in reference and target (unit is according to TRAIT::getDiffAbsolute(), i.e. could be ppm, Da, seconds, ...)

References MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::setToEnd_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_begin_, and MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_end_.

## ◆ MatchedIterator() [3/5]

MatchedIterator | ( |  | ) |

inline explicit

Default CTor; do not use this for anything other than assigning to it;.

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::end().

## ◆ MatchedIterator() [4/5]

MatchedIterator | ( | const MatchedIterator< CONT_T, TRAIT, CONST_T > & | rhs | ) |

default

Copy CTor (default)

## ◆ MatchedIterator() [5/5]

MatchedIterator | ( | bool |  | ) |

inline protected

protected Ctor which creates and end() iterator the bool argument is only used to call the correct target (its value is ignored)

## Member Function Documentation

## ◆ advanceTarget_()

void advanceTarget_ | ( |  | ) |

inline protected

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_, MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_, MatchedIterator< CONT_T, TRAIT, CONST_T >::ref_end_, MatchedIterator< CONT_T, TRAIT, CONST_T >::setToEnd_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_end_, and MatchedIterator< CONT_T, TRAIT, CONST_T >::tol_.

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::operator++().

## ◆ end()

static MatchedIterator end | ( |  | ) |

inline static

the end iterator

References MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator().

Referenced by SpectrumAlignment::getSpectrumAlignment().

## ◆ isEnd_()

bool isEnd_ | ( |  | ) | const

inline protected

References MatchedIterator< CONT_T, TRAIT, CONST_T >::is_end_.

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::operator++(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==().

## ◆ operator!=()

bool operator!= | ( | const MatchedIterator< CONT_T, TRAIT, CONST_T > & | rhs | ) | const

inline

## ◆ operator*() [1/2]

std::enable_if< _CONST, reference >::type operator* | ( |  | ) | const

inline

dereference current target element

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_.

## ◆ operator*() [2/2]

std::enable_if< !_CONST, reference >::type operator* | ( |  | ) |

inline

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_.

## ◆ operator++() [1/2]

MatchedIterator& operator++ | ( |  | ) |

inline

Advances to the next valid pair.

Exceptions

  Exception::InvalidIterator | If iterator is already at end

References MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::isEnd_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_, and OPENMS_PRECONDITION.

## ◆ operator++() [2/2]

MatchedIterator operator++ | ( | int |  | ) |

inline

post-increment

## ◆ operator->() [1/2]

std::enable_if< _CONST, pointer >::type operator-> | ( |  | ) | const

inline

pointer to current target element

## ◆ operator->() [2/2]

std::enable_if< !_CONST, pointer >::type operator-> | ( |  | ) |

inline

## ◆ operator=()

MatchedIterator& operator= | ( | const MatchedIterator< CONT_T, TRAIT, CONST_T > & | rhs | ) |

default

Assignment operator (default)

## ◆ operator==()

bool operator== | ( | const MatchedIterator< CONT_T, TRAIT, CONST_T > & | rhs | ) | const

inline

References MatchedIterator< CONT_T, TRAIT, CONST_T >::isEnd_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_, MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_, MatchedIterator< CONT_T, TRAIT, CONST_T >::ref_begin_, MatchedIterator< CONT_T, TRAIT, CONST_T >::ref_end_, MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_begin_, and MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_end_.

## ◆ ref()

const value_type& ref | ( |  | ) | const

inline

current element in reference container

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_.

## ◆ refIdx()

size_t refIdx | ( |  | ) | const

inline

index into reference container

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_, and MatchedIterator< CONT_T, TRAIT, CONST_T >::ref_begin_.

Referenced by SpectrumAlignment::getSpectrumAlignment().

## ◆ setToEnd_()

void setToEnd_ | ( |  | ) |

inline protected

References MatchedIterator< CONT_T, TRAIT, CONST_T >::is_end_.

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator().

## ◆ tgtIdx()

size_t tgtIdx | ( |  | ) | const

inline

index into target container

References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_, and MatchedIterator< CONT_T, TRAIT, CONST_T >::tgt_begin_.

Referenced by SpectrumAlignment::getSpectrumAlignment().

## Member Data Documentation

## ◆ is_end_

bool is_end_ = false

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::isEnd_(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::setToEnd_().

## ◆ it_ref_

CONT_IT it_ref_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::operator++(), MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==(), MatchedIterator< CONT_T, TRAIT, CONST_T >::ref(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::refIdx().

## ◆ it_tgt_

CONT_IT it_tgt_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::operator*(), MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::tgtIdx().

## ◆ ref_begin_

CONST_CONT_IT ref_begin_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::refIdx().

## ◆ ref_end_

CONST_CONT_IT ref_end_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==().

## ◆ tgt_begin_

CONST_CONT_IT tgt_begin_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator(), MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::tgtIdx().

## ◆ tgt_end_

CONST_CONT_IT tgt_end_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_(), MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator(), and MatchedIterator< CONT_T, TRAIT, CONST_T >::operator==().

## ◆ tol_

float tol_

protected

Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_().