noodles_csi::binning_index::index::reference_sequence

Struct ReferenceSequence

Source
pub struct ReferenceSequence<I> { /* private fields */ }
Expand description

A binning index reference sequence.

Implementations§

Source§

impl<I> ReferenceSequence<I>
where I: Index,

Source

pub fn new( bins: IndexMap<usize, Bin>, index: I, metadata: Option<Metadata>, ) -> Self

Creates a binning index reference sequence.

§Examples
use noodles_csi::binning_index::index::ReferenceSequence;
let reference_sequence = ReferenceSequence::new(Default::default(), Vec::new(), None);
Source

pub fn bins(&self) -> &IndexMap<usize, Bin>

Returns the list of bins in the reference sequence.

This list does not include the metadata pseudo-bin. Use binning_index::ReferenceSequence::metadata instead.

§Examples
use noodles_csi::binning_index::index::ReferenceSequence;
let reference_sequence = ReferenceSequence::new(Default::default(), Vec::new(), None);
assert!(reference_sequence.bins().is_empty());
Source

pub fn index(&self) -> &I

Returns the index.

The index is optional and can be empty.

Source

pub fn query<J>( &self, min_shift: u8, depth: u8, interval: J, ) -> Result<Vec<&Bin>>
where J: Into<Interval>,

Returns a list of bins in this reference sequence that intersects the given range.

The interval values are 1-based.

§Examples
use noodles_core::Position;
use noodles_csi::binning_index::index::ReferenceSequence;

let reference_sequence = ReferenceSequence::new(Default::default(), Vec::new(), None);
let start = Position::try_from(8)?;
let end = Position::try_from(13)?;

let query_bins = reference_sequence.query(14, 5, start..=end)?;
assert!(query_bins.is_empty());
Source

pub fn min_offset( &self, min_shift: u8, depth: u8, start: Position, ) -> VirtualPosition

Finds the start virtual position of the first record in the bin that contains that given start position.

§Examples
use noodles_bgzf as bgzf;
use noodles_core::Position;
use noodles_csi::binning_index::index::{
    reference_sequence::{index::BinnedIndex, Bin},
    ReferenceSequence,
};

const MIN_SHIFT: u8 = 4;
const DEPTH: u8 = 2;

let bins = [(1, Bin::new(Vec::new()))].into_iter().collect();
let index = [(1, bgzf::VirtualPosition::from(233))].into_iter().collect();
let reference_sequence: ReferenceSequence<BinnedIndex> = ReferenceSequence::new(bins, index, None);

let start = Position::try_from(8)?;
assert_eq!(
    reference_sequence.min_offset(MIN_SHIFT, DEPTH, start),
    bgzf::VirtualPosition::from(233)
);

let start = Position::try_from(144)?;
assert_eq!(
    reference_sequence.min_offset(MIN_SHIFT, DEPTH, start),
    bgzf::VirtualPosition::default()
);
Source

pub fn first_record_in_last_linear_bin_start_position( &self, ) -> Option<VirtualPosition>

Returns the start position of the first record in the last linear bin.

This uses the linear index, if available; otherwise, the largest linear offset of all the bins is returned. If there is neither a linear index nor a collection of bins, this returns None.

§Examples
use noodles_bgzf as bgzf;
use noodles_csi::binning_index::index::{
    reference_sequence::{index::BinnedIndex, Bin},
    ReferenceSequence,
};

let reference_sequence = ReferenceSequence::new(
    Default::default(),
    vec![
        bgzf::VirtualPosition::from(8),
        bgzf::VirtualPosition::from(13),
        bgzf::VirtualPosition::from(21),
    ],
    None,
);
assert_eq!(
    reference_sequence.first_record_in_last_linear_bin_start_position(),
    Some(bgzf::VirtualPosition::from(21))
);

let mut reference_sequence: ReferenceSequence<BinnedIndex> = ReferenceSequence::new(
    [
        (0, Bin::new(Vec::new())),
        (2, Bin::new(Vec::new())),
        (9, Bin::new(Vec::new())),
    ]
    .into_iter()
    .collect(),
    [
        (0, bgzf::VirtualPosition::from(8)),
        (2, bgzf::VirtualPosition::from(21)),
        (9, bgzf::VirtualPosition::from(13)),
    ]
    .into_iter()
    .collect(),
    None,
);

assert_eq!(
    reference_sequence.first_record_in_last_linear_bin_start_position(),
    Some(bgzf::VirtualPosition::from(21))
);

let reference_sequence = ReferenceSequence::new(Default::default(), Vec::new(), None);
assert!(reference_sequence.first_record_in_last_linear_bin_start_position().is_none());

Trait Implementations§

Source§

impl<I: Clone> Clone for ReferenceSequence<I>

Source§

fn clone(&self) -> ReferenceSequence<I>

Returns a copy 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<I: Debug> Debug for ReferenceSequence<I>

Source§

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

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

impl<I: PartialEq> PartialEq for ReferenceSequence<I>

Source§

fn eq(&self, other: &ReferenceSequence<I>) -> 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<I> ReferenceSequence for ReferenceSequence<I>
where I: Index,

Source§

fn metadata(&self) -> Option<&Metadata>

Returns the optional metadata for the reference sequence.
Source§

impl<I: Eq> Eq for ReferenceSequence<I>

Source§

impl<I> StructuralPartialEq for ReferenceSequence<I>

Auto Trait Implementations§

§

impl<I> Freeze for ReferenceSequence<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for ReferenceSequence<I>
where I: RefUnwindSafe,

§

impl<I> Send for ReferenceSequence<I>
where I: Send,

§

impl<I> Sync for ReferenceSequence<I>
where I: Sync,

§

impl<I> Unpin for ReferenceSequence<I>
where I: Unpin,

§

impl<I> UnwindSafe for ReferenceSequence<I>
where I: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Compare self to key and return true if they are equal.
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> 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.