pub struct BaseGraph<V: BaseVertex + Hash, E: BaseEdge> {
pub graph: StableDiGraph<V, E>,
/* private fields */
}Expand description
Common code for graphs used for local assembly.
Fields§
§graph: StableDiGraph<V, E>Implementations§
Source§impl<V: BaseVertex + Hash, E: BaseEdge> BaseGraph<V, E>
impl<V: BaseVertex + Hash, E: BaseEdge> BaseGraph<V, E>
pub fn new(kmer_size: usize) -> BaseGraph<V, E>
Sourcepub fn to_sequence_graph(&self) -> SeqGraph<BaseEdgeStruct>
pub fn to_sequence_graph(&self) -> SeqGraph<BaseEdgeStruct>
Convert this kmer graph to a simple sequence graph.
Each kmer suffix shows up as a distinct SeqVertex, attached in the same structure as in the kmer graph. Nodes that are sources are mapped to SeqVertex nodes that contain all of their sequence
@return a newly allocated SequenceGraph
pub fn vertex_set(&self) -> HashSet<&V>
pub fn edge_set(&self) -> HashSet<&E>
pub fn edges_directed( &self, node: NodeIndex, direction: Direction, ) -> Vec<EdgeIndex>
Sourcepub fn contains_all_vertices<'a, I: IntoIterator<Item = &'a NodeIndex>>(
&self,
nodes: I,
) -> bool
pub fn contains_all_vertices<'a, I: IntoIterator<Item = &'a NodeIndex>>( &self, nodes: I, ) -> bool
Checks whether the graph contains all the vertices in a collection.
@param vertices the vertices to check. Must not be null and must not contain a null.
@throws IllegalArgumentException if {@code vertices} is {@code null}.
@return {@code true} if all the vertices in the input collection are present in this graph. Also if the input collection is empty. Otherwise it returns {@code false}.
pub fn contains_edge(&self, edge: EdgeIndex) -> bool
pub fn get_kmer_size(&self) -> usize
Sourcepub fn is_reference_node(&self, vertex_index: NodeIndex) -> bool
pub fn is_reference_node(&self, vertex_index: NodeIndex) -> bool
@param v the vertex to test @return true if this vertex is a reference node (meaning that it appears on the reference path in the graph)
Sourcepub fn is_source(&self, vertex_index: NodeIndex) -> bool
pub fn is_source(&self, vertex_index: NodeIndex) -> bool
@param v the vertex to test @return true if this vertex is a source node (in degree == 0)
Sourcepub fn is_sink(&self, veretex_index: NodeIndex) -> bool
pub fn is_sink(&self, veretex_index: NodeIndex) -> bool
@param v the vertex to test @return true if this vertex is a sink node (out degree == 0)
Sourcepub fn in_degree_of(&self, vertex_index: NodeIndex) -> usize
pub fn in_degree_of(&self, vertex_index: NodeIndex) -> usize
@param v the vertex to test @return number of incoming edges
Sourcepub fn out_degree_of(&self, vertex_index: NodeIndex) -> usize
pub fn out_degree_of(&self, vertex_index: NodeIndex) -> usize
@param v the vertex to test @return number of outgoing edges
Sourcepub fn get_sources(&self) -> VecDeque<NodeIndex>
pub fn get_sources(&self) -> VecDeque<NodeIndex>
Get the set of source vertices of this graph NOTE: We return a BTreeSet here in order to preserve the determinism in the output order of VertexSet(), which is deterministic in output due to the underlying sets all being BTreeSet @return a non-null set
pub fn get_sources_generic(&self) -> Externals<'_, V, Directed, u32>
Sourcepub fn get_sinks(&self) -> BinaryHeap<NodeIndex>
pub fn get_sinks(&self) -> BinaryHeap<NodeIndex>
Get the set of sink vertices of this graph NOTE: We return a BTreeSet here in order to preserve the determinism in the output order of VertexSet(), which is deterministic in output due to the underlying sets all being BTreeSet @return a non-null set
pub fn get_sinks_generic(&self) -> Externals<'_, V, Directed, u32>
pub fn compare_paths(&self, first_path: &Path, second_path: &Path) -> Ordering
Sourcepub fn incoming_vertices_of(&self, v: NodeIndex) -> LinkedHashSet<NodeIndex>
pub fn incoming_vertices_of(&self, v: NodeIndex) -> LinkedHashSet<NodeIndex>
Get the set of vertices connected to v by incoming edges NOTE: We return a HashSet here in order to preserve the determinism in the output order of VertexSet(), which is deterministic in output due to the underlying sets all being HashSets. @param v a non-null vertex @return a set of vertices {X} connected X -> v
Sourcepub fn outgoing_vertices_of(&self, v: NodeIndex) -> LinkedHashSet<NodeIndex>
pub fn outgoing_vertices_of(&self, v: NodeIndex) -> LinkedHashSet<NodeIndex>
Get the set of vertices connected to v by outgoing edges NOTE: We return a HashSet here in order to preserve the determinism in the output order of VertexSet(), which is deterministic in output due to the underlying sets all being HashSets. @param v a non-null vertex @return a set of vertices {X} connected X -> v
Sourcepub fn incoming_edge_of(&self, v: NodeIndex) -> Option<EdgeIndex>
pub fn incoming_edge_of(&self, v: NodeIndex) -> Option<EdgeIndex>
Get the incoming edge of v. Requires that there be only one such edge or throws an error @param v our vertex @return the single incoming edge to v, or null if none exists
Sourcepub fn outgoing_edge_of(&self, v: NodeIndex) -> Option<EdgeIndex>
pub fn outgoing_edge_of(&self, v: NodeIndex) -> Option<EdgeIndex>
Get the incoming edge of v. Requires that there be only one such edge or throws an error @param v our vertex @return the single incoming edge to v, or null if none exists
pub fn get_edge_target(&self, edge: EdgeIndex) -> NodeIndex
pub fn get_edge_source(&self, edge: EdgeIndex) -> NodeIndex
pub fn edge_is_ref(&self, edge: EdgeIndex) -> bool
Sourcepub fn remove_all_vertices<'a, I>(&'a mut self, vertices: I)where
I: IntoIterator<Item = &'a NodeIndex>,
pub fn remove_all_vertices<'a, I>(&'a mut self, vertices: I)where
I: IntoIterator<Item = &'a NodeIndex>,
Removes all provided vertices from the graph
Sourcepub fn remove_all_edges<'a, I>(&'a mut self, edges: I)where
I: IntoIterator<Item = &'a EdgeIndex>,
pub fn remove_all_edges<'a, I>(&'a mut self, edges: I)where
I: IntoIterator<Item = &'a EdgeIndex>,
Removes all provided edges from the graph
Sourcepub fn is_ref_source(&self, v: NodeIndex) -> bool
pub fn is_ref_source(&self, v: NodeIndex) -> bool
@param v the vertex to test @return true if this vertex is a reference source
Sourcepub fn is_ref_sink(&self, v: NodeIndex) -> bool
pub fn is_ref_sink(&self, v: NodeIndex) -> bool
@param v the vertex to test @return true if this vertex is a reference source
Sourcepub fn remove_singleton_orphan_vertices(&mut self)
pub fn remove_singleton_orphan_vertices(&mut self)
Remove all vertices in the graph that have in and out degree of 0
Sourcepub fn get_reference_source_vertex(&self) -> Option<NodeIndex>
pub fn get_reference_source_vertex(&self) -> Option<NodeIndex>
@return the reference source vertex pulled from the graph, can be None if it doesn’t exist in the graph
Sourcepub fn get_reference_sink_vertex(&self) -> Option<NodeIndex>
pub fn get_reference_sink_vertex(&self) -> Option<NodeIndex>
@return the reference sink vertex pulled from the graph, can be None if it doesn’t exist in the graph
Sourcepub fn get_next_reference_vertex(
&self,
v: Option<NodeIndex>,
allow_non_ref_paths: bool,
blacklisted_edge: Option<EdgeIndex>,
) -> Option<NodeIndex>
pub fn get_next_reference_vertex( &self, v: Option<NodeIndex>, allow_non_ref_paths: bool, blacklisted_edge: Option<EdgeIndex>, ) -> Option<NodeIndex>
Traverse the graph and get the next reference vertex if it exists @param v the current vertex, can be null @param allowNonRefPaths if true, allow sub-paths that are non-reference if there is only a single outgoing edge @param blacklistedEdge optional edge to ignore in the traversal down; useful to exclude the non-reference dangling paths @return the next vertex (but not necessarily on the reference path if allowNonRefPaths is true) if it exists, otherwise null
Sourcepub fn get_prev_reference_vertex(
&self,
v: Option<NodeIndex>,
) -> Option<NodeIndex>
pub fn get_prev_reference_vertex( &self, v: Option<NodeIndex>, ) -> Option<NodeIndex>
Traverse the graph and get the previous reference vertex if it exists @param v the current vertex, can be null @return the previous reference vertex if it exists or null otherwise.
Sourcepub fn print_graph(
&self,
destination: &str,
write_header: bool,
prune_factor: usize,
)
pub fn print_graph( &self, destination: &str, write_header: bool, prune_factor: usize, )
Print out the graph in the dot language for visualization @param destination File to write to
Sourcepub fn get_additional_sequence<'a>(
&self,
index: NodeIndex,
v: &'a V,
) -> &'a [u8] ⓘ
pub fn get_additional_sequence<'a>( &self, index: NodeIndex, v: &'a V, ) -> &'a [u8] ⓘ
Pull out the additional sequence implied by traversing this node in the graph @param v the vertex from which to pull out the additional base sequence @return non-null byte array
pub fn get_sequence_from_index<'a>(&'a self, index: NodeIndex) -> &'a [u8] ⓘ
Sourcepub fn subset_to_neighbours(
&self,
target: NodeIndex,
distance: usize,
) -> BaseGraph<V, E>
pub fn subset_to_neighbours( &self, target: NodeIndex, distance: usize, ) -> BaseGraph<V, E>
Get a graph containing only the vertices within distance edges of target @param target a vertex in graph @param distance the max distance @return a non-null graph
Sourcepub fn has_cycles(&self) -> bool
pub fn has_cycles(&self) -> bool
Checks for the presence of directed cycles in the graph.
@return {@code true} if the graph has cycles, {@code false} otherwise.
Sourcepub fn remove_paths_not_connected_to_ref(&mut self)
pub fn remove_paths_not_connected_to_ref(&mut self)
Remove all vertices in the graph that aren’t on a path from the reference source vertex to the reference sink vertex
More aggressive reference pruning algorithm than removeVerticesNotConnectedToRefRegardlessOfEdgeDirection, as it requires vertices to not only be connected by a series of directed edges but also prunes away paths that do not also meet eventually with the reference sink vertex
Sourcepub fn clean_non_ref_paths(&mut self)
pub fn clean_non_ref_paths(&mut self)
Remove edges that are connected before the reference source and after the reference sink
Also removes all vertices that are orphaned by this process
Sourcepub fn remove_vertices_not_connected_to_ref_regardless_of_edge_direction(
&mut self,
)
pub fn remove_vertices_not_connected_to_ref_regardless_of_edge_direction( &mut self, )
Remove all vertices on the graph that cannot be accessed by following any edge, regardless of its direction, from the reference source vertex
Sourcepub fn get_reference_bytes(
&self,
from_vertex: NodeIndex,
to_vertex: Option<NodeIndex>,
include_start: bool,
include_stop: bool,
) -> Vec<u8> ⓘ
pub fn get_reference_bytes( &self, from_vertex: NodeIndex, to_vertex: Option<NodeIndex>, include_start: bool, include_stop: bool, ) -> Vec<u8> ⓘ
Walk along the reference path in the graph and pull out the corresponding bases @param fromVertex starting vertex @param toVertex ending vertex @param includeStart should the starting vertex be included in the path @param includeStop should the ending vertex be included in the path @return byte[] array holding the reference bases, this can be null if there are no nodes between the starting and ending vertex (insertions for example)
pub fn add_vertices<'a, I>(&mut self, vertices: I) -> Vec<NodeIndex>
pub fn add_edges( &mut self, start: NodeIndex, remaining: Vec<NodeIndex>, template: E, )
Sourcepub fn get_node_weights(&self, node_indices: &Vec<NodeIndex>) -> Vec<Option<&V>>
pub fn get_node_weights(&self, node_indices: &Vec<NodeIndex>) -> Vec<Option<&V>>
Gets all node weights in vector of node indices. Returns a vector of Options pointing to references
Sourcepub fn graph_equals(&self, other: &Self) -> bool
pub fn graph_equals(&self, other: &Self) -> bool
Semi-lenient comparison of two graphs, truing true if g1 and g2 have similar structure
By similar this means that both graphs have the same number of vertices, where each vertex can find a vertex in the other graph that’s seqEqual to it. A similar constraint applies to the edges, where all edges in g1 must have a corresponding edge in g2 where both source and target vertices are seqEqual
@param g1 the first graph to compare
@param g2 the second graph to compare
@param
Sourcepub fn add_node(&mut self, v: &V) -> NodeIndex
pub fn add_node(&mut self, v: &V) -> NodeIndex
Add nodes to the graph, if the node is already present in the graph then retrieve and return its current index. Use this instead of petgraph’s usual add_node as we do not want to be able have identical nodes especially when dealing with k-mers Returns the NodeIndex of the provided vertex/node
Sourcepub fn add_or_update_edge(&mut self, source: NodeIndex, target: NodeIndex, e: E)
pub fn add_or_update_edge(&mut self, source: NodeIndex, target: NodeIndex, e: E)
Add edge between source -> target if none exists, or add e to an already existing one if present
@param source source vertex @param target vertex @param e edge to add
Sourcepub fn index_from_vertex(&self, v: &V) -> Option<NodeIndex>
pub fn index_from_vertex(&self, v: &V) -> Option<NodeIndex>
Returns the index of a given node if it is found in the graph. None if not found.
Trait Implementations§
impl<V: BaseVertex + Hash, E: BaseEdge> Eq for BaseGraph<V, E>
Auto Trait Implementations§
impl<V, E> Freeze for BaseGraph<V, E>
impl<V, E> RefUnwindSafe for BaseGraph<V, E>where
V: RefUnwindSafe,
E: RefUnwindSafe,
impl<V, E> Send for BaseGraph<V, E>
impl<V, E> Sync for BaseGraph<V, E>
impl<V, E> Unpin for BaseGraph<V, E>
impl<V, E> UnwindSafe for BaseGraph<V, E>where
V: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.