Go to the documentation of this file. 1 #ifndef BIFROST_KMER_HPP
2 #define BIFROST_KMER_HPP
5 #define MAX_KMER_SIZE 32
9 #define MAX_GMER_SIZE MAX_KMER_SIZE
32 class CompressedSequence;
44 friend class CompressedSequence;
62 explicit Kmer(
const char* s);
74 for (
size_t i = 0; i < MAX_K/32; ++i) longs[i] = 0xffffffffffffffffULL;
81 for (
size_t i = 0; i < MAX_K/32; ++i) longs[i] = 0xfffffffffffffffeULL;
89 return (longs[(MAX_K/32)-1] == 0xffffffffffffffffULL);
97 return (longs[(MAX_K/32)-1] == 0xfffffffffffffffeULL);
100 bool operator<(
const Kmer& o)
const;
120 BFG_INLINE uint64_t
hash(
const uint64_t seed = 0)
const {
122 return wyhash(bytes, MAX_K/4, seed, _wyp);
169 bool setChar(
const size_t offset,
const char b);
187 bool write(std::ostream& stream_out)
const;
195 bool read(std::istream& stream_in);
201 static void set_k(
const unsigned int _k);
203 static unsigned int k;
207 static const unsigned int MAX_K = MAX_KMER_SIZE;
211 uint8_t bytes[MAX_K/4];
212 uint64_t longs[MAX_K/32];
215 void set_kmer(
const char *s);
217 Kmer getLink(
const size_t index)
const;
219 std::string getBinary()
const;
225 inline size_t operator()(
const Kmer& km)
const {
234 friend class CompressedSequence;
239 Minimizer(
const Minimizer& o);
240 explicit Minimizer(
const char *s);
242 Minimizer& operator=(
const Minimizer& o);
244 bool operator<(
const Minimizer& o)
const;
245 bool operator==(
const Minimizer& o)
const;
246 bool operator!=(
const Minimizer& o)
const;
248 void set_minimizer(
const char *s);
250 BFG_INLINE uint64_t hash(
const uint64_t seed = 0)
const {
252 return wyhash(bytes, MAX_G/4, seed, _wyp);
255 BFG_INLINE
void set_deleted() {
257 for (
size_t i = 0; i < MAX_G/32; ++i) longs[i] = 0xffffffffffffffffULL;
260 BFG_INLINE
void set_empty() {
262 for (
size_t i = 0; i < MAX_G/32; ++i) longs[i] = 0xfffffffffffffffeULL;
265 BFG_INLINE
bool isDeleted()
const {
267 return (longs[(MAX_G/32)-1] == 0xffffffffffffffffULL);
270 BFG_INLINE
bool isEmpty()
const {
272 return (longs[(MAX_G/32)-1] == 0xfffffffffffffffeULL);
275 Minimizer twin()
const;
276 Minimizer rep()
const;
278 Minimizer getLink(
const size_t index)
const;
280 Minimizer forwardBase(
const char b)
const;
281 Minimizer backwardBase(
const char b)
const;
283 std::string getBinary()
const;
285 void toString(
char *s)
const;
286 std::string toString()
const;
288 bool write(std::ostream& stream_out)
const;
289 bool read(std::istream& stream_in);
292 static void set_g(
unsigned int _g);
294 static unsigned int g;
298 static const unsigned int MAX_G = MAX_GMER_SIZE;
303 uint8_t bytes[MAX_G/4];
304 uint64_t longs[MAX_G/32];
313 struct MinimizerHash {
315 inline size_t operator()(
const Minimizer& minz)
const {
322 #endif // BFG_KMER_HPP
std::string toString() const
Get the string of a k-mer.
bool setChar(const size_t offset, const char b)
Set a character at a given position in a k-mer.
uint64_t hash(const uint64_t seed=0) const
Get the hash of a k-mer.
Definition: Kmer.hpp:120
Kmer & operator=(const Kmer &o)
Copy assignment operator (copy a k-mer).
Interface to store and manipulate k-mers.
Definition: Kmer.hpp:42
static void set_k(const unsigned int _k)
Set the length of k-mers.
bool isEmpty() const
Check whether a k-mer is "empty".
Definition: Kmer.hpp:95
bool isDeleted() const
Check whether a k-mer is "deleted".
Definition: Kmer.hpp:87
void selfForwardBase(const char b)
Shift the current k-mer of one base on the left with one new character on the right.
void toString(char *s) const
Get the string of a k-mer.
bool operator==(const Kmer &o) const
Equality comparison operator.
void set_empty()
Set a k-mer as "empty".
Definition: Kmer.hpp:79
bool read(std::istream &stream_in)
Read a k-mer (binary) from a stream.
bool write(std::ostream &stream_out) const
Write a k-mer (binary) to a stream.
Kmer rep() const
Get the canonical k-mer (lexicographically smallest between a k-mer and its reverse-complement).
void set_deleted()
Set a k-mer as "deleted".
Definition: Kmer.hpp:72
Kmer(const Kmer &o)
Copy constructor (copy a k-mer).
bool operator!=(const Kmer &o) const
Inequality comparison operator.
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 charact...
char getChar(const size_t offset) const
Get the character at a given position in a k-mer.
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 characte...
Kmer()
Constructor (initialize a k-mer with 'A' k times).
Kmer(const char *s)
Constructor.
Kmer twin() const
Get the reverse-complement of a k-mer.