Skip to content

Commit

Permalink
fix: backward search yielding potentially incorrect positions on FM-I…
Browse files Browse the repository at this point in the history
…ndex (#454) (#455)
  • Loading branch information
jch-13 authored and johanneskoester committed Oct 4, 2021
1 parent a3ebaa8 commit 3489e6a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/data_structures/fmindex.rs
Expand Up @@ -127,7 +127,7 @@ pub trait FMIndexable {

// The symbol was not found if we end up with an empty interval.
// Terminate the LF-mapping process.
if l == r {
if l > r {
break;
}
}
Expand Down Expand Up @@ -540,6 +540,24 @@ mod tests {
assert_eq!(positions, []);
}

#[test]
fn test_fmindex_backward_search_optimization() {
let text = b"GATTACA$";
let pattern = &text[..text.len() - 1];
let alphabet = dna::n_alphabet();
let sa = suffix_array(text);
let bwt = bwt(text, &sa);
let less = less(&bwt, &alphabet);
let occ = Occ::new(&bwt, 3, &alphabet);
let fm = FMIndex::new(&bwt, &less, &occ);

let sai = fm.backward_search(pattern.iter());

let positions = sai.occ(&sa);

assert_eq!(positions, [0]);
}

#[test]
fn test_smems() {
let orig_text = b"GCCTTAACAT";
Expand Down

0 comments on commit 3489e6a

Please sign in to comment.