fix_error

Function fix_error 

Source
pub fn fix_error<'a, I>(
    mismatch_seq: &str,
    possible_seqs: I,
    mismatches: u16,
) -> Option<String>
where I: IntoIterator<Item = &'a String>,
Expand description

Fix an error in a sequence by comparing it to all possible sequences. If no sequence matches with fewer or equal to the number of mismatches ‘None’ is returned. ‘None’ is also returned if two or more sequences are best matches. Will work with vec and hashset

§Example

use barcode_count::parse::fix_error;

let barcode = "AGTAG";

let possible_barcodes_one_match: std::collections::AHashSet<String> = ["AGCAG".to_string(), "ACAAG".to_string(), "AGCAA".to_string()].iter().cloned().collect(); // only the first has a single mismatch
let possible_barcodes_two_match: std::collections::AHashSet<String> = ["AGCAG".to_string(), "AGAAG".to_string(), "AGCAA".to_string()].iter().cloned().collect(); // first and second have a single mismatch

let max_mismatches = barcode.chars().count() as u16 / 5; // allow up to 20% mismatches

let fixed_error_one = fix_error(barcode, &possible_barcodes_one_match, max_mismatches);
let fixed_error_two = fix_error(barcode, &possible_barcodes_two_match, max_mismatches);

assert_eq!(fixed_error_one, Some("AGCAG".to_string()));
assert_eq!(fixed_error_two, None);