ete icon indicating copy to clipboard operation
ete copied to clipboard

Initial node is ignored when using a list in get_common_ancestor

Open danpal96 opened this issue 3 years ago • 2 comments

Manjaro Linux x86_64 python 3.8.8 ete3 3.1.2

The TreeNode get_common_ancestor method says in its docstring:

Returns the first common ancestor between this node and a given list of 'target_nodes'.

In this example:

tree = Tree("(A,(B,C));")

A = tree & "A"
B = tree & "B"
C = tree & "C"

anc_1 = A.get_common_ancestor(B)
anc_2 = A.get_common_ancestor([B, C])

anc_1 is the common ancestor between A and B, but anc_2 is the common ancestor of only B and C. I don't think the second case is intended according to the docstring.

danpal96 avatar Apr 28 '21 19:04 danpal96

thanks, this is a known behavior. When using a list as an argument, it finds the common ancestor of the nodes in the list. If you only provide a single node, it finds the common ancestor of that node and the seed node initiating the search. I agree this is counter-intuitive, maybe we can modify it for the next ete4 version, but not really sure what would be the most elegant approach... Let's keep it open for discussion @dengzq1234 @jorgebotas @jordibc

jhcepas avatar Apr 29 '21 06:04 jhcepas

I think that a clarification of this two behaviors in the docstring would be enough for now

danpal96 avatar Apr 29 '21 15:04 danpal96