vg
tools for working with variation graphs
|
#include <snarls.hpp>
Classes | |
struct | SnarlRecord |
Public Member Functions | |
template<typename SnarlIterator > | |
SnarlManager (SnarlIterator begin, SnarlIterator end) | |
SnarlManager (istream &in) | |
Construct a SnarlManager for the snarls contained in an input stream. More... | |
SnarlManager (const function< void(const function< void(Snarl &)> &)> &for_each_snarl) | |
Construct a SnarlManager from a function that calls a callback with each Snarl in turn. More... | |
SnarlManager ()=default | |
~SnarlManager ()=default | |
Destructor. More... | |
SnarlManager (const SnarlManager &other)=delete | |
Cannot be copied because of all the internal pointer indexes. More... | |
SnarlManager & | operator= (const SnarlManager &other)=delete |
SnarlManager (SnarlManager &&other)=default | |
Can be moved. More... | |
SnarlManager & | operator= (SnarlManager &&other)=default |
void | serialize (ostream &out) const |
const Snarl * | add_snarl (const Snarl &new_snarl) |
void | flip (const Snarl *snarl) |
Reverses the orientation of a managed snarl. More... | |
void | flip (const Chain *snarl) |
void | finish () |
const vector< const Snarl * > & | children_of (const Snarl *snarl) const |
const Snarl * | parent_of (const Snarl *snarl) const |
Returns a pointer to the parent of a Snarl or nullptr if there is none. More... | |
const Snarl * | into_which_snarl (int64_t id, bool reverse) const |
const Snarl * | into_which_snarl (const Visit &visit) const |
const Chain * | chain_of (const Snarl *snarl) const |
bool | chain_orientation_of (const Snarl *snarl) const |
size_t | chain_rank_of (const Snarl *snarl) const |
bool | in_nontrivial_chain (const Snarl *here) const |
const deque< Chain > & | chains_of (const Snarl *snarl) const |
NetGraph | net_graph_of (const Snarl *snarl, const HandleGraph *graph, bool use_internal_connectivity=true) const |
bool | is_leaf (const Snarl *snarl) const |
Returns true if snarl has no children and false otherwise. More... | |
bool | is_root (const Snarl *snarl) const |
Returns true if snarl has no parent and false otherwise. More... | |
bool | is_trivial (const Snarl *snarl, const HandleGraph &graph) const |
bool | all_children_trivial (const Snarl *snarl, const HandleGraph &graph) const |
Returns true if the snarl lacks any nontrivial children. More... | |
const vector< const Snarl * > & | top_level_snarls () const |
Returns a reference to a vector with the roots of the Snarl trees. More... | |
pair< unordered_set< id_t >, unordered_set< edge_t > > | shallow_contents (const Snarl *snarl, const HandleGraph &graph, bool include_boundary_nodes) const |
pair< unordered_set< id_t >, unordered_set< edge_t > > | deep_contents (const Snarl *snarl, const HandleGraph &graph, bool include_boundary_nodes) const |
vector< Visit > | visits_left (const Visit &visit, const HandleGraph &graph, const Snarl *in_snarl) const |
vector< Visit > | visits_right (const Visit &visit, const HandleGraph &graph, const Snarl *in_snarl) const |
unordered_map< pair< int64_t, bool >, const Snarl * > | snarl_boundary_index () const |
unordered_map< pair< int64_t, bool >, const Snarl * > | snarl_start_index () const |
Returns a map from all Snarl start boundaries to the Snarl they point into. More... | |
unordered_map< pair< int64_t, bool >, const Snarl * > | snarl_end_index () const |
void | for_each_top_level_snarl (const function< void(const Snarl *)> &lambda) const |
Execute a function on all top level sites. More... | |
void | for_each_snarl_preorder (const function< void(const Snarl *)> &lambda) const |
Execute a function on all sites in a preorder traversal. More... | |
void | for_each_top_level_snarl_parallel (const function< void(const Snarl *)> &lambda) const |
Execute a function on all top level sites in parallel. More... | |
void | for_each_snarl_parallel (const function< void(const Snarl *)> &lambda) const |
Execute a function on all sites in parallel. More... | |
void | for_each_top_level_chain (const function< void(const Chain *)> &lambda) const |
Execute a function on all top level chains. More... | |
void | for_each_top_level_chain_parallel (const function< void(const Chain *)> &lambda) const |
Execute a function on all top level chains in parallel. More... | |
void | for_each_chain (const function< void(const Chain *)> &lambda) const |
Ececute a function on all chains. More... | |
void | for_each_chain_parallel (const function< void(const Chain *)> &lambda) const |
Ececute a function on all chains in parallel. More... | |
void | for_each_snarl_unindexed (const function< void(const Snarl *)> &lambda) const |
Iterate over snarls as they are stored in deque<SnarlRecords> More... | |
const Snarl * | manage (const Snarl ¬_owned) const |
const Snarl * | discrete_uniform_sample (minstd_rand0 &random_engine) const |
int | num_snarls () const |
Count snarls in deque<SnarlRecords>, a master list of snarls in graph. More... | |
size_t | snarl_number (const Snarl *snarl) const |
Get the snarl number from the SnarlRecord* member with given snarl. More... | |
const Snarl * | translate_snarl_num (size_t snarl_num) |
Private Member Functions | |
const SnarlRecord * | record (const Snarl *snarl) const |
Get the const SnarlRecord for a const managed snarl. More... | |
SnarlRecord * | record (Snarl *snarl) |
Get the SnarlRecord for a managed snarl. More... | |
const Snarl * | unrecord (const SnarlRecord *record) const |
Get the const Snarl owned by a const SnarlRecord. More... | |
Snarl * | unrecord (SnarlRecord *record) |
Get the Snarl owned by a SnarlRecord. More... | |
void | build_indexes () |
Builds tree indexes after Snarls have been added to the snarls vector. More... | |
deque< Chain > | compute_chains (const vector< const Snarl * > &input_snarls) |
void | regularize () |
Visit | next_snarl (const Visit &here) const |
Visit | prev_snarl (const Visit &here) const |
const Snarl * | snarl_sharing_start (const Snarl *here) const |
const Snarl * | snarl_sharing_end (const Snarl *here) const |
Private Attributes | |
deque< SnarlRecord > | snarls |
vector< const Snarl * > | roots |
Roots of snarl trees. More... | |
deque< Chain > | root_chains |
Chains of root-level snarls. Uses a deque so Chain* pointers don't get invalidated. More... | |
unordered_map< pair< int64_t, bool >, const Snarl * > | snarl_into |
Map of node traversals to the snarls they point into. More... | |
A structure to keep track of the tree relationships between Snarls and perform utility algorithms on them
vg::SnarlManager::SnarlManager | ( | SnarlIterator | begin, |
SnarlIterator | end | ||
) |
Construct a SnarlManager for the snarls returned by an iterator Also covers iterators of chains of snarls.
vg::SnarlManager::SnarlManager | ( | istream & | in | ) |
Construct a SnarlManager for the snarls contained in an input stream.
vg::SnarlManager::SnarlManager | ( | const function< void(const function< void(Snarl &)> &)> & | for_each_snarl | ) |
Construct a SnarlManager from a function that calls a callback with each Snarl in turn.
|
default |
Default constructor for an empty SnarlManager. Must call finish() once all snarls have been added with add_snarl().
|
default |
Destructor.
|
delete |
Cannot be copied because of all the internal pointer indexes.
|
default |
Can be moved.
Add the given snarl to the SnarlManager. After all snarls have been added, finish() must be called to compute chains and indexes. We don't let precomputed chains be added, because we want chain orientations relative to snarls to be deterministic given an order of snarls. Returns a pointer to the managed snarl copy. Only this function may add in new Snarls.
bool vg::SnarlManager::all_children_trivial | ( | const Snarl * | snarl, |
const HandleGraph & | graph | ||
) | const |
Returns true if the snarl lacks any nontrivial children.
|
private |
Builds tree indexes after Snarls have been added to the snarls vector.
Get the Chain that the given snarl participates in. Instead of asking this class to walk the chain for you, use ChainIterators on this chain. This is always non-null.
bool vg::SnarlManager::chain_orientation_of | ( | const Snarl * | snarl | ) | const |
If the given Snarl is backward in its chain, return true. Otherwise, return false.
size_t vg::SnarlManager::chain_rank_of | ( | const Snarl * | snarl | ) | const |
Get the rank that the given snarl appears in in its chain. If two snarls are in forward orientation in the chain, then leaving the end of the lower rank snarl will eventually reach the start of the higher rank snarl. If either or both snarls is backward, you leave/arrive at the other bounding node instead.
Sorting snarls by rank will let you visit them in chain order without walking the whole chain.
Get all the snarls in all the chains under the given parent snarl. If the parent snarl is null, gives the top-level chains that connect and contain the top-level root snarls. Unary snarls and snarls in trivial chains will be presented as their own chains. Snarls are not necessarily oriented appropriately given their ordering in the chain. Useful for making a net graph.
Returns a vector of pointers to the children of a Snarl. If given null, returns the top-level root snarls.
|
private |
Actually compute chains for a set of already indexed snarls, which is important when chains were not provided. Returns the chains.
pair< unordered_set< id_t >, unordered_set< edge_t > > vg::SnarlManager::deep_contents | ( | const Snarl * | snarl, |
const HandleGraph & | graph, | ||
bool | include_boundary_nodes | ||
) | const |
const Snarl * vg::SnarlManager::discrete_uniform_sample | ( | minstd_rand0 & | random_engine | ) | const |
Sample snarls discrete uniformly Returns a nullptr if no snarls are found
void vg::SnarlManager::finish | ( | ) |
Note that we have finished calling add_snarl. Compute the snarl parent/child indexes and chains.
void vg::SnarlManager::flip | ( | const Chain * | snarl | ) |
Reverses the order and orientation of a managed chain, leaving all the component snarls in their original orientations.
void vg::SnarlManager::flip | ( | const Snarl * | snarl | ) |
Reverses the orientation of a managed snarl.
void vg::SnarlManager::for_each_chain | ( | const function< void(const Chain *)> & | lambda | ) | const |
Ececute a function on all chains.
void vg::SnarlManager::for_each_chain_parallel | ( | const function< void(const Chain *)> & | lambda | ) | const |
Ececute a function on all chains in parallel.
void vg::SnarlManager::for_each_snarl_parallel | ( | const function< void(const Snarl *)> & | lambda | ) | const |
Execute a function on all sites in parallel.
void vg::SnarlManager::for_each_snarl_preorder | ( | const function< void(const Snarl *)> & | lambda | ) | const |
Execute a function on all sites in a preorder traversal.
void vg::SnarlManager::for_each_snarl_unindexed | ( | const function< void(const Snarl *)> & | lambda | ) | const |
Iterate over snarls as they are stored in deque<SnarlRecords>
void vg::SnarlManager::for_each_top_level_chain | ( | const function< void(const Chain *)> & | lambda | ) | const |
Execute a function on all top level chains.
void vg::SnarlManager::for_each_top_level_chain_parallel | ( | const function< void(const Chain *)> & | lambda | ) | const |
Execute a function on all top level chains in parallel.
void vg::SnarlManager::for_each_top_level_snarl | ( | const function< void(const Snarl *)> & | lambda | ) | const |
Execute a function on all top level sites.
void vg::SnarlManager::for_each_top_level_snarl_parallel | ( | const function< void(const Snarl *)> & | lambda | ) | const |
Execute a function on all top level sites in parallel.
bool vg::SnarlManager::in_nontrivial_chain | ( | const Snarl * | here | ) | const |
Return true if a Snarl is part of a nontrivial chain of more than one snarl. Note that chain_of() still works for snarls in trivial chains.
const Snarl * vg::SnarlManager::into_which_snarl | ( | int64_t | id, |
bool | reverse | ||
) | const |
bool vg::SnarlManager::is_leaf | ( | const Snarl * | snarl | ) | const |
Returns true if snarl has no children and false otherwise.
bool vg::SnarlManager::is_root | ( | const Snarl * | snarl | ) | const |
Returns true if snarl has no parent and false otherwise.
bool vg::SnarlManager::is_trivial | ( | const Snarl * | snarl, |
const HandleGraph & | graph | ||
) | const |
Returns true if the snarl is trivial (an ultrabubble with just the start and end nodes) and false otherwise. TODO: Implement without needing the vg graph, by adding a flag to trivial snarls.
NetGraph vg::SnarlManager::net_graph_of | ( | const Snarl * | snarl, |
const HandleGraph * | graph, | ||
bool | use_internal_connectivity = true |
||
) | const |
Get the net graph of the given Snarl's contents, using the given backing HandleGraph. If use_internal_connectivity is false, each chain and unary child snarl is treated as an ordinary node which is assumed to be only traversable from one side to the other. Otherwise, traversing the graph works like it would if you actually went through the internal graphs fo child snarls.
int vg::SnarlManager::num_snarls | ( | ) | const |
Count snarls in deque<SnarlRecords>, a master list of snarls in graph.
|
delete |
|
default |
Returns a pointer to the parent of a Snarl or nullptr if there is none.
|
inlineprivate |
Get the const SnarlRecord for a const managed snarl.
|
inlineprivate |
Get the SnarlRecord for a managed snarl.
|
private |
Modify the snarls and chains to enforce a couple of invariants:
(This is needed by the distance indexing code, which identifies child snarls by their start nodes. TODO: That distance indexing code needs to also work out unary snarls abitting the ends of chains, which may be allowed eventually.)
Depends on the indexes from build_indexes() having been built.
void vg::SnarlManager::serialize | ( | ostream & | out | ) | const |
pair< unordered_set< id_t >, unordered_set< edge_t > > vg::SnarlManager::shallow_contents | ( | const Snarl * | snarl, |
const HandleGraph & | graph, | ||
bool | include_boundary_nodes | ||
) | const |
unordered_map< pair< int64_t, bool >, const Snarl * > vg::SnarlManager::snarl_boundary_index | ( | ) | const |
unordered_map< pair< int64_t, bool >, const Snarl * > vg::SnarlManager::snarl_end_index | ( | ) | const |
|
inline |
Get the snarl number from the SnarlRecord* member with given snarl.
unordered_map< pair< int64_t, bool >, const Snarl * > vg::SnarlManager::snarl_start_index | ( | ) | const |
const vector< const Snarl * > & vg::SnarlManager::top_level_snarls | ( | ) | const |
Returns a reference to a vector with the roots of the Snarl trees.
|
inline |
|
inlineprivate |
Get the const Snarl owned by a const SnarlRecord.
|
inlineprivate |
Get the Snarl owned by a SnarlRecord.
vector< Visit > vg::SnarlManager::visits_left | ( | const Visit & | visit, |
const HandleGraph & | graph, | ||
const Snarl * | in_snarl | ||
) | const |
Look left from the given visit in the given graph and gets all the attached Visits to nodes or snarls.
vector< Visit > vg::SnarlManager::visits_right | ( | const Visit & | visit, |
const HandleGraph & | graph, | ||
const Snarl * | in_snarl | ||
) | const |
Look left from the given visit in the given graph and gets all the attached Visits to nodes or snarls.
|
private |
Chains of root-level snarls. Uses a deque so Chain* pointers don't get invalidated.
|
private |
Roots of snarl trees.
|
private |
Map of node traversals to the snarls they point into.
|
private |
Master list of the snarls in the graph. Use a deque so pointers never get invalidated but we still have some locality.