vg
tools for working with variation graphs
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
vg::KmerPresenceMatrix Class Reference

#include <recombinator_haplotypes.hpp>

Classes

struct  ChildIterator
 
struct  Iterator
 

Public Types

enum  kmer_classification : size_t { absent = 0 , heterozygous = 1 , present = 2 , frequent = 3 }
 Kmer classification. More...
 
typedef std::pair< gbwt::size_type, gbwt::size_type > sequence_type
 A GBWT sequence as (sequence identifier, offset in a node). More...
 
typedef std::pair< std::uint32_t, std::uint32_t > compact_sequence_type
 A more space-efficient representation of sequence_type. More...
 

Public Member Functions

 KmerPresenceMatrix ()
 Default constructor that creates an empty k-mer presence matrix. More...
 
 KmerPresenceMatrix (size_t num_sequences, size_t num_kmers, sdsl::bit_vector &&matrix)
 
 KmerPresenceMatrix (const std::vector< sequence_type > &sequences, std::vector< compact_sequence_type > &reordered_sequences, size_t num_kmers, const sdsl::bit_vector &matrix)
 
 KmerPresenceMatrix (const KmerPresenceMatrix &other)=default
 
 KmerPresenceMatrix (KmerPresenceMatrix &&other) noexcept=default
 
KmerPresenceMatrix & operator= (const KmerPresenceMatrix &other)=default
 
KmerPresenceMatrix & operator= (KmerPresenceMatrix &&other) noexcept=default
 
bool operator== (const KmerPresenceMatrix &other) const
 
bool operator!= (const KmerPresenceMatrix &other) const
 
size_t size () const
 Returns the size of the matrix (the number of cells in it). More...
 
bool empty () const
 Returns true if the matrix is empty. More...
 
size_t get_num_sequences () const
 Returns the number of sequences (rows) in the matrix. More...
 
size_t get_num_kmers () const
 Returns the number of kmers (columns) in the matrix. More...
 
size_t get_num_parents () const
 
size_t get_num_present (size_t sequence) const
 Returns the number of present kmers in the given sequence. More...
 
size_t get_total_present () const
 Returns the the total number of present kmers in the sequences. More...
 
void for_each_kmer (size_t sequence, const std::function< void(size_t, bool)> &callback) const
 
void score_sequences (const std::vector< std::pair< kmer_classification, double >> &kmers, const std::function< void(size_t, double)> &sequence_score) const
 
std::int64_t diploid_score (size_t first, size_t second, const std::vector< std::pair< kmer_classification, double >> &kmers) const
 
void simple_sds_serialize (std::ostream &out) const
 Serializes the object to a stream in the Simple-SDS format. More...
 
void simple_sds_load (std::istream &in)
 Loads the object from a stream in the Simple-SDS format. More...
 
size_t simple_sds_size () const
 Returns the size of the object in elements. More...
 

Private Member Functions

size_t parent (size_t rank) const
 
size_t child_rank (size_t rank) const
 
bool is_parent (size_t rank) const
 

Private Attributes

size_t num_kmers
 
sdsl::int_vector parent_rank
 
sdsl::bit_vector parents
 
sdsl::sd_vector children
 

Detailed Description

A compressed binary matrix with haplotype sequences as rows and k-mers as columns. Set bits indicate k-mers that are present in the corresponding sequence.

The compression assumes that the matrix consists of clusters of similar sequences. We choose one sequence from each cluster as a parent and store it explicitly. For the other sequences (children), we only store the symmetric difference with their parent sequence. The internal representation reorders the sequences so that the parent of each cluster appears first, followed by its children.

Member Typedef Documentation

◆ compact_sequence_type

typedef std::pair<std::uint32_t, std::uint32_t> vg::KmerPresenceMatrix::compact_sequence_type

A more space-efficient representation of sequence_type.

◆ sequence_type

typedef std::pair<gbwt::size_type, gbwt::size_type> vg::KmerPresenceMatrix::sequence_type

A GBWT sequence as (sequence identifier, offset in a node).

Member Enumeration Documentation

◆ kmer_classification

Kmer classification.

Enumerator
absent 
heterozygous 
present 
frequent 

Constructor & Destructor Documentation

◆ KmerPresenceMatrix() [1/5]

vg::KmerPresenceMatrix::KmerPresenceMatrix ( )

Default constructor that creates an empty k-mer presence matrix.

◆ KmerPresenceMatrix() [2/5]

vg::KmerPresenceMatrix::KmerPresenceMatrix ( size_t  num_sequences,
size_t  num_kmers,
sdsl::bit_vector &&  matrix 
)

Constructor that creates an uncompressed k-mer presence matrix by taking ownership of the given matrix. See below for the semantics of the matrix. Throws std::runtime_error if the dimensions do not match.

◆ KmerPresenceMatrix() [3/5]

vg::KmerPresenceMatrix::KmerPresenceMatrix ( const std::vector< sequence_type > &  sequences,
std::vector< compact_sequence_type > &  reordered_sequences,
size_t  num_kmers,
const sdsl::bit_vector &  matrix 
)

Constructor from a given uncompressed matrix, where sequence i contains kmer j if and only if matrix[i * num_kmers + j] == 1. Throws std::runtime_error if the dimensions do not match. Reorders the sequences to reordered_sequences to match the internal representation.

◆ KmerPresenceMatrix() [4/5]

vg::KmerPresenceMatrix::KmerPresenceMatrix ( const KmerPresenceMatrix &  other)
default

◆ KmerPresenceMatrix() [5/5]

vg::KmerPresenceMatrix::KmerPresenceMatrix ( KmerPresenceMatrix &&  other)
defaultnoexcept

Member Function Documentation

◆ child_rank()

size_t vg::KmerPresenceMatrix::child_rank ( size_t  rank) const
inlineprivate

◆ diploid_score()

std::int64_t vg::KmerPresenceMatrix::diploid_score ( size_t  first,
size_t  second,
const std::vector< std::pair< kmer_classification, double >> &  kmers 
) const

Scores a pair of sequences in the subchain. The score is the sum of 1 - abs(expected - observed) over the kmers.

◆ empty()

bool vg::KmerPresenceMatrix::empty ( ) const
inline

Returns true if the matrix is empty.

◆ for_each_kmer()

void vg::KmerPresenceMatrix::for_each_kmer ( size_t  sequence,
const std::function< void(size_t, bool)> &  callback 
) const

Calls callback(kmer_index, is_present) for each kmer in the given sequence, ordered by their indices.

◆ get_num_kmers()

size_t vg::KmerPresenceMatrix::get_num_kmers ( ) const
inline

Returns the number of kmers (columns) in the matrix.

◆ get_num_parents()

size_t vg::KmerPresenceMatrix::get_num_parents ( ) const
inline

Returns the number of clusters, which is also the number of sequences stored explicitly as parents.

◆ get_num_present()

size_t vg::KmerPresenceMatrix::get_num_present ( size_t  sequence) const

Returns the number of present kmers in the given sequence.

◆ get_num_sequences()

size_t vg::KmerPresenceMatrix::get_num_sequences ( ) const
inline

Returns the number of sequences (rows) in the matrix.

◆ get_total_present()

size_t vg::KmerPresenceMatrix::get_total_present ( ) const

Returns the the total number of present kmers in the sequences.

◆ is_parent()

bool vg::KmerPresenceMatrix::is_parent ( size_t  rank) const
inlineprivate

◆ operator!=()

bool vg::KmerPresenceMatrix::operator!= ( const KmerPresenceMatrix &  other) const
inline

◆ operator=() [1/2]

KmerPresenceMatrix& vg::KmerPresenceMatrix::operator= ( const KmerPresenceMatrix &  other)
default

◆ operator=() [2/2]

KmerPresenceMatrix& vg::KmerPresenceMatrix::operator= ( KmerPresenceMatrix &&  other)
defaultnoexcept

◆ operator==()

bool vg::KmerPresenceMatrix::operator== ( const KmerPresenceMatrix &  other) const

◆ parent()

size_t vg::KmerPresenceMatrix::parent ( size_t  rank) const
inlineprivate

◆ score_sequences()

void vg::KmerPresenceMatrix::score_sequences ( const std::vector< std::pair< kmer_classification, double >> &  kmers,
const std::function< void(size_t, double)> &  sequence_score 
) const

Scores every sequence in the subchain. The score of a sequence is the sum of (present : 1 : -1) * kmer.second over kmers. It is reported by calling sequence_score(sequence, score) in an arbitrary order.

NOTE: Because we reuse the score of a parent when scoring its children, the scores are often different from what we would get by scoring each sequence independently. This is due to numerical instability with floating point arithmetic.

◆ simple_sds_load()

void vg::KmerPresenceMatrix::simple_sds_load ( std::istream &  in)

Loads the object from a stream in the Simple-SDS format.

◆ simple_sds_serialize()

void vg::KmerPresenceMatrix::simple_sds_serialize ( std::ostream &  out) const

Serializes the object to a stream in the Simple-SDS format.

◆ simple_sds_size()

size_t vg::KmerPresenceMatrix::simple_sds_size ( ) const

Returns the size of the object in elements.

◆ size()

size_t vg::KmerPresenceMatrix::size ( ) const
inline

Returns the size of the matrix (the number of cells in it).

Member Data Documentation

◆ children

sdsl::sd_vector vg::KmerPresenceMatrix::children
private

◆ num_kmers

size_t vg::KmerPresenceMatrix::num_kmers
private

◆ parent_rank

sdsl::int_vector vg::KmerPresenceMatrix::parent_rank
private

◆ parents

sdsl::bit_vector vg::KmerPresenceMatrix::parents
private

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