pub struct BkTree { /* private fields */ }Expand description
BK-tree for efficient Hamming distance queries on UMIs.
A BK-tree (Burkhard-Keller tree) is a metric tree that exploits the triangle inequality to efficiently find all strings within a given edit distance. For Hamming distance queries with threshold k, it achieves O(k * log n) average case complexity instead of O(n) for linear scan.
This implementation uses BitEnc for O(1) Hamming distance computation.
§Algorithm
The tree is built by inserting UMIs one by one:
- The first UMI becomes the root
- For each subsequent UMI, traverse from root following edges labeled with the Hamming distance to each node’s UMI
- Insert as a new child when no edge exists for that distance
To query for all UMIs within distance k of a query:
- Compute distance d from query to current node
- If d <= k, include this node in results
- Recursively search children with edge labels in range [d-k, d+k] (triangle inequality guarantees other children can’t contain matches)
Implementations§
Source§impl BkTree
impl BkTree
Sourcepub fn from_umis(umis: &[(usize, &str)]) -> Option<BkTree>
pub fn from_umis(umis: &[(usize, &str)]) -> Option<BkTree>
Build a BK-tree from a list of UMIs with their indices.
Returns None if any UMI contains non-ACGT bases (cannot be encoded).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BkTree
impl RefUnwindSafe for BkTree
impl Send for BkTree
impl Sync for BkTree
impl Unpin for BkTree
impl UnsafeUnpin for BkTree
impl UnwindSafe for BkTree
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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