Skip to main content

GraphInterface

Struct GraphInterface 

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

Source

pub fn new(database: &'a GBZBase) -> Result<Self, String>

Returns a new interface to the given database.

Passes through any database errors.

Source

pub fn get_gbwt_tag(&mut self, key: &str) -> Result<Option<String>, String>

Returns the value of the GBWT tag with the given key, or None if the tag does not exist.

Source

pub fn get_gbz_tag(&mut self, key: &str) -> Result<Option<String>, String>

Returns the value of the GBZ tag with the given key, or None if the tag does not exist.

Source

pub fn get_gbwt_tags(&mut self) -> Result<Tags, String>

Returns all GBWT tags.

Source

pub fn get_gbz_tags(&mut self) -> Result<Tags, String>

Returns all GBZ tags.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn paths_for_sample( &mut self, sample_name: &str, ) -> Result<Vec<GBZPath>, String>

Returns all paths with the given sample name.

Source

pub fn indexed_position( &mut self, path_handle: usize, path_offset: usize, ) -> Result<Option<(usize, Pos)>, String>

Returns the last indexed position at or before offset path_offset on path path_handle.

Returns None if the path does not exist or it has not been indexed.

Trait Implementations§

Source§

impl<'a> Debug for GraphInterface<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for GraphInterface<'a>

§

impl<'a> !RefUnwindSafe for GraphInterface<'a>

§

impl<'a> !Send for GraphInterface<'a>

§

impl<'a> !Sync for GraphInterface<'a>

§

impl<'a> Unpin for GraphInterface<'a>

§

impl<'a> UnsafeUnpin for GraphInterface<'a>

§

impl<'a> !UnwindSafe for GraphInterface<'a>

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> 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, 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.