Skip to content

treedist

zombi2 tools treedist TREE_A TREE_B reports how far apart two rooted trees are, over the same tip set, or with --restrict over the tips they share, printed as <metric><TAB><value> to stdout (or a file with -o). Pick the metric with --metric:

--metric Distance
rf (default) Robinson–Foulds, the number of clades present in one tree but not the other
rf-normalized that count over the total number of non-trivial clades, so it lands in [0, 1]
branch-score Kuhner–Felsenstein, the square root of the summed squared branch-length differences over every clade, terminal branches included; unlike RF it moves even when only the branch lengths differ
all every metric above, one per line

Tips are matched by label, the tip name for an external tree or n<id> for a ZOMBI2 tree, so a true tree and an inferred tree line up by taxon whatever order their files list them in. The two trees must carry the same tip set, or --restrict prunes both to the taxa they share and scores them there, saying on stderr how many that left; fewer than three shared taxa is refused, since there is no clade to disagree about. Without --restrict a differing leaf set is an error, not a partial score.

# Robinson–Foulds between a true tree and an inferred one over the same tips
zombi2 tools treedist true.nwk inferred.nwk --metric rf

Comparing a gene tree to a species tree

A gene tree's tips are genes (n<species>_g<copy>) and a species tree's are species (n<species>), so the two share no labels. treedist notices and compares them on the species each gene sits in, asking "does this family's tree recover the species tree?", and says so on stderr. It works only when the family is single-copy, so the mapping is one-to-one; a family with two copies in some genome is refused, naming the genomes at fault, rather than answered with a plausible number. Two trees of the same kind are compared as they are, with no such note.

A family rarely sits in every genome, so the two tip sets usually still differ after that mapping, even when the family is single-copy. Pass --restrict to score them on the genomes the family occupies. zombi2 tools format DIR --format markers names the single-copy families to choose from.

# fam72 here is a single-copy family from out/genomes/markers.tsv
zombi2 tools treedist out/genomes/gene_trees/gene_tree_fam72_extant.nwk \
                      out/species/species_extant.nwk --metric all --restrict