Bifrost
|
Interface to store and manipulate k-mers. More...
Public Member Functions | |
Kmer () | |
Constructor (initialize a k-mer with 'A' k times). | |
Kmer (const Kmer &o) | |
Copy constructor (copy a k-mer). More... | |
Kmer (const char *s) | |
Constructor. More... | |
Kmer & | operator= (const Kmer &o) |
Copy assignment operator (copy a k-mer). More... | |
void | set_deleted () |
Set a k-mer as "deleted". | |
void | set_empty () |
Set a k-mer as "empty". | |
bool | isDeleted () const |
Check whether a k-mer is "deleted". More... | |
bool | isEmpty () const |
Check whether a k-mer is "empty". More... | |
bool | operator== (const Kmer &o) const |
Equality comparison operator. More... | |
bool | operator!= (const Kmer &o) const |
Inequality comparison operator. More... | |
uint64_t | hash (const uint64_t seed=0) const |
Get the hash of a k-mer. More... | |
Kmer | twin () const |
Get the reverse-complement of a k-mer. More... | |
Kmer | rep () const |
Get the canonical k-mer (lexicographically smallest between a k-mer and its reverse-complement). More... | |
Kmer | forwardBase (const char b) const |
Get a new k-mer which is the shift of the current k-mer of one base on the left with one new character on the right. More... | |
Kmer | backwardBase (const char b) const |
Get a new k-mer which is the shift of the current k-mer of one base on the right with one new character on the left. More... | |
void | selfForwardBase (const char b) |
Shift the current k-mer of one base on the left with one new character on the right. More... | |
char | getChar (const size_t offset) const |
Get the character at a given position in a k-mer. More... | |
bool | setChar (const size_t offset, const char b) |
Set a character at a given position in a k-mer. More... | |
void | toString (char *s) const |
Get the string of a k-mer. More... | |
std::string | toString () const |
Get the string of a k-mer. More... | |
bool | write (std::ostream &stream_out) const |
Write a k-mer (binary) to a stream. More... | |
bool | read (std::istream &stream_in) |
Read a k-mer (binary) from a stream. More... | |
Static Public Member Functions | |
static void | set_k (const unsigned int _k) |
Set the length of k-mers. More... | |
Interface to store and manipulate k-mers.
The default maximum supported k-mer size is 31. To work with larger k, you must replace the macro defined MAX_KMER_SIZE with a larger number which is a multiple of 32. For such a number K, the available maximum supported k-mer size will be K-1. For example, if MAX_KMER_SIZE is defined as 64, the maximum k allowed is 63. Keep in mind that increasing MAX_KMER_SIZE increases memory usage (k=31 uses 8 bytes of memory per k-mer while k=63 uses 16 bytes of memory per k-mer).
Kmer::Kmer | ( | const Kmer & | o | ) |
Copy constructor (copy a k-mer).
After the call to this function, the same k-mer exists twice in memory.
o | is a constant reference to the k-mer to copy |
|
explicit |
Constructor.
Initialize a k-mer from a string of characters.
s | is a constant pointer to an array of characters. The array of characters must contain valid DNA characters ('A', 'C', 'G', 'T') and be of length at least k. |
Kmer Kmer::backwardBase | ( | const char | b | ) | const |
Get a new k-mer which is the shift of the current k-mer of one base on the right with one new character on the left.
For a k-mer km of length k, km.backwardBase(b) = b + km[0..k-2].
b | is a new character to add on the left of the shifted k-mer (as a first character). It must be either 'A', 'C', 'G' or 'T'. |
Kmer Kmer::forwardBase | ( | const char | b | ) | const |
Get a new k-mer which is the shift of the current k-mer of one base on the left with one new character on the right.
For a k-mer km of length k, km.forwardBase(b) = km[1..k-1] + b.
b | is a new character to add on the right of the shifted k-mer (as a last character). It must be either 'A', 'C', 'G' or 'T'. |
char Kmer::getChar | ( | const size_t | offset | ) | const |
Get the character at a given position in a k-mer.
offset | is the position of the character to get in the k-mer. |
|
inline |
Get the hash of a k-mer.
seed | is a seed number for the hash function (0 by default). |
|
inline |
Check whether a k-mer is "deleted".
|
inline |
Check whether a k-mer is "empty".
bool Kmer::operator!= | ( | const Kmer & | o | ) | const |
Inequality comparison operator.
o | is a constant reference to the k-mer to compare to. |
Copy assignment operator (copy a k-mer).
After the call to this function, the same k-mer exists twice in memory.
o | is a constant reference to the k-mer to copy |
bool Kmer::operator== | ( | const Kmer & | o | ) | const |
Equality comparison operator.
o | is a constant reference to the k-mer to compare to. |
bool Kmer::read | ( | std::istream & | stream_in | ) |
Read a k-mer (binary) from a stream.
The stream must be opened prior to this function call and it won't be closed by this function.
stream_in | is an in stream from which the k-mer must be read. The stream must be opened prior to this function call and it won't be closed by this function. |
Kmer Kmer::rep | ( | ) | const |
Get the canonical k-mer (lexicographically smallest between a k-mer and its reverse-complement).
void Kmer::selfForwardBase | ( | const char | b | ) |
Shift the current k-mer of one base on the left with one new character on the right.
b | is a new character to add on the right (as a last character) after shifting the current k-mer. It must be either 'A', 'C', 'G' or 'T'. |
|
static |
Set the length of k-mers.
After this function call, all Kmer functions considers _k to be the k-mer length.
_k | is the k-mer length to set. |
bool Kmer::setChar | ( | const size_t | offset, |
const char | b | ||
) |
Set a character at a given position in a k-mer.
offset | is the position of the character to set in the k-mer. |
b | is the character to set. It must be either 'A', 'C', 'G' or 'T'. |
std::string Kmer::toString | ( | ) | const |
Get the string of a k-mer.
void Kmer::toString | ( | char * | s | ) | const |
Get the string of a k-mer.
s | is a pointer to an array of characters that will be set with the string of a k-mer. |
Kmer Kmer::twin | ( | ) | const |
Get the reverse-complement of a k-mer.
bool Kmer::write | ( | std::ostream & | stream_out | ) | const |
Write a k-mer (binary) to a stream.
The stream must be opened prior to this function call and it won't be closed by this function.
stream_out | is an out stream to which the k-mer must be written to. The stream must be opened prior to this function call and it won't be closed by this function. |