1

I wrote a program which calculates the distance between two trees. The trees are already rooted.

I want to make sure that the trees are rooted on the same root or outgroup.

As far as I know, in ete2 one can only set the root but cannot find the root and root the other tree on the same one.

I want to find the root in one tree and set the same root in the other. So the trees are rooted in the same way.

#>>> print t1
#
#         /-aaaaaaaaad
#      /-|
#   /-|   \-aaaaaaaaae
#  |  |
#--|   \-aaaaaaaaaa
#  |
#  |   /-aaaaaaaaab
#   \-|
#      \-aaaaaaaaac
#>>> print t2
#
#      /-aaaaaaaaaa
#   /-|
#  |  |   /-aaaaaaaaab
#  |   \-|
#--|      \-aaaaaaaaac
#  |
#  |   /-aaaaaaaaad
#   \-|
#      \-aaaaaaaaae
#

So in t1, the tree is rooted on the outgroup ending with b and c. I want to get this outgroup and root t2 on the same group.

Does anyone know if there is the posibility to make sure the trees are rooted the same? Or does another package include such a method?

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130
IssnKissn
  • 81
  • 1
  • 1
  • 6

1 Answers1

1

the etetoolkit provides the set_outgroup method for rooting trees. If you just want to have the same root in two trees for topology comparison, the simplest approach would be to pick the same tip name as the root in both trees.

from ete2 import Tree
# generate 2 random trees
t1 = Tree()
t2 = Tree()
t1.populate(5)
t2.populate(5)
# root both to the same tip name
root = t1.get_leaf_names()[0]
t1.set_outgroup(root)
t2.set_outgroup(root)

print t1
print t2
#
#  /-aaaaaaaaaa
#-|
# |   /-aaaaaaaaab
#  \-|
#    |   /-aaaaaaaaac
#     \-|
#       |   /-aaaaaaaaad
#        \-|
#           \-aaaaaaaaae
#
#  /-aaaaaaaaaa
# |
#-|      /-aaaaaaaaad
# |   /-|
# |  |   \-aaaaaaaaae
#  \-|
#    |   /-aaaaaaaaab
#     \-|
#        \-aaaaaaaaac
jhc
  • 1,671
  • 3
  • 13
  • 16
  • Thank's a lot. I was thinking about this, too. But my problem is not setting the root, but getting the root. I specified my question above, maybe this helps. Thanks – IssnKissn Apr 01 '14 at 13:39
  • you can use the tree.search_nodes() method to locate a specific leaf. Then, root to it. Alternatively, the tree.get_common_ancestor() allows you to find the first internal node connecting a given set of terminal nodes, so you could use it to select the same rooting point in both trees. – jhc Jun 21 '14 at 06:47