Skip to main content

Subgraph

Struct Subgraph 

Source
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::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.

Source

pub fn new() -> Self

Creates a new empty subgraph.

Source

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()));
Source

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();
Source

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.

Source

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.

Source

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);
Source

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()));
Source

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()));
Source

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);
Source

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();
Source

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);
Source

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.

Source

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.

Source

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.

Source

pub fn nodes(&self) -> usize

Returns the number of nodes in the subgraph.

Source

pub fn min_node(&self) -> Option<usize>

Returns the smallest node identifier in the subgraph.

Source

pub fn max_node(&self) -> Option<usize>

Returns the largest node identifier in the subgraph.

Source

pub fn min_handle(&self) -> Option<usize>

Returns the smallest handle in the subgraph.

Source

pub fn max_handle(&self) -> Option<usize>

Returns the largest handle in the subgraph.

Source

pub fn has_node(&self, node_id: usize) -> bool

Returns true if the subgraph contains the given node.

Source

pub fn has_handle(&self, handle: usize) -> bool

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn paths(&self) -> usize

Returns the number of paths in the subgraph.

Source

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.

Source

pub fn write_gfa<T: Write>(&self, output: &mut T, cigar: bool) -> Result<()>

Writes the subgraph in the GFA format to the given output.

The output is a full GFA file, including the header. If cigar is true, the CIGAR strings for the non-reference haplotypes are included in the output.

Source

pub fn write_json<T: Write>(&self, output: &mut T, cigar: bool) -> Result<()>

Writes the subgraph in the JSON format to the given output.

If cigar is true, the CIGAR strings for the non-reference haplotypes are included in the output.

Source§

impl Subgraph

Graph names.

Source

pub fn graph_name(&self) -> Option<&GraphName>

Returns the stable graph name (pggname) for the subgraph.

Source

pub fn has_graph_name(&self) -> bool

Returns true if the subgraph has a graph name.

Source

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.

Trait Implementations§

Source§

impl Clone for Subgraph

Source§

fn clone(&self) -> Subgraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Subgraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Subgraph

Source§

fn default() -> Subgraph

Returns the “default value” for a type. Read more
Source§

impl Graph for Subgraph

Source§

fn new() -> Self

Creates a new empty graph.
Source§

fn add_node(&mut self, _: &[u8], _: &[u8]) -> Result<(), String>

Adds a node to the graph. Read more
Source§

fn add_edge( &mut self, _: &[u8], _: Orientation, _: &[u8], _: Orientation, ) -> Result<(), String>

Adds an edge to the graph. Read more
Source§

fn finalize(&mut self) -> Result<(), String>

Finalizes the graph by sorting and deduplicating edges. Read more
Source§

fn statistics(&self) -> (usize, usize, usize)

Returns the number of nodes, the number of edges, and total sequence length in the graph.
Source§

fn node_iter(&self) -> impl Iterator<Item = Vec<u8>>

Returns an iterator over serialized nodes in sorted order.
Source§

impl PartialEq for Subgraph

Source§

fn eq(&self, other: &Subgraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Subgraph

Source§

impl StructuralPartialEq for Subgraph

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.