Skip to main content

MinHash

Struct MinHash 

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

Bottom-k MinHash sketch for rapid genome comparison.

Keeps the sketch_size smallest canonical k-mer hash values from a DNA sequence. Jaccard similarity between two sketches is estimated from the overlap of their bottom-k hash sets.

Implementations§

Source§

impl MinHash

Source

pub fn new(k: usize, sketch_size: usize) -> Result<Self>

Create a new empty MinHash sketch.

§Errors

Returns an error if k == 0 or sketch_size == 0.

Source

pub fn from_sequence(seq: &[u8], k: usize, sketch_size: usize) -> Result<Self>

Build a MinHash sketch from a DNA sequence.

Non-ACGT bases act as k-mer break points (k-mers spanning them are skipped). Input is case-insensitive.

§Errors

Returns an error if k == 0 or sketch_size == 0.

Source

pub fn add_sequence(&mut self, seq: &[u8])

Add k-mers from a DNA sequence to this sketch.

Non-ACGT bases act as k-mer break points. The sketch is maintained as a sorted bottom-k set.

Source

pub fn jaccard(&self, other: &MinHash) -> Result<f64>

Estimate Jaccard similarity between this sketch and another.

Uses the merge-based estimator: merge both sorted hash arrays, count how many of the bottom-k values from the union appear in both sketches.

§Errors

Returns an error if the sketches have different k values.

Source

pub fn containment(&self, other: &MinHash) -> Result<f64>

Estimate containment of self in other.

Containment C(A, B) = |A intersect B| / |A|.

§Errors

Returns an error if the sketches have different k values.

Source

pub fn ani(&self, other: &MinHash) -> Result<f64>

Estimate average nucleotide identity (ANI) from Jaccard similarity.

Uses the Mash formula: ANI = 1 + (2/k) * ln(2J / (1 + J))

§Errors

Returns an error if the sketches have different k values, or if the Jaccard similarity is zero (ANI undefined).

Source

pub fn len(&self) -> usize

Number of hash values currently in the sketch.

Source

pub fn is_empty(&self) -> bool

Whether the sketch is empty (no k-mers hashed).

Source

pub fn k(&self) -> usize

The k-mer size used by this sketch.

Source

pub fn sketch_size(&self) -> usize

The target sketch size (bottom-k parameter).

Source

pub fn hashes(&self) -> &[u64]

Return a reference to the sorted hash values.

Trait Implementations§

Source§

impl Clone for MinHash

Source§

fn clone(&self) -> MinHash

Returns a duplicate 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 Debug for MinHash

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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.