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
impl Haplotype
Sourcepub fn allele_index(&self) -> usize
pub fn allele_index(&self) -> usize
Return the allele index of this haplotype.
Sourcepub fn extract_fragment(
&self,
reference: &[u8],
ref_start: u32,
fragment_len: usize,
) -> (Vec<u8>, Vec<u32>)
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.