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> ) -> ReferenceSequence<I>

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>, Error>
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 for ReferenceSequence<I>
where I: Clone,

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 for ReferenceSequence<I>
where I: Debug,

source§

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

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

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

source§

fn eq(&self, other: &ReferenceSequence<I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 for ReferenceSequence<I>
where I: Eq,

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<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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more