Musaline
 All Classes Namespaces Functions Variables Pages
Public Types | Public Member Functions | List of all members
musaline::ConsolidatingAligner< CostCalc > Class Template Reference

#include <musaline.hpp>

Public Types

typedef CostCalc CostCalculator
 

Public Member Functions

 ConsolidatingAligner (CostCalculator ccal=CostCalculator())
 Constructor. Takes a CostaCalculator object as parameter.
 
void set_cost_calculator (CostCalculator ccal)
 Set a different CostCalculator object.
 
CostCalculator const & get_cost_calculator () const
 Get a const reference to the current CostCalculator object.
 
template<class Sequence0 , class Sequence1 >
Alignment global_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment cut_one_end_off_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment cut_one_begin_off_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment initial_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment end_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment inside_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment semi_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 
template<class Sequence0 , class Sequence1 >
Alignment partial_align (Sequence0 const &seq0, Sequence1 const &seq1) const
 No requirement for start and end.
 

Detailed Description

template<class CostCalc>
class musaline::ConsolidatingAligner< CostCalc >

An element of a sequence can be aligned with an element of the other sequence or with a gap. The cost of aligning two elements or an element with a gap, does not depend on the context.

The class has several align functions which differ in what part of the sequences should be aligned. Details are provided with the individual align functions.

This class takes a CostCalculator class as a template parameter. The requirements are much like those for LinearAligner, except that gap_bft is replaced by match_gap_with1 and match_gap_with2, which take an element as parameter. Furthermore, there should be a member function1 match_range_with1 and match_range_with2.

If you can call the following function template with your cost calculator and sequences without compilation errors, you should be OK. More detailed requirements are listed after the function.

#include "boost/range.hpp"
template <class CostCalculator, class Sequence0, class Sequence1>
void consolidating_usage(CostCalculator const &ccal,
Sequence0 const &seq0, Sequence1 const &seq1)
{
// Copy constructor
CostCalculator ccal_copy(ccal);
// assignment operator
ccal_copy = ccal;
ccal.preprocess(seq0, seq1);
size_t sz0 = boost::distance(seq0);
size_t sz1 = boost::distance(seq1);
auto s0begin = boost::const_begin(seq0);
auto s0cur(s0begin)
for (size_t i=0; i!=sz0; ++i) {
auto s1begin = boost::const_begin(seq1));
auto s1cur = s1begin;
double d = ccal.match_gap_with1(*s0cur);
for (size_t j=0; j!=sz1; ++j) {
double benefit = ccal.match(*s0cur, *s1cur);
d = ccal.match_gap_with2(*s1cur);
vector<double> benefits = ccal.match_range_with1(*s0cur,
s1begin, s1cur);
benefits = ccal.match_range_with2(s0begin, s0cur, *s1cur);
++s1cur;
}
++s0cur;
}
}
The classes Sequence0 and Sequence1 should fulfill the requirements for
a boost Bidirectional Range. See the documentation of the range library on
http://www.boost.org for full details. A range can be thought of as a
'container light'. It should give access to a begin and end iterator, which
should be bidirectional iterators.

The CostCalculator class should have the following member functions:
\li a copy constructor and an assignment operator.
\li \c match which
takes an element of seq0 and an element of seq1 and returns a
double. This value is a measure for how well the two elements match. A
good match should yield a (big) positive value. A bad match should yield
a negative value.
\li \c match_gap_with1. Takes an element of the first sequence as parameter.
Returns the benefit for matching that element with a gap (nothing).
The returned value should be negative, otherwise, the results
are not guaranteed to be the optimal solution.
\li \c match_gap_with2. Takes an element of the second sequence as parameter.
Returns the benefit for matching that element with a gap (nothing).
\li \c match_range_with1.
Takes three parameters. The first is an element of the first sequence. The
second and third are the begin and end iterator of a range of the
second sequences. The result should be a vector of doubles.
The resulting vector may have any length less than the size of the
supplied range. The first element (if existant) contains the benefit of
matching the last two elements of the range with the first parameter
element. The second element of the result contains the benefit of
matching the last three elements of the range with the first parameter
element, etcetera.
\li \c match_range_with2. Matches an element of the second sequence with a
 number of elements of the first sequence.
\li \c preprocess which takes two sequences as argument. This member
function is guaranteed to be called before any call to \c match for those
sequences.
This may be used to do some preprocessing of the sequences. For
instance, say we want to compare two melodies, where a melody is a
sequences of notes and a key. If one of the melodies is in C and the
other one is in G, we might want to transpose the latter melody. This
can be done in the preprocess step.

In \ref sec_consol_require "introductory page" you can find a more gentle
(and less precise) description of the requirements.

Member Function Documentation

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::cut_one_begin_off_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align one complete sequence with the end of the other sequence. end[0]==size of seq0, end[1]==size of seq1 and either start[0]==0 or start[1]==0.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::cut_one_end_off_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align one complete sequence with the start of the other sequence. start[0]==0, start[1]==0 and either end[0]==size of seq0 or end[1]==size of seq1.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::end_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align the end of the sequences. end[0]==size of seq0 and end[1]==size of seq1.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::global_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align both complete sequences. The resulting Alignment will have start[i]==0 and end[i]==size of seq i, for i==1 and 2.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::initial_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align the start of the sequences. start[0]==0 and start[1]==0.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::inside_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

align seq0 inside seq1. start[0]==0 and end[0]==size of sequence 0.

template<class CostCalc >
template<class Sequence0 , class Sequence1 >
Alignment musaline::ConsolidatingAligner< CostCalc >::semi_align ( Sequence0 const &  seq0,
Sequence1 const &  seq1 
) const

start[0]==0 or start[1]==0 end[0]==size of seq0 or end[1]==size of seq1.


The documentation for this class was generated from the following file: