Trait bio::data_structures::fmindex::FMIndexable
source · pub trait FMIndexable {
// Required methods
fn occ(&self, r: usize, a: u8) -> usize;
fn less(&self, a: u8) -> usize;
fn bwt(&self) -> &BWT;
// Provided method
fn backward_search<'b, P: Iterator<Item = &'b u8> + DoubleEndedIterator>(
&self,
pattern: P,
) -> BackwardSearchResult { ... }
}
Required Methods§
Provided Methods§
sourcefn backward_search<'b, P: Iterator<Item = &'b u8> + DoubleEndedIterator>(
&self,
pattern: P,
) -> BackwardSearchResult
fn backward_search<'b, P: Iterator<Item = &'b u8> + DoubleEndedIterator>( &self, pattern: P, ) -> BackwardSearchResult
Perform backward search, yielding BackwardSearchResult
enum that
contains the suffix array interval denoting exact occurrences of the given pattern
of length m in the text if it exists, or the suffix array interval denoting the
exact occurrences of a maximal matching suffix of the given pattern if it does
not exist. If none of the pattern can be matched, the BackwardSearchResult
is
Absent
.
Complexity: O(m).
§Arguments
pattern
- the pattern to search
§Example
use bio::alphabets::dna;
use bio::data_structures::bwt::{bwt, less, Occ};
use bio::data_structures::fmindex::{BackwardSearchResult, FMIndex, FMIndexable};
use bio::data_structures::suffix_array::suffix_array;
let text = b"GCCTTAACATTATTACGCCTA$";
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 pattern = b"TTA";
let bsr = fm.backward_search(pattern.iter());
let positions = match bsr {
BackwardSearchResult::Complete(sai) => sai.occ(&sa),
BackwardSearchResult::Partial(sai, _l) => sai.occ(&sa),
BackwardSearchResult::Absent => Vec::<usize>::new(),
};
assert_eq!(positions, [3, 12, 9]);
Object Safety§
This trait is not object safe.