Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backward search on FM-Index (#454) #455

Merged
merged 1 commit into from Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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