tree-accuracy: score a phylogenetic tree against a reference taxonomy
tree-accuracy measures how well a phylogenetic tree agrees with a known
taxonomy, using the F-measure metric from tax2tree (McDonald et al, 2012, see
below). For each named taxon (e.g. a genus), it finds the best-matching clade
in the tree and scores it by the harmonic mean of precision and recall of that
clade's leaf set against the taxon's true leaf set. The overall score is the
mean F-measure over all taxa, pooled across every level of the lineage.
A perfectly congruent tree — every named taxon forms an exact clade — scores
1.0. A tree whose topology bears no relation to the taxonomy scores much
lower.
Installation
pip install tree-accuracy
Requires Python < 3.13: the ete3 dependency imports the standard-library
cgi module, which was removed in 3.13, so import ete3 (and therefore
import tree_accuracy) fails outright on 3.13+ until upstream fixes this.
Command-line usage
tree_fscore taxmap.tsv treefile
-
taxmap.tsv: a two-column, whitespace-separated file. The first column is an accession (a leaf name intreefile); the rest of the line is a lineage string of taxonomy labels separated by colons and/or semicolons, coarsest first, e.g.:AB012345.1.1200 Eukaryota;Amorphea;Obazoa;Opisthokonta;Nucletmycea;Fungi;Dikarya;Ascomycota;Saccharomycotina;Saccharomycetes;Saccharomycetales;Debaryomycetaceae;Scheffersomyces;Scheffersomyces stipitis -
treefile: a Newick tree whose leaf names match the accessions intaxmap.tsv.
The command prints a single number — the pooled mean F-measure — to stdout.
See examples/ for two small worked datasets (a perfectly congruent tree and
a scrambled one) and examples/README.md for details.
Python API
import ete3
from tree_accuracy import fscore
from tree_accuracy.taxonomy import load_taxmap
lineages = load_taxmap("taxmap.tsv") # accession -> [label_at_depth_0, ...]
tree = ete3.Tree("treefile.nwk")
scores = fscore(tree, lineages)
print(scores["pooled"]) # overall accuracy
print(scores["depth0"]) # mean F-measure at the coarsest lineage level
fscore returns a dict mapping each lineage depth to the mean F-measure of
taxa found at that depth, plus 'pooled' for the mean over all taxa at all
depths combined. Taxon labels shared by fewer than min_count leaves
(default 2) are excluded from scoring, since a label unique to a single leaf
trivially scores F=1 there and would otherwise inflate the mean.
See examples/python_example.py for a complete, runnable script that scores
both example datasets this way and prints the full per-depth breakdown, not
just the pooled number the CLI prints.
Reference
The F-measure scoring method is from tax2tree:
McDonald D, Price MN, Goodrich J, Nawrocki EP, DeSantis TZ, Probst A, Andersen GL, Knight R, Hugenholtz P. "An improved Greengenes taxonomy with explicit ranks for ecological and evolutionary analyses of bacteria and archaea." The ISME Journal 6, 610–618 (2012). https://doi.org/10.1038/ismej.2011.139
This package reimplements the metric directly against
ete3 rather than depending on tax2tree itself
(which is built around skbio TreeNode objects and its own rank-prefixed
consensus string format), so it works with any colon/semicolon-delimited
lineage string (SILVA, PFAM clan/family hierarchies, ...) without first
converting it into that format.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_accuracy-1.0.tar.gz.
File metadata
- Download URL: tree_accuracy-1.0.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
408f583ee6117dd566b8e414708dc2755b720de3444df72d2937225b0a2a86af
|
|
| MD5 |
65a6a17d869f9e4fabcb1ff00e21341c
|
|
| BLAKE2b-256 |
759009d06e0fc6010b54961ca1898392bbfdf35a1bd3f80715c145ed481f2527
|
Provenance
The following attestation bundles were made for tree_accuracy-1.0.tar.gz:
Publisher:
publish.yml on arvestad/tree-accuracy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_accuracy-1.0.tar.gz -
Subject digest:
408f583ee6117dd566b8e414708dc2755b720de3444df72d2937225b0a2a86af - Sigstore transparency entry: 2299662249
- Sigstore integration time:
-
Permalink:
arvestad/tree-accuracy@b517da39fb0d26ceb1ecddaab3b5db8c98378810 -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/arvestad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b517da39fb0d26ceb1ecddaab3b5db8c98378810 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_accuracy-1.0-py3-none-any.whl.
File metadata
- Download URL: tree_accuracy-1.0-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a367449e8a4f78b0c75e094dd4bcc1cae13e79279ff52620e64b4fd62c8944a0
|
|
| MD5 |
c9748d60122bc704441f8032c3aad31a
|
|
| BLAKE2b-256 |
4a605fe630a63a52ab73b497a6498c53ad933ef6f91c2625bc70ae4d2aab02c8
|
Provenance
The following attestation bundles were made for tree_accuracy-1.0-py3-none-any.whl:
Publisher:
publish.yml on arvestad/tree-accuracy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_accuracy-1.0-py3-none-any.whl -
Subject digest:
a367449e8a4f78b0c75e094dd4bcc1cae13e79279ff52620e64b4fd62c8944a0 - Sigstore transparency entry: 2299662277
- Sigstore integration time:
-
Permalink:
arvestad/tree-accuracy@b517da39fb0d26ceb1ecddaab3b5db8c98378810 -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/arvestad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b517da39fb0d26ceb1ecddaab3b5db8c98378810 -
Trigger Event:
push
-
Statement type: