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

source

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.

source

pub fn to_internal_index(&self, tax_id: &str) -> TaxonomyResult<usize>

source

pub fn from_internal_index(&self, tax_id: usize) -> TaxonomyResult<&str>

source

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>

source

pub fn find_all_by_name(&self, name: &str) -> Vec<&str>

Retrieves all external IDs given a name

source

pub fn add(&mut self, parent_id: &str, tax_id: &str) -> TaxonomyResult<()>

Add a new node to the taxonomy.

source

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

source§

fn clone(&self) -> GeneralTaxonomy

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GeneralTaxonomy

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GeneralTaxonomy

source§

fn default() -> Self

Create a new GeneralTaxonomy with only a root node.

source§

impl<'de> Deserialize<'de> for GeneralTaxonomy

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<GeneralTaxonomy> for GeneralTaxonomy

source§

fn eq(&self, other: &GeneralTaxonomy) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for GeneralTaxonomy

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where
__S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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 root(&'t self) -> &'t str

Returns the root node of the entire tree.
source§

fn children(&'t self, tax_id: &str) -> TaxonomyResult<Vec<&'t str>>

Returns a Vec of all the direct children IDs of the given tax_id.
source§

fn descendants(&'t self, tax_id: &'t str) -> TaxonomyResult<Vec<&'t str>>

Returns a Vec of all the children IDs of the given tax_id.
source§

fn parent(&'t self, tax_id: &str) -> TaxonomyResult<Option<(&'t str, f32)>>

Returns the parent of the given taxonomic node and the distance to said parent. The parent of the root node will return None.
source§

fn name(&'t self, tax_id: &str) -> TaxonomyResult<&str>

Returns the name of the tax_id provided.
source§

fn data(
&'t self,
tax_id: &str
) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>

Returns the additional data at the given tax id node This is only used by the json taxonomy so the value is serde_json::Value By default it just returns an empty hashmap
source§

fn rank(&'t self, tax_id: &str) -> TaxonomyResult<TaxRank>

Returns the taxonomic rank of the tax_id provided.
source§

fn len(&'t self) -> usizewhere
Self: Sized,

Returns the number of nodes in the taxonomy
source§

fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>

Returns a Vec of taxonomy nodes from the one provided back to root. This method must return the node itself as the first entry in the list and the root node as the last entry in the list.
source§

fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>

Returns the parent at a given taxonomic rank (note this may not be the immediate parent). This also returns the distance to that parent.
source§

fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>

Returns the first common parent between two nodes. E.g. for the tree: Read more
source§

fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,

Generates an iterator that traces over the entire taxonomic tree from the given node. During preorder traversal, it returns (T, true) and during postorder traversal it returns (T, false)
source§

fn is_empty(&'t self) -> boolwhere
Self: Sized,

Determines if there are any nodes at all in the taxonomy. This should almost always be implemented for performance reasons.
source§

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 root(&'t self) -> usize

Returns the root node of the entire tree.
source§

fn children(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>

Returns a Vec of all the direct children IDs of the given tax_id.
source§

fn descendants(&'t self, tax_id: usize) -> TaxonomyResult<Vec<usize>>

Returns a Vec of all the children IDs of the given tax_id.
source§

fn parent(&'t self, idx: usize) -> TaxonomyResult<Option<(usize, f32)>>

Returns the parent of the given taxonomic node and the distance to said parent. The parent of the root node will return None.
source§

fn name(&'t self, idx: usize) -> TaxonomyResult<&str>

Returns the name of the tax_id provided.
source§

fn data(&'t self, idx: usize) -> TaxonomyResult<Cow<'t, HashMap<String, Value>>>

Returns the additional data at the given tax id node This is only used by the json taxonomy so the value is serde_json::Value By default it just returns an empty hashmap
source§

fn rank(&'t self, idx: usize) -> TaxonomyResult<TaxRank>

Returns the taxonomic rank of the tax_id provided.
source§

fn len(&'t self) -> usizewhere
Self: Sized,

Returns the number of nodes in the taxonomy
source§

fn lineage(&'t self, tax_id: T) -> TaxonomyResult<Vec<T>>

Returns a Vec of taxonomy nodes from the one provided back to root. This method must return the node itself as the first entry in the list and the root node as the last entry in the list.
source§

fn parent_at_rank(
&'t self,
tax_id: T,
rank: TaxRank
) -> TaxonomyResult<Option<(T, f32)>>

Returns the parent at a given taxonomic rank (note this may not be the immediate parent). This also returns the distance to that parent.
source§

fn lca(&'t self, id1: T, id2: T) -> TaxonomyResult<T>

Returns the first common parent between two nodes. E.g. for the tree: Read more
source§

fn traverse(&'t self, node: T) -> TaxonomyResult<TaxonomyIterator<'t, T>>where
Self: Sized,

Generates an iterator that traces over the entire taxonomic tree from the given node. During preorder traversal, it returns (T, true) and during postorder traversal it returns (T, false)
source§

fn is_empty(&'t self) -> boolwhere
Self: Sized,

Determines if there are any nodes at all in the taxonomy. This should almost always be implemented for performance reasons.
source§

impl StructuralPartialEq for GeneralTaxonomy

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere
T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,