|
vg
tools for working with variation graphs
|
#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 |
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.
| typedef std::pair<std::uint32_t, std::uint32_t> vg::KmerPresenceMatrix::compact_sequence_type |
A more space-efficient representation of 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).
| enum vg::KmerPresenceMatrix::kmer_classification : size_t |
| vg::KmerPresenceMatrix::KmerPresenceMatrix | ( | ) |
Default constructor that creates an empty k-mer presence matrix.
| 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.
| 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.
|
default |
|
defaultnoexcept |
|
inlineprivate |
| 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.
|
inline |
Returns true if the matrix is empty.
| 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.
|
inline |
Returns the number of kmers (columns) in the matrix.
|
inline |
Returns the number of clusters, which is also the number of sequences stored explicitly as parents.
| size_t vg::KmerPresenceMatrix::get_num_present | ( | size_t | sequence | ) | const |
Returns the number of present kmers in the given sequence.
|
inline |
Returns the number of sequences (rows) in the matrix.
| size_t vg::KmerPresenceMatrix::get_total_present | ( | ) | const |
Returns the the total number of present kmers in the sequences.
|
inlineprivate |
|
inline |
|
default |
|
defaultnoexcept |
| bool vg::KmerPresenceMatrix::operator== | ( | const KmerPresenceMatrix & | other | ) | const |
|
inlineprivate |
| 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.
| void vg::KmerPresenceMatrix::simple_sds_load | ( | std::istream & | in | ) |
Loads the object from a stream in the Simple-SDS format.
| void vg::KmerPresenceMatrix::simple_sds_serialize | ( | std::ostream & | out | ) | const |
Serializes the object to a stream in the Simple-SDS format.
| size_t vg::KmerPresenceMatrix::simple_sds_size | ( | ) | const |
Returns the size of the object in elements.
|
inline |
Returns the size of the matrix (the number of cells in it).
|
private |
|
private |
|
private |
|
private |
1.9.1