Navigating lineages

Core functions

NCBITaxonomy.lineageFunction
lineage(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.

source
AbstractTrees.parentFunction
AbstractTrees.parent(taxon::NCBITaxon)

Returns the taxon from which the argument taxon is descended.

source
NCBITaxonomy.taxonomicdistance!Function

This 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 rankdistance
species0
genus1
family2
subclass3
:fallback4

Shimatani, K. 2001. On the measurement of species diversity incorporating species differences. Oikos 93:135–147.

source
NCBITaxonomy.commonancestorFunction
commonancestor(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.

source
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.

source

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.children

Note that the parent function does the opposite of children:

ncbi"Lamellodiscus kechemirae" |> AbstractTrees.parent

To 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