agormp / phylotreelib

Library for analyzing and manipulating phylogenetic trees
GNU General Public License v3.0
11 stars 1 forks source link

bug in treedist() function #3

Closed EDohmen closed 1 year ago

EDohmen commented 1 year ago

Hey again, I detected a bug in the treedist() function, which returns 0.0 (i.e. no difference) between two trees with different topologies such as these (ete3 normalised robinson-foulds dist for comparison):

import phylotreelib as pt
import ete3
a = pt.Tree.from_string('(A,(B,(C,D)));')
b = pt.Tree.from_string('((A,B),(C,D));')
a.treedist(b)

>0.0

tree1 = ete3.Tree('(A,(B,(C,D)));')
tree2 = ete3.Tree('((A,B),(C,D));')
tree1.compare(tree2)['norm_rf']
>0.5

Is this known?

agormp commented 1 year ago

Thanks for the interest!

The .treedist() method, as currently implemented, treats the trees as unrooted when computing the Robinson-Foulds symmetric distance (and the two trees in your example are then identical). I should implement the rooted version also. (And in fact I should implement other measures, in addition to RF, that are less sensitive to e.g., moving a single taxon)

agormp commented 1 year ago

I have now implemented the rooted version of Robinson-Foulds (phylotreelib version 1.20.1, available at PyPi and GitHub). Syntax is as follows (note new method name. Also note that default is now to return the un-normalised measure):

rf_unrooted = tree1.treedist_RF(tree2)
rf_unrooted_normalised = tree1.treedist_RF(tree2, normalise=True)
rf_rooted = tree1.treedist_RF(tree2, rooted=True)
rf_rooted_normalised = tree1.treedist_RF(tree2, rooted=True, normalise=True)

While I was at it, I also added a method to compute the path difference distance, as described in Steel and Penny (1993) and used in various other software packages:

pd = tree1.treedist_pathdiff(tree2)

I plan to also implement the branch length-aware method from Kuhner and Felsenstein, 1994, and also the information-theoretic method from Smith, 2020.

Closing for now, but let me know if there are any issues.

Kind regards, Anders

EDohmen commented 1 year ago

Cool, thanks a lot, sounds awesome! I will try it out!