pub struct BitEnc { /* private fields */ }Expand description
A 2-bit encoded DNA sequence stored in a u64.
Supports sequences up to 32 bases (64 bits). Each base is encoded as: A=0, C=1, G=2, T=3.
Implementations§
Source§impl BitEnc
impl BitEnc
Sourcepub fn from_bytes(seq: &[u8]) -> Option<BitEnc>
pub fn from_bytes(seq: &[u8]) -> Option<BitEnc>
Create a BitEnc from a byte slice.
Returns None if the sequence contains non-ACGT bases or exceeds 32 bases.
Sourcepub fn from_umi_str(umi: &str) -> Option<BitEnc>
pub fn from_umi_str(umi: &str) -> Option<BitEnc>
Create a BitEnc from a UMI string, skipping non-ACGT characters (e.g., dashes in paired UMIs).
This is useful for paired UMIs like “ACGT-TGCA” where the dash should be ignored. Returns None if the sequence contains invalid bases (not ACGT or dash) or exceeds 32 bases.
Sourcepub fn hamming_distance(&self, other: &BitEnc) -> u32
pub fn hamming_distance(&self, other: &BitEnc) -> u32
Compute the Hamming distance between two encoded sequences.
Both sequences must have the same length (debug assertion).
Sourcepub fn base_at(&self, pos: usize) -> u8
pub fn base_at(&self, pos: usize) -> u8
Get the 2-bit encoded base at the given position.
Returns a value in 0..4 representing A, C, G, T respectively.
Sourcepub fn with_base_at(&self, pos: usize, base: u8) -> BitEnc
pub fn with_base_at(&self, pos: usize, base: u8) -> BitEnc
Return a copy of this sequence with a different base at the given position.
base must be in 0..4 (A=0, C=1, G=2, T=3).
Sourcepub fn extract_bits(&self, start_base: usize, num_bases: usize) -> u32
pub fn extract_bits(&self, start_base: usize, num_bases: usize) -> u32
Extract bits for bases [start_base, start_base + len) as a u32.
Each base is 2 bits, so this can extract up to 16 bases into a u32. Used for N-gram partitioning in similarity search.
Trait Implementations§
impl Copy for BitEnc
impl Eq for BitEnc
impl StructuralPartialEq for BitEnc
Auto Trait Implementations§
impl Freeze for BitEnc
impl RefUnwindSafe for BitEnc
impl Send for BitEnc
impl Sync for BitEnc
impl Unpin for BitEnc
impl UnsafeUnpin for BitEnc
impl UnwindSafe for BitEnc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more