Struct bio::data_structures::annot_map::AnnotMap
source · Expand description
Efficient container for querying annotations, using HashMap
and
IntervalTree
.
The container is parameterized over the type of the reference
sequence names R
(which is often a String
) and the type of the
contained objects T
.
The container finds annotations that overlap a specific query location. Overlaps are identified without regard for strandedness and without regard for e.g. spliced-out introns within the annotation or the query.
Thus, the overlapping annotations identified by querying a
AnnotMap
may need further filtering.
Implementations
sourceimpl<R, T> AnnotMap<R, T>where
R: Eq + Hash,
impl<R, T> AnnotMap<R, T>where
R: Eq + Hash,
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty AnnotMap
.
extern crate bio;
use bio::data_structures::annot_map::AnnotMap;
let mut genes: AnnotMap<String,String> = AnnotMap::new();
sourcepub fn insert_at<L>(&mut self, data: T, location: &L)where
R: Eq + Hash + Clone,
L: Loc<RefID = R>,
pub fn insert_at<L>(&mut self, data: T, location: &L)where
R: Eq + Hash + Clone,
L: Loc<RefID = R>,
Inserts an object into the container at a specified location.
Arguments
data
is the data item to be inserted into the annotation map
location
is the location associated with the data item.
extern crate bio_types;
extern crate bio;
use bio_types::strand::ReqStrand;
use bio_types::annot::contig::Contig;
use bio::data_structures::annot_map::AnnotMap;
let mut genes: AnnotMap<String,String> = AnnotMap::new();
let tma22 = Contig::new("chrX".to_owned(), 461829, 462426 - 461829, ReqStrand::Forward);
genes.insert_at("TMA22".to_owned(), &tma22);
let tma19 = Contig::new("chrXI".to_owned(), 334412, (334916 - 334412), ReqStrand::Reverse);
genes.insert_at("TMA19".to_owned(), &tma19);
sourcepub fn find<'a, L>(&'a self, location: &'a L) -> AnnotMapIterator<'a, R, T> ⓘwhere
L: Loc<RefID = R>,
pub fn find<'a, L>(&'a self, location: &'a L) -> AnnotMapIterator<'a, R, T> ⓘwhere
L: Loc<RefID = R>,
Creates an Iterator
that will visit all entries that overlap
a query location.
Arguments
location
is the annotation location to be searched for
overlapping data items.
extern crate bio_types;
extern crate bio;
use bio_types::strand::ReqStrand;
use bio_types::annot::contig::Contig;
use bio::data_structures::annot_map::AnnotMap;
let mut genes: AnnotMap<String,String> = AnnotMap::new();
let tma22 = Contig::new("chrX".to_owned(), 461829, 462426 - 461829, ReqStrand::Forward);
genes.insert_at("TMA22".to_owned(), &tma22);
let tma19 = Contig::new("chrXI".to_owned(), 334412, (334916 - 334412), ReqStrand::Reverse);
genes.insert_at("TMA19".to_owned(), &tma19);
let query = Contig::new("chrX".to_owned(), 462400, 100, ReqStrand::Forward);
let hits: Vec<&String> = genes.find(&query).map(|e| e.data()).collect();
assert_eq!(hits, vec!["TMA22"]);
let query = Contig::new("chrXI".to_owned(), 334400, 100, ReqStrand::Forward);
let hits: Vec<&String> = genes.find(&query).map(|e| e.data()).collect();
assert_eq!(hits, vec!["TMA19"]);
sourceimpl<R, T> AnnotMap<R, T>where
R: Eq + Hash + Clone,
T: Loc<RefID = R>,
impl<R, T> AnnotMap<R, T>where
R: Eq + Hash + Clone,
T: Loc<RefID = R>,
sourcepub fn insert_loc(&mut self, data: T)
pub fn insert_loc(&mut self, data: T)
Inserts an object with the Loc
trait into the container at
its location.
Argument
data
is the data to be inserted based on its location.
Equivalent to inserting data
at data.contig()
.