btllib

Public Member Functions | Static Public Member Functions | List of all members
btllib::KmerCountingBloomFilter< T > Class Template Reference

`#include <counting_bloom_filter.hpp>`

## Public Member Functions
| KmerCountingBloomFilter ()
| KmerCountingBloomFilter (size_t bytes, unsigned hash_num, unsigned k)
| KmerCountingBloomFilter (const std::string &path)
| KmerCountingBloomFilter (const KmerCountingBloomFilter &)=delete
| KmerCountingBloomFilter (KmerCountingBloomFilter &&)=delete
KmerCountingBloomFilter & | operator= (const KmerCountingBloomFilter &)=delete
KmerCountingBloomFilter & | operator= (KmerCountingBloomFilter &&)=delete
void | insert (const char *seq, size_t seq_len)
void | insert (const std::string &seq)
void | insert (const uint64_t *hashes)
void | insert (const std::vector< uint64_t > &hashes)
uint64_t | contains (const char *seq, size_t seq_len) const
uint64_t | contains (const std::string &seq) const
T | contains (const uint64_t *hashes) const
T | contains (const std::vector< uint64_t > &hashes) const
T | contains_insert (const char *seq, size_t seq_len)
T | contains_insert (const std::string &seq)
T | contains_insert (const uint64_t *hashes)
T | contains_insert (const std::vector< uint64_t > &hashes)
T | insert_contains (const char *seq, size_t seq_len)
T | insert_contains (const std::string &seq)
T | insert_contains (const uint64_t *hashes)
T | insert_contains (const std::vector< uint64_t > &hashes)
T | insert_thresh_contains (const char *seq, size_t seq_len, T threshold)
T | insert_thresh_contains (const std::string &seq, const T threshold)
T | insert_thresh_contains (const uint64_t *hashes, const T threshold)
T | insert_thresh_contains (const std::vector< uint64_t > &hashes, const T threshold)
T | contains_insert_thresh (const char *seq, size_t seq_len, T threshold)
T | contains_insert_thresh (const std::string &seq, const T threshold)
T | contains_insert_thresh (const uint64_t *hashes, const T threshold)
T | contains_insert_thresh (const std::vector< uint64_t > &hashes, const T threshold)
size_t | get_bytes () const
uint64_t | get_pop_cnt (T threshold=1) const
double | get_occupancy (T threshold=1) const
unsigned | get_hash_num () const
double | get_fpr (T threshold=1) const
unsigned | get_k () const
const std::string & | get_hash_fn () const
CountingBloomFilter< T > & | get_counting_bloom_filter ()
void | save (const std::string &path)

## Static Public Member Functions
static bool | is_bloom_file (const std::string &path)

## Detailed Description

template<typename T>
class btllib::KmerCountingBloomFilter< T >

Counting Bloom filter data structure that stores k-mers. Provides KmerCountingBloomFilter8, KmerCountingBloomFilter16, and KmerCountingBloomFilter32 classes with corresponding bit-size counters.

## Constructor & Destructor Documentation

## ◆ KmerCountingBloomFilter() [1/3]

template<typename T >

btllib::KmerCountingBloomFilter< T >::KmerCountingBloomFilter | ( |  | ) |
| inline

Construct a dummy k-mer Bloom filter (e.g. as a default argument).

## ◆ KmerCountingBloomFilter() [2/3]

template<typename T >

btllib::KmerCountingBloomFilter< T >::KmerCountingBloomFilter | ( | size_t | bytes,
|  | unsigned | hash_num,
|  | unsigned | k
| ) |  |
| inline

Construct an empty k-mer Counting Bloom filter of given size.

Parameters

  bytes | Filter size in bytes.
  hash_num | Number of hash values per element.
  k | K-mer size.

## ◆ KmerCountingBloomFilter() [3/3]

template<typename T >

btllib::KmerCountingBloomFilter< T >::KmerCountingBloomFilter | ( | const std::string & | path | ) |
| inline explicit

Load a k-mer Counting Bloom filter from a file.

Parameters

  path | Filepath to load from.

## Member Function Documentation

## ◆ contains() [1/4]

template<typename T >

uint64_t btllib::KmerCountingBloomFilter< T >::contains | ( | const char * | seq,
|  | size_t | seq_len
| ) |  | const
| inline

Query the counts of k-mers of a sequence.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.

Returns
  The sum of counts of seq's k-mers found in the filter.

## ◆ contains() [2/4]

template<typename T >

uint64_t btllib::KmerCountingBloomFilter< T >::contains | ( | const std::string & | seq | ) | const
| inline

Query the counts of k-mers of a sequence.

Parameters

  seq | Sequence to k-merize.

Returns
  The sum of counts of seq's k-mers found in the filter.

## ◆ contains() [3/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains | ( | const std::vector< uint64_t > & | hashes | ) | const
| inline

Get a k-mer's count.

Parameters

  hashes | Integer vector of k-mer's hash values.

Returns
  The count of the queried k-mer.

## ◆ contains() [4/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains | ( | const uint64_t * | hashes | ) | const
| inline

Get a k-mer's count.

Parameters

  hashes | Integer array of k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

Returns
  The count of the queried k-mer.

## ◆ contains_insert() [1/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert | ( | const char * | seq,
|  | size_t | seq_len
| ) |  |
| inline

Get the counts of a sequence's k-mers and then increment the counts.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.

Returns
  The sum of counts of the queried k-mers before insertion.

## ◆ contains_insert() [2/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert | ( | const std::string & | seq | ) |
| inline

Get the counts of a sequence's k-mers and then increment the counts.

Parameters

  seq | Sequence to k-merize.

Returns
  The sum of counts of the queried k-mers before insertion.

## ◆ contains_insert() [3/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert | ( | const std::vector< uint64_t > & | hashes | ) |
| inline

Get the count of a k-mer and then increment the count.

Parameters

  hashes | Integer vector of the k-mer's hash values.

Returns
  The count of the queried k-mer before insertion.

## ◆ contains_insert() [4/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert | ( | const uint64_t * | hashes | ) |
| inline

Get the count of a k-mer and then increment the count.

Parameters

  hashes | Integer array of the k-mers's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

Returns
  The count of the queried k-mer before insertion.

## ◆ contains_insert_thresh() [1/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert_thresh | ( | const char * | seq,
|  | size_t | seq_len,
|  | T | threshold
| ) |  |
| inline

Get the counts of a sequence's k-mer's and then increment the counts if they are not above the threshold.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.
  threshold | The threshold.

Returns
  The sum of counts of the queried k-mers before insertion.

## ◆ contains_insert_thresh() [2/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert_thresh | ( | const std::string & | seq,
|  | const T | threshold
| ) |  |
| inline

Get the counts of a sequence's k-mer's and then increment the counts if they are not above the threshold.

Parameters

  seq | Sequence to k-merize.
  threshold | The threshold.

Returns
  The sum of counts of the queried k-mers before insertion.

## ◆ contains_insert_thresh() [3/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert_thresh | ( | const std::vector< uint64_t > & | hashes,
|  | const T | threshold
| ) |  |
| inline

Get the count of a k-mer and then increment the count if it's not above the threshold.

Parameters

  hashes | Integer vector of the k-mer's hash values.
  threshold | The threshold.

Returns
  The count of the queried k-mer before insertion.

## ◆ contains_insert_thresh() [4/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::contains_insert_thresh | ( | const uint64_t * | hashes,
|  | const T | threshold
| ) |  |
| inline

Get the count of a k-mer and then increment the count if it's not above the threshold.

Parameters

  hashes | Integer array of the k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried k-mer before insertion.

## ◆ get_bytes()

template<typename T >

size_t btllib::KmerCountingBloomFilter< T >::get_bytes | ( |  | ) | const
| inline

Get filter size in bytes.

## ◆ get_counting_bloom_filter()

template<typename T >

CountingBloomFilter< T > & btllib::KmerCountingBloomFilter< T >::get_counting_bloom_filter | ( |  | ) |
| inline

Get a reference to the underlying vanilla Counting Bloom filter.

## ◆ get_fpr()

template<typename T >

double btllib::KmerCountingBloomFilter< T >::get_fpr | ( | T | threshold = `1` | ) | const
| inline

Get the query false positive rate for elements with count >= threshold.

Parameters

  threshold | The threshold.

Returns
  The false positive rate.

## ◆ get_hash_fn()

template<typename T >

const std::string & btllib::KmerCountingBloomFilter< T >::get_hash_fn | ( |  | ) | const
| inline

Get the name of the hash function used.

## ◆ get_hash_num()

template<typename T >

unsigned btllib::KmerCountingBloomFilter< T >::get_hash_num | ( |  | ) | const
| inline

Get the number of hash values per element.

## ◆ get_k()

template<typename T >

unsigned btllib::KmerCountingBloomFilter< T >::get_k | ( |  | ) | const
| inline

Get the k-mer size used.

## ◆ get_occupancy()

template<typename T >

double btllib::KmerCountingBloomFilter< T >::get_occupancy | ( | T | threshold = `1` | ) | const
| inline

Get the fraction of the filter occupied by >0 counters.

## ◆ get_pop_cnt()

template<typename T >

uint64_t btllib::KmerCountingBloomFilter< T >::get_pop_cnt | ( | T | threshold = `1` | ) | const
| inline

Get population count, i.e. the number of counters >0 in the filter.

## ◆ insert() [1/4]

template<typename T >

void btllib::KmerCountingBloomFilter< T >::insert | ( | const char * | seq,
|  | size_t | seq_len
| ) |  |
| inline

Insert a sequence's k-mers into the filter.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.

## ◆ insert() [2/4]

template<typename T >

void btllib::KmerCountingBloomFilter< T >::insert | ( | const std::string & | seq | ) |
| inline

Insert a sequence's k-mers into the filter.

Parameters

  seq | Sequence to k-merize.

## ◆ insert() [3/4]

template<typename T >

void btllib::KmerCountingBloomFilter< T >::insert | ( | const std::vector< uint64_t > & | hashes | ) |
| inline

Insert a k-mer into the filter.

Parameters

  hashes | Integer vector of the k-mer's hash values.

## ◆ insert() [4/4]

template<typename T >

void btllib::KmerCountingBloomFilter< T >::insert | ( | const uint64_t * | hashes | ) |
| inline

Insert a k-mer into the filter.

Parameters

  hashes | Integer array of the k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

## ◆ insert_contains() [1/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_contains | ( | const char * | seq,
|  | size_t | seq_len
| ) |  |
| inline

Increment the counts of a sequence's k-mers and then return the counts.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.

Returns
  The sum of counts of the queried k-mers after insertion.

## ◆ insert_contains() [2/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_contains | ( | const std::string & | seq | ) |
| inline

Increment the counts of a sequence's k-mers and then return the counts.

Parameters

  seq | Sequence to k-merize.

Returns
  The sum of counts of the queried k-mers after insertion.

## ◆ insert_contains() [3/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_contains | ( | const std::vector< uint64_t > & | hashes | ) |
| inline

Increment a k-mer's count and then return the count.

Parameters

  hashes | Integer vector of the k-mer's hash values.

Returns
  The count of the queried k-mer after insertion.

## ◆ insert_contains() [4/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_contains | ( | const uint64_t * | hashes | ) |
| inline

Increment a k-mer's count and then return the count.

Parameters

  hashes | Integer array of the k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.

Returns
  The count of the queried k-mer after insertion.

## ◆ insert_thresh_contains() [1/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_thresh_contains | ( | const char * | seq,
|  | size_t | seq_len,
|  | T | threshold
| ) |  |
| inline

Increment the counts of a sequence's k-mers if they are not above the threshold and then return the counts.

Parameters

  seq | Sequence to k-merize.
  seq_len | Length of seq.
  threshold | The threshold.

Returns
  The sum of counts of the queried k-mers after insertion.

## ◆ insert_thresh_contains() [2/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_thresh_contains | ( | const std::string & | seq,
|  | const T | threshold
| ) |  |
| inline

Increment the counts of a sequence's k-mers if they are not above the threshold and then return the counts.

Parameters

  seq | Sequence to k-merize.
  threshold | The threshold.

Returns
  The sum of counts of the queried k-mers after insertion.

## ◆ insert_thresh_contains() [3/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_thresh_contains | ( | const std::vector< uint64_t > & | hashes,
|  | const T | threshold
| ) |  |
| inline

Increment a k-mer's count if it's not above the threshold and then return the count.

Parameters

  hashes | Integer array of the k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried k-mer after insertion.

## ◆ insert_thresh_contains() [4/4]

template<typename T >

T btllib::KmerCountingBloomFilter< T >::insert_thresh_contains | ( | const uint64_t * | hashes,
|  | const T | threshold
| ) |  |
| inline

Increment a k-mer's count if it's not above the threshold and then return the count.

Parameters

  hashes | Integer array of the k-mer's hash values. Array size should equal the hash_num argument used when the Bloom filter was constructed.
  threshold | The threshold.

Returns
  The count of the queried k-mer after insertion.

## ◆ is_bloom_file()

template<typename T >

static bool btllib::KmerCountingBloomFilter< T >::is_bloom_file | ( | const std::string & | path | ) |
| inline static

Check whether the file at the given path is a saved k-mer counting Bloom filter.

Parameters

  path | Filepath to check.

## ◆ save()

template<typename T >

void btllib::KmerCountingBloomFilter< T >::save | ( | const std::string & | path | ) |
| inline

Save the Bloom filter to a file that can be loaded in the future.

Parameters

  path | Filepath to store filter at.

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

- include/btllib/counting_bloom_filter.hpp