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

#include <snarl_manager_decomposition.hpp>

Inheritance diagram for vg::SnarlManagerDecomposition:
handlegraph::SnarlDecomposition

Classes

struct  ChainPosition
 The place of a chain node in its chain. More...
 
class  NodeDirectory
 
class  TraversalSet
 
class  TraversalSurvey
 

Public Member Functions

 SnarlManagerDecomposition (const SnarlManager &manager, const HandleGraph &graph)
 
 ~SnarlManagerDecomposition () override=default
 
net_handle_t get_snarl_net (const Snarl *snarl) const
 Get the start-to-end traversal of a snarl. More...
 
const Snarl * get_snarl (const net_handle_t &net) const
 
net_handle_t get_root () const override
 
bool is_root (const net_handle_t &net) const override
 
bool is_snarl (const net_handle_t &net) const override
 
bool is_chain (const net_handle_t &net) const override
 
bool is_node (const net_handle_t &net) const override
 
bool is_sentinel (const net_handle_t &net) const override
 
net_handle_t get_net (const handle_t &handle, const HandleGraph *handle_graph) const override
 
handle_t get_handle (const net_handle_t &net, const HandleGraph *handle_graph) const override
 
net_handle_t get_parent (const net_handle_t &child) const override
 
net_handle_t get_bound (const net_handle_t &snarl, bool get_end, bool face_in) const override
 
net_handle_t flip (const net_handle_t &net) const override
 Flip a traversal, or turn a sentinel to face the other way. More...
 
net_handle_t canonical (const net_handle_t &net) const override
 
endpoint_t starts_at (const net_handle_t &traversal) const override
 
endpoint_t ends_at (const net_handle_t &traversal) const override
 
net_handle_t get_parent_traversal (const net_handle_t &traversal_start, const net_handle_t &traversal_end) const override
 
- Public Member Functions inherited from handlegraph::SnarlDecomposition
virtual ~SnarlDecomposition ()=default
 
template<typename Iteratee >
bool for_each_child (const net_handle_t &parent, const Iteratee &iteratee) const
 
template<typename Iteratee >
bool for_each_traversal (const net_handle_t &item, const Iteratee &iteratee) const
 
template<typename Iteratee >
bool follow_net_edges (const net_handle_t &here, const HandleGraph *graph, bool go_left, const Iteratee &iteratee) const
 
template<typename Iteratee >
bool for_each_tippy_child (const net_handle_t &parent, const Iteratee &iteratee) const
 
template<typename Iteratee >
bool for_each_traversal_start (const net_handle_t &traversal, const Iteratee &) const
 
template<typename Iteratee >
bool for_each_traversal_end (const net_handle_t &traversal, const Iteratee &) const
 
net_handle_t get_start_bound (const net_handle_t &parent) const
 
net_handle_t get_end_bound (const net_handle_t &parent) const
 
bool starts_at_start (const net_handle_t &net) const
 
bool starts_at_end (const net_handle_t &net) const
 
bool starts_at_tip (const net_handle_t &net) const
 
bool ends_at_start (const net_handle_t &net) const
 
bool ends_at_end (const net_handle_t &net) const
 
bool ends_at_tip (const net_handle_t &net) const
 

Protected Member Functions

bool for_each_child_impl (const net_handle_t &traversal, const std::function< bool(const net_handle_t &)> &iteratee) const override
 
bool for_each_traversal_impl (const net_handle_t &item, const std::function< bool(const net_handle_t &)> &iteratee) const override
 
bool follow_net_edges_impl (const net_handle_t &here, const HandleGraph *handle_graph, bool go_left, const std::function< bool(const net_handle_t &)> &iteratee) const override
 
- Protected Member Functions inherited from handlegraph::SnarlDecomposition
virtual bool for_each_tippy_child_impl (const net_handle_t &parent, const std::function< bool(const net_handle_t &)> &iteratee) const
 
virtual bool for_each_traversal_start_impl (const net_handle_t &traversal, const std::function< bool(const net_handle_t &)> &iteratee) const
 
virtual bool for_each_traversal_end_impl (const net_handle_t &traversal, const std::function< bool(const net_handle_t &)> &iteratee) const
 

Private Member Functions

Visit snarl_bound (const Snarl *snarl, bool get_end) const
 
const Snarl * snarl_of_number (uint64_t number) const
 Get the manager's Snarl for a snarl number. More...
 
net_handle_t snarl_net (const Snarl *snarl, bool forward) const
 
net_handle_t chain_net (const Chain &chain) const
 Get a chain's start-to-end net handle. More...
 
const Chain & chain_of_net (const net_handle_t &net) const
 Get the chain that a chain's net handle is for. More...
 
net_handle_t chain_node_net (const Chain &chain, size_t position, bool is_reverse) const
 
bool for_each_snarl_child (const Snarl *parent, const std::function< bool(const net_handle_t &)> &iteratee) const
 Call a function on each child of a snarl, or of the root if given null. More...
 
bool for_each_chain_child (const net_handle_t &traversal, const std::function< bool(const net_handle_t &)> &iteratee) const
 Call a function on each chain node and snarl of a chain. More...
 
std::optional< net_handle_t > next_in_chain (const net_handle_t &here) const
 
net_handle_t sibling_entered_by (const HandleGraph &graph, const handle_t &handle, const Snarl *parent) const
 
bool for_each_sibling_ahead (const HandleGraph &graph, const net_handle_t &here, const std::function< bool(const net_handle_t &)> &iteratee) const
 
bool for_each_traversal_from (const net_handle_t &element, endpoint_t start, const std::function< bool(const net_handle_t &)> &iteratee) const
 
bool follow_right (const HandleGraph &graph, const net_handle_t &here, const std::function< bool(const net_handle_t &)> &iteratee) const
 
std::pair< net_handle_t, endpoint_t > parent_endpoint (const net_handle_t &net, bool is_start) const
 
TraversalSet traversals_of (const net_handle_t &item) const
 

Private Attributes

const SnarlManager & manager
 The manager whose snarls the view presents. More...
 
NodeDirectory directory
 
TraversalSurvey survey
 

Additional Inherited Members

- Public Types inherited from handlegraph::SnarlDecomposition
enum  endpoint_t { START , END , TIP }
 

Detailed Description

A view of the snarls and chains in a SnarlManager, through the SnarlDecomposition interface.

A chain alternates chain nodes and snarls, starting and ending with a chain node. Each chain node has a position, counting from 0 at the start bound of the chain. The snarl of rank i lies between the chain nodes at positions i and i + 1.

Each snarl is oriented forward along its chain. So a Snarl that is reversed in parent starts at its end() flipped and ends at its start() flipped.

In a looping chain, the last snarl leads back into the first chain node. That node is both bounds of the chain, and one child at position 0.

Each node that is not a chain node is a free node. It is a trivial chain whose start-to-end traversal visits the node forward.

The view keeps a reference to the manager, which must outlive it and must not change. It does not keep the graph. A graph passed to a method must have the same nodes and edges as the graph the view was made with.

Note
Unlike a SnarlDistanceIndex, the view puts top-level chains directly in the root, and shows snarls that have no children.

Constructor & Destructor Documentation

◆ SnarlManagerDecomposition()

vg::SnarlManagerDecomposition::SnarlManagerDecomposition ( const SnarlManager &  manager,
const HandleGraph &  graph 
)

Make a view of the snarls in a SnarlManager.

Walk the graph to find which traversals of each snarl and chain are realizable.

Precondition
finish() has been called on the manager.
Exceptions
std::invalid_argumentIf the manager holds a unary snarl.

◆ ~SnarlManagerDecomposition()

vg::SnarlManagerDecomposition::~SnarlManagerDecomposition ( )
overridedefault

Member Function Documentation

◆ canonical()

net_handle_t vg::SnarlManagerDecomposition::canonical ( const net_handle_t &  net) const
overridevirtual

Get the canonical traversal of a net graph element.

For a snarl, chain or node, pick the first realizable traversal among start-to-end, start-to-tip, end-to-tip, start-to-start, end-to-end and tip-to-tip. For a sentinel, pick its bound facing in.

TODO: An element with no realizable traversal gets start-to-end, but the interface requires the canonical traversal to be realizable. Such elements exist: IntegratedSnarlFinder makes a snarl around a cycle that walks from both of its bounds fall into and never leave.

Implements handlegraph::SnarlDecomposition.

◆ chain_net()

net_handle_t vg::SnarlManagerDecomposition::chain_net ( const Chain &  chain) const
private

Get a chain's start-to-end net handle.

◆ chain_node_net()

net_handle_t vg::SnarlManagerDecomposition::chain_node_net ( const Chain &  chain,
size_t  position,
bool  is_reverse 
) const
private

Get the net handle for the chain node at a position, oriented in reverse along the chain if is_reverse, and forward along it otherwise.

◆ chain_of_net()

const Chain & vg::SnarlManagerDecomposition::chain_of_net ( const net_handle_t &  net) const
private

Get the chain that a chain's net handle is for.

◆ ends_at()

handlegraph::SnarlDecomposition::endpoint_t vg::SnarlManagerDecomposition::ends_at ( const net_handle_t &  traversal) const
overridevirtual

Return the kind of location at which the given traversal ends.

Implements handlegraph::SnarlDecomposition.

◆ flip()

net_handle_t vg::SnarlManagerDecomposition::flip ( const net_handle_t &  net) const
overridevirtual

Flip a traversal, or turn a sentinel to face the other way.

Implements handlegraph::SnarlDecomposition.

◆ follow_net_edges_impl()

bool vg::SnarlManagerDecomposition::follow_net_edges_impl ( const net_handle_t &  here,
const HandleGraph *  handle_graph,
bool  go_left,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
overrideprotectedvirtual

Call a function on each realizable traversal that comes just after or just before a traversal in its parent.

In a looping chain, going right from the last snarl gives the first chain node.

Implements handlegraph::SnarlDecomposition.

◆ follow_right()

bool vg::SnarlManagerDecomposition::follow_right ( const HandleGraph &  graph,
const net_handle_t &  here,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
private

Do follow_net_edges() going right.

Find the net graph elements that edges from the end of here lead into, and give each realizable traversal of them that starts at the endpoint the edge leads into.

◆ for_each_chain_child()

bool vg::SnarlManagerDecomposition::for_each_chain_child ( const net_handle_t &  traversal,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
private

Call a function on each chain node and snarl of a chain.

◆ for_each_child_impl()

bool vg::SnarlManagerDecomposition::for_each_child_impl ( const net_handle_t &  traversal,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
overrideprotectedvirtual

Call a function on each child of the root, a snarl, a chain or a trivial chain.

The root or a snarl gives its chains in the manager's order, then its free nodes in ID order. A chain traversal other than start-to-end and end-to-start gives the children in chain order, each start-to-end.

Implements handlegraph::SnarlDecomposition.

◆ for_each_sibling_ahead()

bool vg::SnarlManagerDecomposition::for_each_sibling_ahead ( const HandleGraph &  graph,
const net_handle_t &  here,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
private

Call a function on each sibling that an edge from the end of a traversal leads into.

A sibling is a chain or trivial chain in the same parent, or a sentinel of the parent facing out. A looping chain, a sentinel facing out, and a traversal that ends at a tip have no siblings ahead.

◆ for_each_snarl_child()

bool vg::SnarlManagerDecomposition::for_each_snarl_child ( const Snarl *  parent,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
private

Call a function on each child of a snarl, or of the root if given null.

◆ for_each_traversal_from()

bool vg::SnarlManagerDecomposition::for_each_traversal_from ( const net_handle_t &  element,
endpoint_t  start,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
private

Call a function on each realizable traversal of a net graph element that starts at the given endpoint.

◆ for_each_traversal_impl()

bool vg::SnarlManagerDecomposition::for_each_traversal_impl ( const net_handle_t &  item,
const std::function< bool(const net_handle_t &)> &  iteratee 
) const
overrideprotectedvirtual

Call a function on each realizable traversal of a net graph element.

Give them ordered by start endpoint, then end endpoint, each in the order START, END, TIP. A sentinel is its own only traversal.

Implements handlegraph::SnarlDecomposition.

◆ get_bound()

net_handle_t vg::SnarlManagerDecomposition::get_bound ( const net_handle_t &  snarl,
bool  get_end,
bool  face_in 
) const
overridevirtual

Get a sentinel of a snarl, or a boundary node of a chain.

A looping chain gives its first chain node as both bounds.

Implements handlegraph::SnarlDecomposition.

◆ get_handle()

handle_t vg::SnarlManagerDecomposition::get_handle ( const net_handle_t &  net,
const HandleGraph *  handle_graph 
) const
overridevirtual

Get the graph handle for a node, a trivial chain, or a sentinel.

A sentinel gives its boundary node, oriented the way the sentinel faces.

Exceptions
std::invalid_argumentIf the net handle is for a snarl, the root, or a chain that holds a snarl.

Implements handlegraph::SnarlDecomposition.

◆ get_net()

net_handle_t vg::SnarlManagerDecomposition::get_net ( const handle_t &  handle,
const HandleGraph *  graph 
) const
overridevirtual

Turn a handle to an oriented node into a net handle for a start-to-end or end-to-start traversal of the node, as appropriate.

Implements handlegraph::SnarlDecomposition.

◆ get_parent()

net_handle_t vg::SnarlManagerDecomposition::get_parent ( const net_handle_t &  child) const
overridevirtual

Get the parent snarl of a chain, or the parent chain of a snarl or node. If the child is start-to-end or end-to-start, and the parent is a chain, the chain comes out facing the same way, accounting for the relative orientation of the child snarl or node in the chain. Otherwise, everything is produced as start-to-end, even if that is not actually a realizable traversal of a snarl or chain. May not be called on the root snarl.

Also works on snarl boundary sentinels.

Implements handlegraph::SnarlDecomposition.

◆ get_parent_traversal()

net_handle_t vg::SnarlManagerDecomposition::get_parent_traversal ( const net_handle_t &  traversal_start,
const net_handle_t &  traversal_end 
) const
overridevirtual

Get the traversal of a snarl or chain from one of its children or bounds to another.

Exceptions
std::invalid_argumentIf the two arguments are in different snarls or chains, or if the traversal between them is not realizable.

Implements handlegraph::SnarlDecomposition.

◆ get_root()

net_handle_t vg::SnarlManagerDecomposition::get_root ( ) const
overridevirtual

Get a net handle referring to a tip-to-tip traversal of the contents of the root snarl. TODO: Special handling for circular things in the root snarl? Circular traversal type?

Implements handlegraph::SnarlDecomposition.

◆ get_snarl()

const Snarl * vg::SnarlManagerDecomposition::get_snarl ( const net_handle_t &  net) const

Get the manager's Snarl for a traversal of a snarl.

Exceptions
std::invalid_argumentIf the net handle is not for a snarl.

◆ get_snarl_net()

net_handle_t vg::SnarlManagerDecomposition::get_snarl_net ( const Snarl *  snarl) const

Get the start-to-end traversal of a snarl.

◆ is_chain()

bool vg::SnarlManagerDecomposition::is_chain ( const net_handle_t &  net) const
overridevirtual

Returns true if the given net handle refers to (a traversal of) a chain.

Implements handlegraph::SnarlDecomposition.

◆ is_node()

bool vg::SnarlManagerDecomposition::is_node ( const net_handle_t &  net) const
overridevirtual

Returns true if the given net handle refers to (a traversal of) a single node, and thus has a corresponding handle_t.

Implements handlegraph::SnarlDecomposition.

◆ is_root()

bool vg::SnarlManagerDecomposition::is_root ( const net_handle_t &  net) const
overridevirtual

Return true if the given handle refers to (a traversal of) the root snarl, and false otherwise.

Implements handlegraph::SnarlDecomposition.

◆ is_sentinel()

bool vg::SnarlManagerDecomposition::is_sentinel ( const net_handle_t &  net) const
overridevirtual

Return true if the given net handle is a snarl bound sentinel (in either inward or outward orientation), and false otherwise.

Implements handlegraph::SnarlDecomposition.

◆ is_snarl()

bool vg::SnarlManagerDecomposition::is_snarl ( const net_handle_t &  net) const
overridevirtual

Returns true if the given net handle refers to (a traversal of) a snarl.

Implements handlegraph::SnarlDecomposition.

◆ next_in_chain()

optional< net_handle_t > vg::SnarlManagerDecomposition::next_in_chain ( const net_handle_t &  here) const
private

Get the next child in a chain after a chain node or snarl.

Return nullopt when here ends at a tip, leaves its chain at a bound, or is a free node.

Precondition
here is a start-to-end or end-to-start traversal of a node, or any traversal of a snarl.

◆ parent_endpoint()

pair< net_handle_t, endpoint_t > vg::SnarlManagerDecomposition::parent_endpoint ( const net_handle_t &  net,
bool  is_start 
) const
private

Find the snarl or chain, and its endpoint, where a traversal of it can start or end at a net graph element or sentinel.

Parameters
netOne of:
  • A sentinel facing into its snarl, if is_start, or out of it otherwise. This gives the snarl and the bound of the sentinel.
  • A node traversal that enters its chain or trivial chain at a bound, if is_start, or leaves it at a bound otherwise. This gives the chain and that bound.
  • A snarl, chain or trivial chain, which gives its parent and TIP.
Returns
The snarl or chain, start-to-end, and the endpoint.
Exceptions
std::invalid_argumentIf net is the root, a child of the root, a sentinel facing the wrong way, or a node traversal that does not enter or leave its chain at a bound.

◆ sibling_entered_by()

net_handle_t vg::SnarlManagerDecomposition::sibling_entered_by ( const HandleGraph &  graph,
const handle_t &  handle,
const Snarl *  parent 
) const
private

Get the child of a snarl or the root that a handle enters.

If the handle leaves the parent, return the sentinel of the parent for that bound, facing out.

Exceptions
std::logic_errorIf the handle enters a chain between its bounds.

◆ snarl_bound()

Visit vg::SnarlManagerDecomposition::snarl_bound ( const Snarl *  snarl,
bool  get_end 
) const
private

Get a snarl's start bound oriented into the snarl, or its end bound oriented out of it.

◆ snarl_net()

net_handle_t vg::SnarlManagerDecomposition::snarl_net ( const Snarl *  snarl,
bool  forward 
) const
private

Get a snarl's net handle, start-to-end if forward and end-to-start otherwise.

◆ snarl_of_number()

const Snarl * vg::SnarlManagerDecomposition::snarl_of_number ( uint64_t  number) const
private

Get the manager's Snarl for a snarl number.

◆ starts_at()

handlegraph::SnarlDecomposition::endpoint_t vg::SnarlManagerDecomposition::starts_at ( const net_handle_t &  traversal) const
overridevirtual

Return the kind of location at which the given traversal starts.

Implements handlegraph::SnarlDecomposition.

◆ traversals_of()

SnarlManagerDecomposition::TraversalSet vg::SnarlManagerDecomposition::traversals_of ( const net_handle_t &  item) const
private

Get the realizable traversals of a net graph element. A sentinel's only traversal is itself.

Member Data Documentation

◆ directory

NodeDirectory vg::SnarlManagerDecomposition::directory
private

Tells the view each node's place in its chain, and the snarl that contains it.

◆ manager

const SnarlManager& vg::SnarlManagerDecomposition::manager
private

The manager whose snarls the view presents.

◆ survey

TraversalSurvey vg::SnarlManagerDecomposition::survey
private

Tells the view which traversals of each snarl and chain are realizable.


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