pub struct Subgraph { /* private fields */ }Expand description
A subgraph induced by a set of node identifiers.
The subgraph contains the specified nodes and the edges between them.
Paths in the current subgraph can be extracted using Subgraph::extract_paths.
Only the provided reference path will have proper metadata.
Other paths remain anonymous, as we cannot identify them efficiently using the GBWT.
Any changes to the subgraph will remove the extracted paths.
When a subgraph is changed, the operations will try to reuse already extracted node records.
This makes it viable as a sliding window over a reference path.
Node identifiers can be selected using:
Subgraph::add_node_from_gbz,Subgraph::add_node_from_db, andSubgraph::remove_nodewith individual ids.Subgraph::around_positionfor a context around a graph position.Subgraph::around_intervalfor a context around path interval.Subgraph::around_nodesfor a context around a set of nodes.Subgraph::between_nodesfor all nodes and snarls in an interval of a chain.Subgraph::extract_snarlsto include all nodes in top-level snarls with boundary nodes in the current subgraph.
Subgraph::from_gbz and Subgraph::from_db are integrated methods for extracting a subgraph with paths using a SubgraphQuery.
Subgraph implements a similar graph interface to the node/edge operations of GBZ.
It can also be serialized in GFA and JSON formats using Subgraph::write_gfa and Subgraph::write_json.
Subgraph also implements Graph from the pggname.
That enables computing stable graph names using pggname::stable_name.
§Examples
The following example replicates an offset-based Subgraph::from_gbz query using lower-level functions.
It also demonstrates some parts of the graph interface in the subgraph object.
use gbz_base::{GBZRecord, GraphReference, PathIndex, Subgraph, HaplotypeOutput};
use gbz::{GBZ, FullPathName, Orientation};
use gbz::support;
use simple_sds::serialize;
// Get the graph.
let gbz_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&gbz_file).unwrap();
// Create a path index with 3 bp intervals.
let path_index = PathIndex::new(&graph, 3, false).unwrap();
// Find the position for path A offset 2.
let mut query_pos = FullPathName::generic("A");
query_pos.fragment = 2;
let mut subgraph = Subgraph::new();
let result = subgraph.path_pos_from_gbz(&graph, &path_index, &query_pos);
assert!(result.is_ok());
let (path_pos, path_name) = result.unwrap();
// Extract a 1 bp context around the position.
let result = subgraph.around_position(GraphReference::Gbz(&graph), path_pos.graph_pos(), 1);
assert!(result.is_ok());
// Extract all paths in the subgraph.
let result = subgraph.extract_paths(Some((path_pos, path_name)), HaplotypeOutput::All);
assert!(result.is_ok());
// Compute the stable name of the subgraph with no parent graph.
subgraph.compute_name(None);
assert!(subgraph.has_graph_name());
// The subgraph should be centered around 1 bp node 14 of degree 4.
let nodes = [12, 13, 14, 15, 16];
assert_eq!(subgraph.nodes(), nodes.len());
assert!(subgraph.node_iter().eq(nodes.iter().copied()));
assert_eq!(subgraph.paths(), 3);
// The result is a subgraph induced by the nodes.
for &node_id in nodes.iter() {
assert!(subgraph.has_node(node_id));
assert_eq!(subgraph.sequence(node_id), graph.sequence(node_id));
for orientation in [Orientation::Forward, Orientation::Reverse] {
// Successors are present if they are in the subgraph.
let sub_succ = subgraph.successors(node_id, orientation).unwrap();
let graph_succ = graph.successors(node_id, orientation).unwrap();
assert!(sub_succ.eq(graph_succ.filter(|(id, _)| nodes.contains(id))));
// And the same applies to predecessors.
let sub_pred = subgraph.predecessors(node_id, orientation).unwrap();
let graph_pred = graph.predecessors(node_id, orientation).unwrap();
assert!(sub_pred.eq(graph_pred.filter(|(id, _)| nodes.contains(id))));
}
}Implementations§
Source§impl Subgraph
Construction.
impl Subgraph
Construction.
Sourcepub fn path_pos_from_gbz(
&mut self,
graph: &GBZ,
path_index: &PathIndex,
query_pos: &FullPathName,
) -> Result<(PathPosition, FullPathName), String>
pub fn path_pos_from_gbz( &mut self, graph: &GBZ, path_index: &PathIndex, query_pos: &FullPathName, ) -> Result<(PathPosition, FullPathName), String>
Returns the path position for the haplotype offset represented by the query position.
query_pos.fragment is used as an offset in the haplotype.
The return value consists of the position and metadata for the path covering the position.
Updates the subgraph to include the path from the nearest indexed position to the query position.
§Arguments
graph: A GBZ graph.path_index: A path index for the graph.query_pos: Query position.
§Errors
Returns an error if there is no path covering the given position or the path has not been indexed for random access.
§Examples
use gbz_base::{GBZRecord, Subgraph, GraphReference, PathIndex};
use gbz::{GBZ, FullPathName, Orientation};
use gbz::support;
use simple_sds::serialize;
// Get the graph.
let gbz_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&gbz_file).unwrap();
// Create a path index with 3 bp intervals.
let path_index = PathIndex::new(&graph, 3, false).unwrap();
// Query for path A offset 2.
let mut query_pos = FullPathName::generic("A");
query_pos.fragment = 2;
let mut subgraph = Subgraph::new();
let result = subgraph.path_pos_from_gbz(&graph, &path_index, &query_pos);
assert!(result.is_ok());
let (path_pos, path_name) = result.unwrap();
assert_eq!(path_pos.seq_offset(), query_pos.fragment);
// The query position is at the start of node 14 in forward orientation.
assert_eq!(path_pos.node_id(), 14);
assert_eq!(path_pos.orientation(), Orientation::Forward);
assert_eq!(path_pos.node_offset(), 0);
// And this happens to be the first path visit to the node.
let gbwt_node = support::encode_node(14, Orientation::Forward);
assert_eq!(path_pos.handle(), gbwt_node);
assert_eq!(path_pos.gbwt_offset(), 0);
// And it is covered by the path fragment starting from offset 0.
assert_eq!(path_name, FullPathName::generic("A"));
// Now extract 1 bp context around interval 2..4.
let result = subgraph.around_interval(GraphReference::Gbz(&graph), path_pos, 2, 1);
assert!(result.is_ok());
// The interval corresponds to nodes 14 and 15.
let true_nodes = vec![12, 13, 14, 15, 16, 17];
assert_eq!(subgraph.nodes(), true_nodes.len());
assert!(subgraph.node_iter().eq(true_nodes.iter().copied()));Sourcepub fn path_pos_from_db<'reference, 'graph>(
&mut self,
graph: &'reference mut GraphInterface<'graph>,
query_pos: &FullPathName,
) -> Result<(PathPosition, FullPathName), String>
pub fn path_pos_from_db<'reference, 'graph>( &mut self, graph: &'reference mut GraphInterface<'graph>, query_pos: &FullPathName, ) -> Result<(PathPosition, FullPathName), String>
Returns the path position for the haplotype offset represented by the query position.
query_pos.fragment is used as an offset in the haplotype.
The return value consists of the position and metadata for the path covering the position.
Updates the subgraph to include the path from the nearest indexed position to the query position.
§Arguments
graph: A graph interface.query_pos: Query position.
§Errors
Returns an error if database operations fail. Returns an error if there is no path covering the given position or the path has not been indexed for random access.
§Examples
use gbz_base::{GBZBase, GraphInterface, Subgraph};
use gbz::{FullPathName, Orientation};
use gbz::support;
use simple_sds::serialize;
use std::fs;
// Create the database.
let gbz_file = support::get_test_data("example.gbz");
let db_file = serialize::temp_file_name("subgraph");
let result = GBZBase::create_from_files(&gbz_file, None, &db_file);
assert!(result.is_ok());
// Open the database and create a graph interface.
let database = GBZBase::open(&db_file).unwrap();
let mut interface = GraphInterface::new(&database).unwrap();
// Query for path A offset 2.
let mut query_pos = FullPathName::generic("A");
query_pos.fragment = 2;
let mut subgraph = Subgraph::new();
let result = subgraph.path_pos_from_db(&mut interface, &query_pos);
assert!(result.is_ok());
let (path_pos, path_name) = result.unwrap();
assert_eq!(path_pos.seq_offset(), query_pos.fragment);
// The query position is at the start of node 14 in forward orientation.
assert_eq!(path_pos.node_id(), 14);
assert_eq!(path_pos.orientation(), Orientation::Forward);
assert_eq!(path_pos.node_offset(), 0);
// And this happens to be the first path visit to the node.
let gbwt_node = support::encode_node(14, Orientation::Forward);
assert_eq!(path_pos.handle(), gbwt_node);
assert_eq!(path_pos.gbwt_offset(), 0);
// And it is covered by the path fragment starting from offset 0.
assert_eq!(path_name, FullPathName::generic("A"));
// Clean up.
drop(interface);
drop(database);
fs::remove_file(&db_file).unwrap();Sourcepub fn around_position(
&mut self,
graph: GraphReference<'_, '_>,
pos: GraphPosition,
context: usize,
) -> Result<(usize, usize), String>
pub fn around_position( &mut self, graph: GraphReference<'_, '_>, pos: GraphPosition, context: usize, ) -> Result<(usize, usize), String>
Updates the subgraph to a context around the given graph position.
Reuses existing records when possible.
Removes node records outside the context as well as all path information.
Returns the number of inserted and removed nodes.
See Subgraph for an example.
§Arguments
graph: A GBZ-compatible graph.pos: The reference position for the subgraph.context: The context length around the reference position (in bp).
§Errors
Passes through any errors from accessing the graph.
Sourcepub fn around_interval(
&mut self,
graph: GraphReference<'_, '_>,
start_pos: PathPosition,
len: usize,
context: usize,
) -> Result<(usize, usize), String>
pub fn around_interval( &mut self, graph: GraphReference<'_, '_>, start_pos: PathPosition, len: usize, context: usize, ) -> Result<(usize, usize), String>
Updates the subgraph to a context around the given path interval.
Reuses existing records when possible.
Removes node records outside the context as well as all path information.
Returns the number of inserted and removed nodes.
See Self::path_pos_from_gbz for an example.
§Arguments
graph: A GBZ-compatible graph.start_pos: The starting position for the interval.len: Length of the interval (in bp).context: The context length around the reference interval (in bp).
§Errors
Passes through any errors from accessing the graph. Returns an error if the interval is empty, starts outside the initial node, or is longer than the remaining path.
Sourcepub fn around_nodes(
&mut self,
graph: GraphReference<'_, '_>,
nodes: &BTreeSet<usize>,
context: usize,
) -> Result<(usize, usize), String>
pub fn around_nodes( &mut self, graph: GraphReference<'_, '_>, nodes: &BTreeSet<usize>, context: usize, ) -> Result<(usize, usize), String>
Updates the subgraph to a context around the given nodes.
Reuses existing records when possible. Removes node records outside the context as well as all path information. Returns the number of inserted and removed nodes.
§Arguments
graph: A GBZ-compatible graph.nodes: Set of reference nodes for the subgraph.context: The context length around the reference node (in bp).
§Errors
Passes through any errors from accessing the graph.
§Examples
use gbz_base::{GBZRecord, Subgraph, GraphReference};
use gbz::GBZ;
use gbz::support;
use simple_sds::serialize;
use std::collections::BTreeSet;
// Get the graph.
let gbz_file = support::get_test_data("translation.gbz");
let graph: GBZ = serialize::load_from(&gbz_file).unwrap();
// Extract a subgraph that contains an 1 bp context around node 5.
let mut subgraph = Subgraph::new();
let mut nodes = BTreeSet::new();
nodes.insert(5);
let result = subgraph.around_nodes(GraphReference::Gbz(&graph), &nodes, 1);
assert!(result.is_ok());
// The subgraph should be centered around 2 bp node 5 of degree 3.
let true_nodes = [3, 4, 5, 6];
assert_eq!(subgraph.nodes(), true_nodes.len());
assert!(subgraph.node_iter().eq(true_nodes.iter().copied()));
// But there are no paths.
assert_eq!(subgraph.paths(), 0);Sourcepub fn between_nodes(
&mut self,
graph: GraphReference<'_, '_>,
start: usize,
end: usize,
limit: Option<usize>,
) -> Result<usize, String>
pub fn between_nodes( &mut self, graph: GraphReference<'_, '_>, start: usize, end: usize, limit: Option<usize>, ) -> Result<usize, String>
Inserts all nodes between the given two handles into the subgraph.
If start and end are in the same chain in the given order, this will insert all nodes and snarls between them.
Otherwise the behavior will be unpredictable and it is recommended to set a safety limit to avoid excessive memory usage.
Removes all path information.
Returns the number of inserted nodes.
§Arguments
graph: A GBZ-compatible graph.start: Start handle (inclusive).end: End handle (inclusive).limit: Optional safety limit on the number of inserted nodes.
§Examples
use gbz_base::{GBZRecord, Subgraph, GraphReference};
use gbz::{GBZ, Orientation};
use gbz::support;
use simple_sds::serialize;
let graph_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&graph_file).unwrap();
let start = support::encode_node(14, Orientation::Forward);
let end = support::encode_node(17, Orientation::Forward);
let mut subgraph = Subgraph::new();
let result = subgraph.between_nodes(GraphReference::Gbz(&graph), start, end, None);
assert_eq!(result, Ok(4));
let expected_nodes = [14, 15, 16, 17];
assert!(subgraph.node_iter().eq(expected_nodes.iter().copied()));Sourcepub fn extract_snarls(
&mut self,
graph: GraphReference<'_, '_>,
chains: Option<&Chains>,
) -> Result<usize, String>
pub fn extract_snarls( &mut self, graph: GraphReference<'_, '_>, chains: Option<&Chains>, ) -> Result<usize, String>
Extracts nodes in top-level snarls covered by the current subgraph.
Returns the number of inserted nodes.
Removes all path information.
If a chains are provided, this will use them for determining the top-level snarls.
Otherwise the links stored in node records are used.
Note that chains must be always provided when the subgraph has been extracted from a GBZ graph.
§Errors
Returns an error if the graph reference is GraphReference::None.
Passes through errors from accessing the graph.
§Examples
use gbz::{GBZ, Orientation};
use gbz::support::{self, Chains};
use gbz_base::{Subgraph, GraphReference};
use gbz_base::utils;
use simple_sds::serialize;
use std::collections::BTreeSet;
let graph_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&graph_file).unwrap();
let chains_file = utils::get_test_data("example.chains");
let chains: Chains = serialize::load_from(&chains_file).unwrap();
// Extract the boundary nodes of a snarl as the initial subgraph.
let mut subgraph = Subgraph::new();
let nodes: BTreeSet<usize> = [14, 17].into_iter().collect();
let result = subgraph.around_nodes(GraphReference::Gbz(&graph), &nodes, 0);
assert!(result.is_ok());
assert!(subgraph.node_iter().eq(nodes.iter().copied()));
// Now extract the snarl between the boundary nodes.
let result = subgraph.extract_snarls(GraphReference::Gbz(&graph), Some(&chains));
assert!(result.is_ok());
let snarl_nodes = [14, 15, 16, 17];
assert!(subgraph.node_iter().eq(snarl_nodes.iter().copied()));Sourcepub fn from_gbz(
&mut self,
graph: &GBZ,
path_index: Option<&PathIndex>,
chains: Option<&Chains>,
query: &SubgraphQuery,
) -> Result<(), String>
pub fn from_gbz( &mut self, graph: &GBZ, path_index: Option<&PathIndex>, chains: Option<&Chains>, query: &SubgraphQuery, ) -> Result<(), String>
Extracts a subgraph around the given query position.
Reuses existing records when possible. Removes node records not covered by the query.
§Arguments
graph: A GBZ graph.path_index: A path index for the graph, if the query is path-based.chains: A set of top-level chains, if the query extracts nodes in covered snarls.query: Arguments for extracting the subgraph.
§Errors
Returns an error, if:
- The query or the graph is invalid.
- The graph does not contain the queried position.
- A path index is required but not provided, or if the query path has not been indexed.
If an error occurs, the subgraph may contain arbitrary nodes but no paths.
§Examples
use gbz_base::{PathIndex, Subgraph, SubgraphQuery, HaplotypeOutput};
use gbz::{GBZ, FullPathName};
use gbz::support;
use simple_sds::serialize;
// Get the graph.
let gbz_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&gbz_file).unwrap();
// Create a path index with 3 bp intervals.
let path_index = PathIndex::new(&graph, 3, false).unwrap();
// Extract a subgraph that contains an 1 bp context around path A offset 2.
let path_name = FullPathName::generic("A");
let query = SubgraphQuery::path_offset(&path_name, 2).with_context(1);
let mut subgraph = Subgraph::new();
let result = subgraph.from_gbz(&graph, Some(&path_index), None, &query);
assert!(result.is_ok());
// The subgraph should be centered around 1 bp node 14 of degree 4.
assert_eq!(subgraph.nodes(), 5);
assert_eq!(subgraph.paths(), 3);
// We get the same result using a node id.
let query = SubgraphQuery::nodes([14]).with_context(1);
let mut subgraph = Subgraph::new();
let result = subgraph.from_gbz(&graph, None, None, &query);
assert!(result.is_ok());
assert_eq!(subgraph.nodes(), 5);
assert_eq!(subgraph.paths(), 3);Sourcepub fn from_db<'reference, 'graph>(
&mut self,
graph: &'reference mut GraphInterface<'graph>,
query: &SubgraphQuery,
) -> Result<(), String>
pub fn from_db<'reference, 'graph>( &mut self, graph: &'reference mut GraphInterface<'graph>, query: &SubgraphQuery, ) -> Result<(), String>
Extracts a subgraph around the given query position.
Reuses existing records when possible. Removes node records not covered by the query.
§Errors
Returns an error, if:
- The query or the graph is invalid or if there is a database error.
- The graph does not contain the queried position.
- A path index is required but not provided, or if the query path has not been indexed.
If an error occurs, the subgraph may contain arbitrary nodes but no paths.
§Examples
use gbz_base::{GBZBase, GraphInterface, Subgraph, SubgraphQuery, HaplotypeOutput};
use gbz::FullPathName;
use gbz::support;
use simple_sds::serialize;
use std::fs;
// Create the database.
let gbz_file = support::get_test_data("example.gbz");
let db_file = serialize::temp_file_name("subgraph");
let result = GBZBase::create_from_files(&gbz_file, None, &db_file);
assert!(result.is_ok());
// Open the database and create a graph interface.
let database = GBZBase::open(&db_file).unwrap();
let mut interface = GraphInterface::new(&database).unwrap();
// Extract a subgraph that contains an 1 bp context around path A offset 2.
let path_name = FullPathName::generic("A");
let query = SubgraphQuery::path_offset(&path_name, 2).with_context(1);
let mut subgraph = Subgraph::new();
let result = subgraph.from_db(&mut interface, &query);
assert!(result.is_ok());
// The subgraph should be centered around 1 bp node 14 of degree 4.
assert_eq!(subgraph.nodes(), 5);
assert_eq!(subgraph.paths(), 3);
// Clean up.
drop(interface);
drop(database);
fs::remove_file(&db_file).unwrap();Sourcepub fn extract_paths(
&mut self,
reference_path: Option<(PathPosition, FullPathName)>,
output: HaplotypeOutput,
) -> Result<(), String>
pub fn extract_paths( &mut self, reference_path: Option<(PathPosition, FullPathName)>, output: HaplotypeOutput, ) -> Result<(), String>
Extracts all paths in the subgraph.
Clears the current paths in the subgraph. If a reference path is given, one of the paths is assumed to visit the position. This will then set all information related to the reference path.
§Arguments
reference_path: Position on the reference path and the name of the path.output: How to output the haplotypes.
§Errors
Returns an error if no path visits the reference position. Returns an error if reference-only output is requested without a reference path. Clears all path information in case of an error.
§Examples
use gbz_base::{GBZRecord, Subgraph, HaplotypeOutput};
use gbz::GBZ;
use gbz::support;
use simple_sds::serialize;
// Get the graph.
let gbz_file = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&gbz_file).unwrap();
// Start with an empty subgraph and add a node.
let mut subgraph = Subgraph::new();
let result = subgraph.add_node_from_gbz(&graph,15);
assert!(result.is_ok());
// There are no paths until we extract them.
assert_eq!(subgraph.paths(), 0);
let result = subgraph.extract_paths(None, HaplotypeOutput::All);
assert!(result.is_ok());
assert_eq!(subgraph.paths(), 2);
// When we change the subgraph, we need to extract the paths again.
for node_id in [13, 14] {
let result = subgraph.add_node_from_gbz(&graph, node_id);
assert!(result.is_ok());
}
assert_eq!(subgraph.paths(), 0);
let result = subgraph.extract_paths(None, HaplotypeOutput::All);
assert!(result.is_ok());
assert_eq!(subgraph.paths(), 3);
// The same is true for removing nodes.
for node_id in [14, 15] {
subgraph.remove_node(node_id);
}
assert_eq!(subgraph.paths(), 0);
let result = subgraph.extract_paths(None, HaplotypeOutput::All);
assert!(result.is_ok());
assert_eq!(subgraph.paths(), 1);Sourcepub fn add_node_from_gbz(
&mut self,
graph: &GBZ,
node_id: usize,
) -> Result<(), String>
pub fn add_node_from_gbz( &mut self, graph: &GBZ, node_id: usize, ) -> Result<(), String>
Inserts the given node into the subgraph.
No effect if the node is already in the subgraph.
Clears all path information from the subgraph.
See also Self::add_node_from_db.
§Arguments
graph: A GBZ graph.node_id: Identifier of the node to insert.
§Errors
Returns an error if the node does not exist in the graph.
Sourcepub fn add_node_from_db(
&mut self,
graph: &mut GraphInterface<'_>,
node_id: usize,
) -> Result<(), String>
pub fn add_node_from_db( &mut self, graph: &mut GraphInterface<'_>, node_id: usize, ) -> Result<(), String>
Inserts the given node into the subgraph.
No effect if the node is already in the subgraph.
Clears all path information from the subgraph.
See also Self::add_node_from_gbz.
§Arguments
graph: Graph interface.node_id: Identifier of the node to insert.
§Errors
Returns an error if the node does not exist in the graph. Passes through any errors from the database.
Sourcepub fn remove_node(&mut self, node_id: usize)
pub fn remove_node(&mut self, node_id: usize)
Removes the given node from the subgraph.
No effect if the node is not in the subgraph. Clears all path information from the subgraph.
Source§impl Subgraph
Node/edge operations similar to GBZ.
impl Subgraph
Node/edge operations similar to GBZ.
Sourcepub fn min_handle(&self) -> Option<usize>
pub fn min_handle(&self) -> Option<usize>
Returns the smallest handle in the subgraph.
Sourcepub fn max_handle(&self) -> Option<usize>
pub fn max_handle(&self) -> Option<usize>
Returns the largest handle in the subgraph.
Sourcepub fn has_node(&self, node_id: usize) -> bool
pub fn has_node(&self, node_id: usize) -> bool
Returns true if the subgraph contains the given node.
pub fn has_handle(&self, handle: usize) -> bool
Sourcepub fn sequence_for_handle(&self, handle: usize) -> Option<&[u8]>
pub fn sequence_for_handle(&self, handle: usize) -> Option<&[u8]>
Returns the sequence for the handle in the subgraph, or None if there is no such handle.
Sourcepub fn sequence(&self, node_id: usize) -> Option<&[u8]>
pub fn sequence(&self, node_id: usize) -> Option<&[u8]>
Returns the sequence for the node in the subgraph, or None if there is no such node.
Sourcepub fn oriented_sequence(
&self,
node_id: usize,
orientation: Orientation,
) -> Option<&[u8]>
pub fn oriented_sequence( &self, node_id: usize, orientation: Orientation, ) -> Option<&[u8]>
Returns the sequence for the node in the given orientation, or None if there is no such node.
Sourcepub fn sequence_len(&self, node_id: usize) -> Option<usize>
pub fn sequence_len(&self, node_id: usize) -> Option<usize>
Returns the length of the sequence for the node in the subgraph, or None if there is no such node.
Sourcepub fn node_iter(&self) -> impl Iterator<Item = usize> + use<'_>
pub fn node_iter(&self) -> impl Iterator<Item = usize> + use<'_>
Returns an iterator over the node identifiers in the subgraph.
The identifiers are listed in ascending order.
Sourcepub fn handle_iter(&self) -> impl Iterator<Item = usize> + use<'_>
pub fn handle_iter(&self) -> impl Iterator<Item = usize> + use<'_>
Returns an iterator over the handles in the subgraph.
The handles are listed in ascending order.
Sourcepub fn successors(
&self,
node_id: usize,
orientation: Orientation,
) -> Option<EdgeIter<'_>>
pub fn successors( &self, node_id: usize, orientation: Orientation, ) -> Option<EdgeIter<'_>>
Returns an iterator over the successors of an oriented node, or None if there is no such node.
Sourcepub fn supergraph_successors(
&self,
node_id: usize,
orientation: Orientation,
) -> Option<EdgeIter<'_>>
pub fn supergraph_successors( &self, node_id: usize, orientation: Orientation, ) -> Option<EdgeIter<'_>>
Returns an iterator over the successors of an oriented node in the supergraph, or None if there is no such node.
This is otherwise the same as Self::successors, but this also lists successors not in the subgraph.
Sourcepub fn predecessors(
&self,
node_id: usize,
orientation: Orientation,
) -> Option<EdgeIter<'_>>
pub fn predecessors( &self, node_id: usize, orientation: Orientation, ) -> Option<EdgeIter<'_>>
Returns an iterator over the predecessors of an oriented node, or None if there is no such node.
Sourcepub fn supergraph_predecessors(
&self,
node_id: usize,
orientation: Orientation,
) -> Option<EdgeIter<'_>>
pub fn supergraph_predecessors( &self, node_id: usize, orientation: Orientation, ) -> Option<EdgeIter<'_>>
Returns an iterator over the predecessors of an oriented node in the supergraph, or None if there is no such node.
This is otherwise the same as Self::predecessors, but this also lists predecessors not in the subgraph.
Sourcepub fn covered_snarls(
&self,
chains: Option<&Chains>,
) -> BTreeSet<(usize, usize)>
pub fn covered_snarls( &self, chains: Option<&Chains>, ) -> BTreeSet<(usize, usize)>
Returns the top-level snarls covered by the current subgraph.
Each snarl is reported as a pair of handles (start, end) of its boundary nodes.
Here start points inside the snarl and end points outside the snarl.
The snarls are returned in the canonical orientation (see support::edge_is_canonical).
By default, this uses the chain links stored in node records.
However, a crate::GBZBase does not always store top-level chains, and a GBZ graph does not have that information.
In such cases a Chains object can be provided as an override.
Source§impl Subgraph
Output formats.
impl Subgraph
Output formats.
Source§impl Subgraph
Graph names.
impl Subgraph
Graph names.
Sourcepub fn graph_name(&self) -> Option<&GraphName>
pub fn graph_name(&self) -> Option<&GraphName>
Returns the stable graph name (pggname) for the subgraph.
Sourcepub fn has_graph_name(&self) -> bool
pub fn has_graph_name(&self) -> bool
Returns true if the subgraph has a graph name.
Sourcepub fn compute_name(&mut self, parent: Option<&GraphName>)
pub fn compute_name(&mut self, parent: Option<&GraphName>)
Computes and stores the stable graph name (pggname) for the subgraph.
If the name of the parent graph is given, this graph will be marked as its subgraph. All other graph relationships are also copied from the parent. No effect if the subgraph already has a graph name.