gatb.core-API-0.0.0
Kmer< span >::ModelAbstract< ModelImpl, T > Class Template Reference

#include <Model.hpp>

Inheritance diagram for Kmer< span >::ModelAbstract< ModelImpl, T >:
Inheritance graph

Public Types

typedef T Kmer
 

Public Member Functions

 ModelAbstract (size_t sizeKmer=span-1)
 
size_t getSpan () const
 
size_t getMemorySize () const
 
size_t getKmerSize () const
 
const TypegetKmerMax () const
 
std::string toString (const Type &kmer) const
 
Type reverse (const Type &kmer) const
 
Kmer getKmer (const tools::misc::Data &data, size_t startIndex=0) const
 
template<typename Callback >
bool iterate (tools::misc::Data &data, Callback callback) const
 
Kmer codeSeed (const char *seq, tools::misc::Data::Encoding_e encoding, size_t startIndex=0) const
 
Kmer codeSeedRight (const Kmer &kmer, char nucl, tools::misc::Data::Encoding_e encoding) const
 
bool build (tools::misc::Data &data, std::vector< Kmer > &kmersBuffer) const
 
template<typename Functor >
void iterateNeighbors (const Type &source, const Functor &fct, const std::bitset< 8 > &mask=0xFF) const
 
template<typename Functor >
void iterateOutgoingNeighbors (const Type &source, Functor &fct, const std::bitset< 4 > &mask=0x0F) const
 
template<typename Functor >
void iterateIncomingNeighbors (const Type &source, Functor &fct, const std::bitset< 4 > &mask=0x0F) const
 
- Public Member Functions inherited from SmartPointer
void use ()
 
void forget ()
 
- Public Member Functions inherited from ISmartPointer
virtual ~ISmartPointer ()
 

Protected Member Functions

template<typename Callback , typename Convert >
bool iterate (const char *seq, size_t length, Callback callback) const
 
- Protected Member Functions inherited from SmartPointer
 SmartPointer ()
 
virtual ~SmartPointer ()
 

Detailed Description

template<size_t span = KMER_DEFAULT_SPAN>
template<class ModelImpl, typename T>
class gatb::core::kmer::impl::Kmer< span >::ModelAbstract< ModelImpl, T >

Abstract class that provides kmer management.

This class is the base class for kmer management. It provides several services on this purpose like getting kmer information from some nucleotides sequence, or iterate kmers through such a sequence.

This class has two templates types :

 1) ModelImpl : ModelAbstract is design for static polymorphism and ModelImpl is the implementation
                that must be provided to it

 2) T : type of kmers handled by the class (ie KmerDirect, KmerCanonical...); I was not successful
        in trying to hide KmerXXX classes in the dedicated ModelXXX classes because of mutual
        dependencies while template specializations (maybe a solution one day)

End user will be given instances of Kmer class, delivering more or less information according to the specific type of ModelImpl

Member Typedef Documentation

typedef T Kmer

Type of kmers provided by the class. It can be KmerDirect, KmerCanonical or KmerMinimizer.

The simple way to get the value of the kmer is done with the 'value' method.

Note that, according to the true type of T, this Kmer typedef may have more or less methods.

Constructor & Destructor Documentation

ModelAbstract ( size_t  sizeKmer = span-1)
inline

(default) Constructor. The provided (runtime) kmer size must be coherent with the span (static) value.

Parameters
[in]sizeKmer: size of kmers handled by the instance.

Member Function Documentation

bool build ( tools::misc::Data data,
std::vector< Kmer > &  kmersBuffer 
) const
inline

Build a vector of successive kmers from a given sequence of nucleotides provided as a Data object.

Parameters
[in]data: the sequence of nucleotides.
[out]kmersBuffer: the successive kmers built from the data object.
Returns
true if kmers have been extracted, false otherwise.
Kmer codeSeed ( const char *  seq,
tools::misc::Data::Encoding_e  encoding,
size_t  startIndex = 0 
) const
inline

Compute the kmer given some nucleotide data. Note that we don't check if we have enough nucleotides in the provided data.

Parameters
[in]seq: the sequence
[in]encoding: encoding mode of the sequence
[in]startIndex: index of the first nucleotide in the seq buffer
Returns
the kmer for the given nucleotides.
Kmer codeSeedRight ( const Kmer kmer,
char  nucl,
tools::misc::Data::Encoding_e  encoding 
) const
inline

Compute the next right kmer given a current kmer and a nucleotide.

Parameters
[in]kmer: the current kmer as a starting point
[in]nucl: the next nucleotide
[in]encoding: encoding mode of the sequence
Returns
the kmer on the right of the given kmer.
Kmer getKmer ( const tools::misc::Data data,
size_t  startIndex = 0 
) const
inline

Build a kmer from a Data object (ie a sequence of nucleotides), starting at an index in the nucleotides sequence. The result is a pair holding the built kmer and a boolean set to yes if the built kmer has to be understood in the forward sense, false otherwise.

Parameters
[in]data: the data from which we extract a kmer
[in]startIndex: start index in the data object (default to 0)
Returns
a pair with the built kmer and a boolean set to yes if the kmer is understood in the forward strand
const Type& getKmerMax ( ) const
inline

Gives the maximum value of a kmer for the instance.

Returns
the maximum kmer value.
size_t getKmerSize ( ) const
inline

Gives the kmer size for this model.

Returns
the kmer size.
size_t getMemorySize ( ) const
inline

Get the memory size (in bytes) of a Kmer<span>::Type object.

Returns
the memory size of a kmer.
size_t getSpan ( ) const
inline

Returns the span of the model

Returns
the model span.
bool iterate ( tools::misc::Data data,
Callback  callback 
) const
inline

Iteration of the kmers from a data object through a functor (so lambda expressions can be used). Note that the functor takes the currently iterated Kmer object and its index during the iteration.

Example of use:

// We iterate the kmers (and minimizers) of the current sequence.
model.iterate (seq.getData(), [&] (const Model::Kmer& kmer, size_t idx)
{
nbKmers ++;
if (kmer.hasChanged() == true) { nbChanged++; }
if (kmer.isValid() == false) { nbInvalid++; }
checksum += kmer.minimizer().value();
});
Parameters
[in]data: the sequence of nucleotides as a Data object.
[in]callback: functor that handles one kmer
bool iterate ( const char *  seq,
size_t  length,
Callback  callback 
) const
inlineprotected

Template method that iterates the kmer of a given sequence (provided as a buffer and its length). Note : we use static polymorphism here (http://en.wikipedia.org/wiki/Template_metaprogramming)

Parameters
[in]seq: the sequence to be iterated
[in]length: length of the sequence
[in]callback: functor called on each found kmer in the sequence
Returns
true if kmers have been found, false otherwise.
void iterateIncomingNeighbors ( const Type source,
Functor &  fct,
const std::bitset< 4 > &  mask = 0x0F 
) const
inline

Iterate the neighbors of a given kmer; these neighbors are:

  • 4 incoming neighbors This method uses a functor that will be called for each possible neighbor of the source kmer.
    Parameters
    [in]source: the kmer from which we want neighbors.
    [in]fct: a functor called for each neighbor.
    [in]mask: mask of the neighbors to be used
void iterateNeighbors ( const Type source,
const Functor &  fct,
const std::bitset< 8 > &  mask = 0xFF 
) const
inline

Iterate the neighbors of a given kmer; these neighbors are:

  • 4 outgoing neighbors (with nt A,C,T,G)
  • 4 incoming neighbors (with nt A,C,T,G) This method uses a functor that will be called for each possible neighbor of the source kmer.
    Parameters
    [in]source: the kmer from which we want neighbors.
    [in]fct: a functor called for each neighbor.
    [in]mask: holds 8 bits for each possible neighbor (1 means that the neighbor is computed)
void iterateOutgoingNeighbors ( const Type source,
Functor &  fct,
const std::bitset< 4 > &  mask = 0x0F 
) const
inline

Iterate the neighbors of a given kmer; these neighbors are:

  • 4 outcoming neighbors This method uses a functor that will be called for each possible neighbor of the source kmer.
    Parameters
    [in]source: the kmer from which we want neighbors.
    [in]fct: a functor called for each neighbor.
    [in]mask: mask of the neighbors to be used
Type reverse ( const Type kmer) const
inline

Compute the reverse complement of a kmer.

Parameters
[in]kmer: the kmer to be reverse-completed.
Returns
the reverse complement.
std::string toString ( const Type kmer) const
inline

Returns an ascii representation of the kmer value.

Parameters
[in]kmer: the kmer we want an ascii representation for
Returns
a string instance holding the ascii representation.

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