|
vg
tools for working with variation graphs
|
#include <zip_code_tree.hpp>
Public Types | |
| enum | State { S_START, S_SCAN_CHAIN, S_SCAN_DAG_SNARL, S_SCAN_CYCLIC_SNARL } |
Public Member Functions | |
| distance_iterator (size_t start_index, const vector< tree_item_t > &zip_code_tree, std::stack< size_t > chain_numbers=std::stack< size_t >(), bool right_to_left=true, size_t distance_limit=std::numeric_limits< size_t >::max()) | |
| distance_iterator & | operator++ () |
| Move in right_to_left direction until we hit another seed or the end. More... | |
| void | move_index () |
| Move index in right_to_left direction. More... | |
| bool | operator== (const distance_iterator &other) const |
| bool | operator!= (const distance_iterator &other) const |
| Compare for inequality. More... | |
| bool | done () const |
| Is the iteration done? More... | |
| seed_result_t | operator* () const |
Private Member Functions | |
| void | push (size_t value) |
| Push a value to the stack. More... | |
| size_t | pop () |
| Pop a value from the stack and return it. More... | |
| size_t & | top () |
| Get a mutable reference to the value on top of the stack. More... | |
| void | dup () |
| Duplicate the top item on the stack. More... | |
| size_t | depth () const |
| Check stack depth. More... | |
| void | swap () |
| Reverse the top two elements of the stack. More... | |
| void | stack_snarl_distances (size_t snarl_start_i, size_t chain_num, bool right_side) |
| void | stack_matrix_value (size_t matrix_start_i, bool has_main_diagonal, size_t row, size_t col) |
| void | stack_below_top (size_t value) |
| void | state (State new_state) |
| Adopt a new state. More... | |
| void | halt () |
| void | unimplemented_error () |
| Throw a domain_error that the current state/symbol combo is unimplemented. More... | |
| tree_item_t | current_item () const |
| What item does index point to? More... | |
| bool | entered_snarl () const |
| bool | exited_snarl () const |
| bool | entered_chain () const |
| bool | exited_chain () const |
| void | skip_chain () |
| void | initialize_chain () |
| bool | initialize_snarl (size_t chain_num) |
| void | continue_snarl () |
| bool | tick () |
Private Attributes | |
| size_t | index |
| Where we are in the stored tree. More... | |
| const size_t | end_index |
| Where we have to stop. More... | |
| const size_t | original_index |
| Where we started from. More... | |
| std::stack< size_t > | chain_numbers |
| Within each parent snarl, which chain are we in? More... | |
| size_t | distance_limit |
| Distance limit we will go up to. More... | |
| bool | right_to_left |
| Whether we are looking right to left (true) or left to right (false) More... | |
| const bool | original_right_to_left |
| Original direction. More... | |
| const vector< tree_item_t > & | zip_code_tree |
| References to the zip code tree to let us look up distance matrices. More... | |
| std::stack< size_t > | stack_data |
| Stack for computing distances. More... | |
| State | current_state |
| Current state of the automaton. More... | |
Iterator that looks sideways in the tree from a seed, possibly up to a maximum base distance.
Iteration flow:
Original Python implementation: https://github.com/benedictpaten/long_read_giraffe_chainer_prototype/blob/b590c34055474b0c901a681a1aa99f1651abb6a4/zip_tree_iterator.py.
New cyclic snarl handling flowchart: https://docs.google.com/drawings/d/1diKMXCuMteR06fF64BhSttsD5RHh3eTnd8FtyYqs17Y/edit?usp=sharing
In order to de-duplicate work, this iterator will not actually look at everything before it. If it knows that seeds from a given chain would have already output transitions to its own position, then it won't even look at anything in that chain. This occurs in cyclic snarls.
For example, since previous chains in a cyclic snarl will have already visited all other chains, later chains do not have to visit previous ones. Similarly, when the traversal enters a cyclic snarl, it only has to handle the chains going in the opposite orientation, since the ones in the same orientation will have already seen the traversal's starting position by exiting the snarl.
| vg::ZipCodeTree::distance_iterator::distance_iterator | ( | size_t | start_index, |
| const vector< tree_item_t > & | zip_code_tree, | ||
| std::stack< size_t > | chain_numbers = std::stack<size_t>(), |
||
| bool | right_to_left = true, |
||
| size_t | distance_limit = std::numeric_limits<size_t>::max() |
||
| ) |
Make a reverse iterator starting from start_index, until the given rend, with the given distance limit.
|
private |
Decide what to do when re-entering a snarl, having already stacked up distances
|
inlineprivate |
What item does index point to?
|
private |
Check stack depth.
|
inline |
Is the iteration done?
|
private |
Duplicate the top item on the stack.
|
inlineprivate |
|
inlineprivate |
Check if the current symbol is an entrance/exit, based on the direction the iterator is going (right_to_left)
|
inlineprivate |
|
inlineprivate |
|
private |
Stop parsing because nothing else can be below the distance limit. This moves the current iterator it.
|
private |
Decide what to do right after entering a new chain. This chain's distance should be on top of the stack.
|
private |
Decide what to do right after entering a new snarl. Return whether the initialization was successful, i.e. whether the snarl was a non-root snarl.
|
inline |
Move index in right_to_left direction.
|
inline |
Compare for inequality.
| auto vg::ZipCodeTree::distance_iterator::operator* | ( | ) | const |
Get the index and orientation of the seed we are currently at, and the distance to it. Automatically handles orientation depending on right_to_left
| auto vg::ZipCodeTree::distance_iterator::operator++ | ( | ) |
Move in right_to_left direction until we hit another seed or the end.
|
inline |
Compare for equality to see if we hit end This just trusts that the two iterators are for the same tree
|
private |
Pop a value from the stack and return it.
|
private |
Push a value to the stack.
|
private |
Skip the current chain, jumping to the matching end and then one past it to continue the snarl Bound pair index should be right below current distance
|
private |
Helper for stack_snarl_distances() Stack a single value below the running distance
|
private |
Helper for stack_snarl_distances() Stack a single value from a triangular distance matrix
|
private |
Push distances relevant to a given chain onto the stack chain_num is one-indexed, so the first chain is 1, and the last is N right_side indicates if distances exit from the right or left side
|
inlineprivate |
Adopt a new state.
|
private |
Reverse the top two elements of the stack.
|
private |
Tick the automaton, looking at the symbol at *it and updating the stack and current_state. Returns true to yield a value at the current symbol, or to halt, and false otherwise.
|
private |
Get a mutable reference to the value on top of the stack.
|
private |
Throw a domain_error that the current state/symbol combo is unimplemented.
|
private |
Within each parent snarl, which chain are we in?
|
private |
Current state of the automaton.
|
private |
Distance limit we will go up to.
|
private |
Where we have to stop.
|
private |
Where we are in the stored tree.
|
private |
Where we started from.
|
private |
Original direction.
|
private |
Whether we are looking right to left (true) or left to right (false)
|
private |
Stack for computing distances.
|
private |
References to the zip code tree to let us look up distance matrices.
1.8.17