pub struct AnnotationIndex { /* private fields */ }Expand description
Fast interval index using interval trees for O(log n + k) overlap queries
This implementation uses a centered interval tree per chromosome, providing logarithmic query time instead of linear scanning.
Implementations§
Source§impl AnnotationIndex
impl AnnotationIndex
Sourcepub fn build_trees(&mut self, annotations: HashMap<String, Vec<Annotation>>)
pub fn build_trees(&mut self, annotations: HashMap<String, Vec<Annotation>>)
Build interval trees from collected annotations
This should be called after all insertions are complete. For efficiency, batch all insertions then call this once.
Sourcepub fn from_bed<P, F>(path: P, extractor: F) -> Result<Self>
pub fn from_bed<P, F>(path: P, extractor: F) -> Result<Self>
Build annotation index from BED file
The extractor function converts each BED record into annotation data.
Typically this extracts the “name” field, but can be customized.
§Examples
use genomicframe_core::interval::annotation::AnnotationIndex;
// Extract gene names from BED name field
let index = AnnotationIndex::from_bed("genes.bed", |record| {
record.name.clone().unwrap_or_default()
})?;
// Custom extraction: combine name and score
let index = AnnotationIndex::from_bed("features.bed", |record| {
format!("{}:{}",
record.name.as_deref().unwrap_or("unknown"),
record.score.unwrap_or(0))
})?;Sourcepub fn from_records<'a, I, F>(records: I, extractor: F) -> Self
pub fn from_records<'a, I, F>(records: I, extractor: F) -> Self
Build annotation index from an iterator of BED records
Sourcepub fn from_reader<I, F>(reader: I, extractor: F) -> Result<Self>
pub fn from_reader<I, F>(reader: I, extractor: F) -> Result<Self>
Build annotation index from a reader (possibly filtered)
Sourcepub fn query(&self, interval: &GenomicInterval) -> Vec<&str>
pub fn query(&self, interval: &GenomicInterval) -> Vec<&str>
Query for all annotations overlapping the given interval
Returns references to annotation data strings.
§Performance
O(log n + k) where n = number of annotations on the chromosome, k = number of overlapping annotations
Sourcepub fn query_annotations(&self, interval: &GenomicInterval) -> Vec<&Annotation>
pub fn query_annotations(&self, interval: &GenomicInterval) -> Vec<&Annotation>
Query for all annotations overlapping the given interval
Returns full Annotation structs (includes intervals).
Sourcepub fn chromosomes(&self) -> Vec<&str>
pub fn chromosomes(&self) -> Vec<&str>
Get chromosomes present in the index
Trait Implementations§
Source§impl Clone for AnnotationIndex
impl Clone for AnnotationIndex
Source§fn clone(&self) -> AnnotationIndex
fn clone(&self) -> AnnotationIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnnotationIndex
impl Debug for AnnotationIndex
Auto Trait Implementations§
impl Freeze for AnnotationIndex
impl RefUnwindSafe for AnnotationIndex
impl Send for AnnotationIndex
impl Sync for AnnotationIndex
impl Unpin for AnnotationIndex
impl UnsafeUnpin for AnnotationIndex
impl UnwindSafe for AnnotationIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more