Module bio::alignment::distance [] [src]

Various subroutines for computing a distance between sequences. Complexity: O(n) for strings of length n for the Hamming distance; O(n * m) for strings of length n and m for the Levenshtein (or edit) distance.

Example

use bio::alignment::distance::*;

let x = b"GTCTGCATGCG";
let y = b"TTTAGCTAGCG";
// GTCTGCATGCG
//  |  ||  |||
// TTTAGCTAGCG
match hamming(x, y) {
    Ok(s)  => println!("Score is: {}", s),  // Score is 5
    Err(e) => println!("Error: {}", e),     // No error in this example
}

let x = b"ACCGTGGAT";
let y = b"AAAAACCGTTGAT";
// ----ACCGTGGAT
//     ||||| |||
// AAAAACCGTTGAT
let l_score = levenshtein(x, y);  // Score is 5
assert_eq!(l_score, 5);

Functions

hamming

Compute the Hamming distance between two strings with hamming. If returns the Result<u32, &str> type with the first element corresponding to the distance between two strings (a number of mismatches) and the second one to the error message when two strings are not of equal sizes.

levenshtein

Compute the Levenshtein (or Edit) distance between two strings with levenshtein. It returns a distance between two strings, i.e. minimal number of mismatches, insertions and deletions between two strings.