pub struct GraphInterface<'a> { /* private fields */ }Expand description
Database query interface.
This structure stores prepared statements for accessing the graph.
§Examples
use gbz_base::{GBZBase, GraphInterface};
use gbz::{Orientation, 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("graph-interface");
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();
// The example graph does not have a reference samples tag.
assert!(interface.get_gbwt_tag("reference_samples").unwrap().is_none());
// Node 21 with edges to 22 and 23, all in forward orientation.
let id = 21;
let orientation = Orientation::Forward;
let handle = support::encode_node(id, orientation);
let record = interface.get_record(handle).unwrap().unwrap();
assert_eq!(record.id(), id);
assert_eq!(record.orientation(), orientation);
let successors: Vec<usize> = record.successors().collect();
assert_eq!(
successors,
vec![
support::encode_node(22, Orientation::Forward),
support::encode_node(23, Orientation::Forward)
]
);
// Reference path for contig B goes from 21 to 22.
let path_name = FullPathName::generic("B");
let path = interface.find_path(&path_name).unwrap().unwrap();
assert_eq!(path.fw_start.node, handle);
let next = record.to_gbwt_record().lf(path.fw_start.offset).unwrap();
assert_eq!(next.node, support::encode_node(22, Orientation::Forward));
// The first indexed position is at the start of the path.
assert!(path.is_indexed);
let indexed_pos = interface.indexed_position(path.handle, 3).unwrap().unwrap();
assert_eq!(indexed_pos, (0, path.fw_start));
// Clean up.
drop(interface);
drop(database);
fs::remove_file(&db_file).unwrap();Implementations§
Source§impl<'a> GraphInterface<'a>
impl<'a> GraphInterface<'a>
Sourcepub fn new(database: &'a GBZBase) -> Result<Self, String>
pub fn new(database: &'a GBZBase) -> Result<Self, String>
Returns a new interface to the given database.
Passes through any database errors.
Returns all GBWT tags.
Returns all GBZ tags.
Sourcepub fn graph_name(&mut self) -> Result<GraphName, String>
pub fn graph_name(&mut self) -> Result<GraphName, String>
Returns the stable graph name (pggname) for the graph.
Passes through any database errors. Returns an empty name if the corresponding GBZ tags cannot be parsed.
Sourcepub fn get_record(&mut self, handle: usize) -> Result<Option<GBZRecord>, String>
pub fn get_record(&mut self, handle: usize) -> Result<Option<GBZRecord>, String>
Returns the node record for the given handle, or None if the node does not exist.
Sourcepub fn get_path(&mut self, handle: usize) -> Result<Option<GBZPath>, String>
pub fn get_path(&mut self, handle: usize) -> Result<Option<GBZPath>, String>
Returns the path with the given handle, or None if the path does not exist.
Sourcepub fn find_path(
&mut self,
name: &FullPathName,
) -> Result<Option<GBZPath>, String>
pub fn find_path( &mut self, name: &FullPathName, ) -> Result<Option<GBZPath>, String>
Returns the path with the given name, or None if the path does not exist.
The fragment field is assumed to be an offset in the haplotype. If the haplotype is fragmented, this returns the last fragment starting at or before the given offset.