Navigating lineages
Core functions
NCBITaxonomy.lineage — Functionlineage(tax::NCBITaxon; stop_at::NCBITaxon=ncbi"root")Returns an array of NCBITaxon going up to the root of the taxonomy, or to the optionally specified stop_at taxonomic node.
AbstractTrees.children — FunctionAbstractTrees.children(tax::NCBITaxon)Returns the children of a taxon.
AbstractTrees.parent — FunctionAbstractTrees.parent(taxon::NCBITaxon)Returns the taxon from which the argument taxon is descended.
NCBITaxonomy.rank — Functionrank(taxon::NCBITaxon)Returns the rank of a taxon.
NCBITaxonomy.taxonomicdistance! — FunctionThis function fills a pre-allocated square matrix D with the taxonomic distance between taxa in a vector tax. The keywords areguments are d (the distance as a function to closest matching level), strict (a boolean to decide whether the distance of a taxon with itself should be read from the distance dictionary, or set to 0), and other keywords passed to the lineage function.
Because the distances are symetrical, there are only (n(n-1))/2 measurements to do.
By default, this function uses the distances from Shimatani (2001):
| equal rank | distance |
|---|---|
| species | 0 |
| genus | 1 |
| family | 2 |
| subclass | 3 |
:fallback | 4 |
Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. Oikos 93:135–147.
NCBITaxonomy.commonancestor — Functioncommonancestor(tax::Vector{NCBITaxon})Returns the node corresponding to the last common ancestor of taxa in a vector. This function can be useful to speed up the iteration using the AbstractTrees interface, notably to find the right node to use for descendantsfilter.
commonancestor(t1::NCBITaxon, t2::NCBITaxon)Returns the node corresponding to the last common ancestor of two taxa. This function can be useful to speed up the iteration using the AbstractTrees interface, notably to find the right node to use for descendantsfilter.
Examples
The children function will return a list of NCBITaxon that are immediately descending from the one given as argument. For example, the genus Lamellodiscus contains:
using NCBITaxonomy
ncbi"Lamellodiscus" |> AbstractTrees.childrenNote that the parent function does the opposite of children:
ncbi"Lamellodiscus kechemirae" |> AbstractTrees.parentTo get the full descendants of a taxon (i.e. the children of its children, recursively), we can use the tree traversal opertions in AbstractTrees, e.g.:
AbstractTrees.PostOrderDFS(ncbi"Diplectanidae")We can also work upwards in the taxonomy, using the lineage function – it takes an optional stop_at argument, which is the farther up it will go:
lineage(ncbi"Lamellodiscus elegans"; stop_at=ncbi"Monogenea")6-element Vector{NCBITaxon}:
Monogenea (ncbi:37945)
Monopisthocotylea (ncbi:37844)
Dactylogyridea (ncbi:2486284)
Diplectanidae (ncbi:67517)
Lamellodiscus (ncbi:119230)
Lamellodiscus elegans (ncbi:142933)The rank function is useful to know where in the taxonomy you are:
[t => rank(t) for t in lineage(ncbi"Lamellodiscus elegans"; stop_at=ncbi"Monogenea")]6-element Vector{Pair{NCBITaxon, Symbol}}:
Monogenea (ncbi:37945) => :class
Monopisthocotylea (ncbi:37844) => :subclass
Dactylogyridea (ncbi:2486284) => :order
Diplectanidae (ncbi:67517) => :family
Lamellodiscus (ncbi:119230) => :genus
Lamellodiscus elegans (ncbi:142933) => :species