Skip to main content

PathIndex

Struct PathIndex 

Source
pub struct PathIndex { /* private fields */ }
Expand description

An index for random access to reference and generic paths in a GBZ graph.

Indexed paths are identified by their offsets in the index. The offsets range from 0 to path_count() - 1.

The combination of GBZ and PathIndex is functionally similar to crate::GraphInterface but tens of times faster. An in-memory graph is better for batch operations, where the loading time is a negligible fraction of the total time. The database is better for interactive applications, where the user works with relatively small subgraphs. For a human graph, the database should be faster than the in-memory graph for subgraphs of up to 1 Mbp.

§Examples

use gbz_base::PathIndex;
use gbz::{GBZ, FullPathName, Pos};
use gbz::support;
use simple_sds::serialize;

let filename = support::get_test_data("example.gbz");
let graph: GBZ = serialize::load_from(&filename).unwrap();

// Create a path index with 3 bp intervals.
let path_index = PathIndex::new(&graph, 3, false);
assert!(path_index.is_ok());
let path_index = path_index.unwrap();

// We have two components with one generic path in each.
assert_eq!(path_index.path_count(), 2);
assert_eq!(path_index.path_length(0), Some(5));
assert_eq!(path_index.path_length(1), Some(4));

// Consider the generic path in component A.
let path_name = FullPathName::generic("A");
let index_offset = path_index.find_path(&graph, &path_name);
assert_eq!(index_offset, Some(0));
let index_offset = index_offset.unwrap();

// There should be two indexed positions for the path.
let first_sample = path_index.indexed_position(index_offset, 2);
assert_eq!(first_sample, Some((0, Pos::new(22, 0))));
let second_sample = path_index.indexed_position(index_offset, 5);
assert_eq!(second_sample, Some((3, Pos::new(30, 0))));
let next_sample = path_index.indexed_position(index_offset, 100);
assert_eq!(next_sample, second_sample);

Implementations§

Source§

impl PathIndex

Source

pub fn new(graph: &GBZ, interval: usize, verbose: bool) -> Result<Self, String>

Creates a new path index for the given GBZ graph.

The index is built for all reference and generic paths.

§Arguments
  • graph: A GBZ graph.
  • interval: Approximate distance between indexed positions (in bp).
  • verbose: Print progress information to stderr.
Source

pub fn path_count(&self) -> usize

Returns the number of indexed paths.

Source

pub fn path_to_offset(&self, path_id: usize) -> Option<usize>

Returns the index offset for the indexed path with the given identifier.

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

Source

pub fn offset_to_path(&self, index_offset: usize) -> Option<usize>

Returns the path identifier for the indexed path with the given index offset.

Returns None if the path does not exist.

Source

pub fn find_path(&self, graph: &GBZ, path_name: &FullPathName) -> Option<usize>

Returns the index offset for the path with the given metadata.

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

Source

pub fn path_length(&self, index_offset: usize) -> Option<usize>

Returns the length of the indexed path with the given index offset.

Returns None if the path does not exist.

Source

pub fn indexed_position( &self, index_offset: usize, query_offset: usize, ) -> Option<(usize, Pos)>

Returns the last indexed position at or before offset on the path with name path_name.

The return value consists of a sequence offset and a GBWT position. Returns None if the path does not exist or it has not been indexed. This is similar to crate::GraphInterface::find_path followed by crate::GraphInterface::indexed_position.

§Arguments
  • index_offset: Offset of the path in the index.
  • query_offset: Sequence position in the path (in bp).

Trait Implementations§

Source§

impl Clone for PathIndex

Source§

fn clone(&self) -> PathIndex

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 PathIndex

Source§

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

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

impl PartialEq for PathIndex

Source§

fn eq(&self, other: &PathIndex) -> 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 PathIndex

Source§

impl StructuralPartialEq for PathIndex

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.