OpenMS
2.7.0
|
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 |
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 chooses 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.
using CONST_CONT_IT = typename CONT_T::const_iterator |
using CONT_IT = typename std::conditional<CONST_T, typename CONT_T::const_iterator, typename CONT_T::iterator>::type |
using difference_type = std::ptrdiff_t |
using iterator_category = std::forward_iterator_tag |
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 value_type = typename CONT_T::value_type |
|
inlineexplicit |
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.
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, ...) |
|
inlineexplicit |
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.
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_.
|
inlineexplicit |
Default CTor; do not use this for anything other than assigning to it;.
Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::end().
|
default |
Copy CTor (default)
|
inlineprotected |
protected Ctor which creates and end() iterator the bool argument is only used to call the correct target (its value is ignored)
|
inlineprotected |
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++().
|
inlinestatic |
the end iterator
References MatchedIterator< CONT_T, TRAIT, CONST_T >::MatchedIterator().
Referenced by SpectrumAlignment::getSpectrumAlignment().
|
inlineprotected |
|
inline |
|
inline |
|
inline |
dereference current target element
References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_tgt_.
|
inline |
Advances to the next valid pair.
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.
|
inline |
post-increment
|
inline |
|
inline |
pointer to current target element
|
default |
Assignment operator (default)
|
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_.
|
inline |
current element in reference container
References MatchedIterator< CONT_T, TRAIT, CONST_T >::it_ref_.
|
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().
|
inlineprotected |
|
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().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by MatchedIterator< CONT_T, TRAIT, CONST_T >::advanceTarget_().