A library for working with phylogenetic and population genetic data.
v0.32.0
Kmer< Tag > Class Template Reference

#include <genesis/sequence/kmer/kmer.hpp>

Detailed Description

template<typename Tag = KmerTagDefault>
class genesis::sequence::Kmer< Tag >

Kmer class template for representing k-mers of various sizes, currently up to k-32.

The class is templated with a Tag parameter, which allows distinguishing instances of different k-mer sizes to avoid accidentally mixing them. This also serves as a mechanism to maintain the value of k for each Tag that is being used, so that it does not have to be handed over to each function using the Kmer. The downside of this is that for a given Tag, only one value of k can be used at a time. For normal use cases, this should be fine, as k usually is a fixed value for the duration of a program. Should multiple values be needed, each needs to use their own Tag.

Definition at line 69 of file kmer.hpp.

Public Member Functions

 Kmer (WordType data)
 
uint8_t operator[] (size_t position) const
 
WordTypevalue ()
 
WordType const & value () const
 

Static Public Member Functions

static uint8_t k ()
 
static void reset_k (uint8_t k)
 Re-set the value of k for all Kmers of the given Tag. More...
 
static void set_k (uint8_t k)
 Set the value of k for all Kmers of the given Tag. More...
 

Public Types

using WordType = uint64_t
 Underlying integer type used to store the k-mer. More...
 

Static Public Attributes

static const size_t BIT_SIZE = sizeof(WordType) * CHAR_BIT
 Number of bits in the underlying integer type used to store the k-mer. More...
 
static const uint8_t BITS_PER_CHAR = 2
 Number of bits needed to store a character of input data. More...
 
static const uint8_t MAX_CHARS_PER_KMER = BIT_SIZE / BITS_PER_CHAR
 

Constructor & Destructor Documentation

◆ Kmer()

Kmer ( WordType  data)
inline

Definition at line 107 of file kmer.hpp.

Member Function Documentation

◆ k()

static uint8_t k ( )
inlinestatic

Definition at line 117 of file kmer.hpp.

◆ operator[]()

uint8_t operator[] ( size_t  position) const
inline

Definition at line 157 of file kmer.hpp.

◆ reset_k()

static void reset_k ( uint8_t  k)
inlinestatic

Re-set the value of k for all Kmers of the given Tag.

Conceptually, this is the same as set_k(), but without checking that the value has not been set already. This invalidates all Kmers of the same Tag, and hence shall only be done if no instances of a Kmer with the Tag are being in use any more. Otherwise, any computations using those will produce errors or meaningless results.

Definition at line 145 of file kmer.hpp.

◆ set_k()

static void set_k ( uint8_t  k)
inlinestatic

Set the value of k for all Kmers of the given Tag.

This needs to be called once for a given Tag in order to initialize the value of k for the Tag. It can also only be done once, and will throw if used again with a different k. When needing to change k for a given Tag later on, use reset_k() instead.

Definition at line 129 of file kmer.hpp.

◆ value() [1/2]

WordType& value ( )
inline

Definition at line 174 of file kmer.hpp.

◆ value() [2/2]

WordType const& value ( ) const
inline

Definition at line 169 of file kmer.hpp.

Member Typedef Documentation

◆ WordType

using WordType = uint64_t

Underlying integer type used to store the k-mer.

Definition at line 80 of file kmer.hpp.

Member Data Documentation

◆ BIT_SIZE

const size_t BIT_SIZE = sizeof(WordType) * CHAR_BIT
static

Number of bits in the underlying integer type used to store the k-mer.

Definition at line 85 of file kmer.hpp.

◆ BITS_PER_CHAR

const uint8_t BITS_PER_CHAR = 2
static

Number of bits needed to store a character of input data.

We currently only offer k-mers for DNA, where we use two bits per nucleotide, using A == 0b00, C == 0b01, G == 0b10, T == 0b11

Definition at line 94 of file kmer.hpp.

◆ MAX_CHARS_PER_KMER

const uint8_t MAX_CHARS_PER_KMER = BIT_SIZE / BITS_PER_CHAR
static

Definition at line 99 of file kmer.hpp.


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