eaton-lab / toytree

A minimalist tree plotting library using toyplot graphs
http://eaton-lab.org/toytree
BSD 3-Clause "New" or "Revised" License
164 stars 28 forks source link

Unrooting does not preserve distances #43

Closed cndewey closed 3 years ago

cndewey commented 3 years ago

This may be due to some "legacy" behavior with the ete library, but unrooting a rooted tree does not preserve the pairwise distances between the leaves. A minimal example is shown below:

>>> import toytree
>>> toytree.__version__
'2.0.3'
>>> rooted_newick = "(A:2,(B:1,C:1):1);"
>>> t = toytree.tree(rooted_newick)
>>> unrooted_t = t.unroot()
>>> unrooted_t.write()
'(A:2,B:1,C:1);'

The correct unrooted tree in this case should be

'(A:3,B:1,C:1);'

The issue seems to be that the distance for one of the children of the root is not properly updated.

eaton-lab commented 3 years ago

Thanks @cndewey! I found and fixed the bug.

I changed the root and unroot functions quite a bit from ete so I think this bug was likely unique to toytree. Here is a demo of the new functionality: https://github.com/eaton-lab/toytree/blob/master/sandbox/unroot-dist.ipynb

The fix is now available on the master branch and will appear in the next tagged conda version.

eaton-lab commented 3 years ago

updated link: https://github.com/eaton-lab/toytree/blob/master/sandbox/43-unroot-dist.ipynb