Struct taxonomy::GeneralTaxonomy
source · pub struct GeneralTaxonomy {
pub tax_ids: Vec<String>,
pub parent_ids: Vec<usize>,
pub parent_distances: Vec<f32>,
pub names: Vec<String>,
pub ranks: Vec<TaxRank>,
pub data: Vec<HashMap<String, Value>>,
/* private fields */
}
Expand description
The type that is returned when loading any taxonomies through that library. It include 2 implementations of the Taxonomy trait: one using strings as ids (easier to use but slower) and one using internal indices (harder to use but faster). Most fields are public for flexibility reason.
Fields§
§tax_ids: Vec<String>
§parent_ids: Vec<usize>
§parent_distances: Vec<f32>
§names: Vec<String>
§ranks: Vec<TaxRank>
§data: Vec<HashMap<String, Value>>
Implementations§
source§impl GeneralTaxonomy
impl GeneralTaxonomy
sourcepub fn validate_uniqueness(&self) -> TaxonomyResult<()>
pub fn validate_uniqueness(&self) -> TaxonomyResult<()>
Ensures that tax ids are unique. This is not useful for all kinds of taxonomies since some formats have optional ids.
pub fn to_internal_index(&self, tax_id: &str) -> TaxonomyResult<usize>
pub fn from_internal_index(&self, tax_id: usize) -> TaxonomyResult<&str>
pub fn from_arrays(
tax_ids: Vec<String>,
parent_ids: Vec<usize>,
names: Option<Vec<String>>,
ranks: Option<Vec<TaxRank>>,
distances: Option<Vec<f32>>,
data: Option<Vec<HashMap<String, Value>>>
) -> TaxonomyResult<Self>
sourcepub fn find_all_by_name(&self, name: &str) -> Vec<&str>
pub fn find_all_by_name(&self, name: &str) -> Vec<&str>
Retrieves all external IDs given a name
sourcepub fn add(&mut self, parent_id: &str, tax_id: &str) -> TaxonomyResult<()>
pub fn add(&mut self, parent_id: &str, tax_id: &str) -> TaxonomyResult<()>
Add a new node to the taxonomy.
sourcepub fn remove(&mut self, tax_id: &str) -> TaxonomyResult<()>
pub fn remove(&mut self, tax_id: &str) -> TaxonomyResult<()>
Remove a single node from the taxonomy.
Unlike pruning the children of the node are kept, but are rejoined onto the node’s parent. The root node can not be removed
Trait Implementations§
source§impl Clone for GeneralTaxonomy
impl Clone for GeneralTaxonomy
source§fn clone(&self) -> GeneralTaxonomy
fn clone(&self) -> GeneralTaxonomy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for GeneralTaxonomy
impl Debug for GeneralTaxonomy
source§impl Default for GeneralTaxonomy
impl Default for GeneralTaxonomy
source§impl<'de> Deserialize<'de> for GeneralTaxonomy
impl<'de> Deserialize<'de> for GeneralTaxonomy
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq<GeneralTaxonomy> for GeneralTaxonomy
impl PartialEq<GeneralTaxonomy> for GeneralTaxonomy
source§fn eq(&self, other: &GeneralTaxonomy) -> bool
fn eq(&self, other: &GeneralTaxonomy) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for GeneralTaxonomy
impl Serialize for GeneralTaxonomy
source§impl<'t> Taxonomy<'t, &'t str> for GeneralTaxonomy
impl<'t> Taxonomy<'t, &'t str> for GeneralTaxonomy
This is the implementation for &str taxonomy access for a more end-user understandable (but slightly slower) workflow.
source§fn children(&'t self, tax_id: &str) -> TaxonomyResult<Vec<&'t str>>
fn children(&'t self, tax_id: &str) -> TaxonomyResult<Vec<&'t str>>
source§fn descendants(&'t self, tax_id: &'t str) -> TaxonomyResult<Vec<&'t str>>
fn descendants(&'t self, tax_id: &'t str) -> TaxonomyResult<Vec<&'t str>>
source§fn parent(&'t self, tax_id: &str) -> TaxonomyResult<Option<(&'t str, f32)>>
fn parent(&'t self, tax_id: &str) -> TaxonomyResult<Option<(&'t str, f32)>>
source§fn name(&'t self, tax_id: &str) -> TaxonomyResult<&str>
fn name(&'t self, tax_id: &str) -> TaxonomyResult<&str>
source§fn data(
&'t self,
tax_id: &str
) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>
fn data(
&'t self,
tax_id: &str
) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>
source§fn rank(&'t self, tax_id: &str) -> TaxonomyResult<TaxRank>
fn rank(&'t self, tax_id: &str) -> TaxonomyResult<TaxRank>
source§fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>
fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>
source§fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>
fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>
source§fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>
fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>
source§fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,
fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,
(T, true)
and during postorder traversal
it returns (T, false)
source§impl<'t> Taxonomy<'t, usize> for GeneralTaxonomy
impl<'t> Taxonomy<'t, usize> for GeneralTaxonomy
This is the implementation for “internal” tax ID lookup; these IDs are arbitrary (they’re positions of the tax nodes in the internal array) and not linked at all to the “external” (e.g. NCBI) IDs. Using these IDs directly can lead to a decent speed up without having to build indices. This is about 3-8x faster than the &str impl, depending on the usage.
source§fn children(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>
fn children(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>
source§fn descendants(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>
fn descendants(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>
source§fn parent(&'t self, idx: usize) -> TaxonomyResult<Option<(usize, f32)>>
fn parent(&'t self, idx: usize) -> TaxonomyResult<Option<(usize, f32)>>
source§fn name(&'t self, idx: usize) -> TaxonomyResult<&str>
fn name(&'t self, idx: usize) -> TaxonomyResult<&str>
source§fn data(&'t self, idx: usize) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>
fn data(&'t self, idx: usize) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>
source§fn rank(&'t self, idx: usize) -> TaxonomyResult<TaxRank>
fn rank(&'t self, idx: usize) -> TaxonomyResult<TaxRank>
source§fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>
fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>
source§fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>
fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>
source§fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>
fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>
source§fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,
fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,
(T, true)
and during postorder traversal
it returns (T, false)