Skip to main content

Haplotype

Struct Haplotype 

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

Sparse representation of one haplotype — a reference overlay of variants.

Instead of materializing a full haplotype sequence (which would require ~250MB per haplotype for human chr1), this stores only the differences from the reference as a sorted set of variants in a COITree for efficient range queries.

Fragment extraction works by walking the reference sequence and substituting alt alleles at variant positions on the fly.

Because coitrees requires Copy + Default for metadata, we store variant indices (as u32) in the tree and keep the actual variant data in a separate Vec.

Implementations§

Source§

impl Haplotype

Source

pub fn allele_index(&self) -> usize

Return the allele index of this haplotype.

Source

pub fn extract_fragment( &self, reference: &[u8], ref_start: u32, fragment_len: usize, ) -> (Vec<u8>, Vec<u32>)

Extract a fragment from this haplotype at the given reference coordinates.

Walks the reference from ref_start and produces fragment_len bases, substituting alternate alleles where this haplotype has variants. Returns the fragment bases and a list of reference positions corresponding to each fragment base (for golden BAM coordinate mapping).

§Arguments
  • reference — Full reference sequence for this contig.
  • ref_start — 0-based start position on the reference.
  • fragment_len — Desired number of output bases.
§Returns

A tuple of (fragment_bases, ref_positions) where ref_positions[i] is the reference position corresponding to fragment_bases[i]. For inserted bases, the reference position is that of the base preceding the insertion.

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V