0

Hello I have a tree such as :

>>> print(tree)

   /-A
--|
  |   /-B
   \-|
     |   /-C
      \-|
        |   /-D
         \-|
            \-E

 tree=Tree("(A,(B,C,(D,E)));") (ete3 function)

And I'm looking for a way to see the closest leaves to a particular leaf.

Here for instance the leaves most closely related to C are D and E. The leaf most closely related to D is E The the leaves most closely related to B are C, D and E.

Grendel
  • 783
  • 4
  • 12

1 Answers1

0

the definition of "closest" is tricky in this context, but what you describe can easily be achieved by the following code (note that the tree in your code was missing a parenthesis):

In [1]: from ete3 import Tree
   ...:
   ...: tree=Tree("(A,(B,(C,(D,E))));")
   ...: c_node  = tree & 'C'
   ...: for sister_node in c_node.get_sisters(): # there might be multifurcations therefore the loop
   ...:     print(sister_node.get_leaf_names())
   ...:
['D', 'E']
jhc
  • 1,671
  • 3
  • 13
  • 16