1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
from ete3 import Tree
# Load an unrooted tree. Note that three branches hang from the root
# node. This usually means that no information is available about
# which of nodes is more basal.
t = Tree('(A,(H,F),(B,(E,D)));')
print("Unrooted tree")
print(t)
# /-A
# |
# | /-H
#---------|---------|
# | \-F
# |
# | /-B
# \--------|
# | /-E
# \--------|
# \-D
#
# Let's define that the ancestor of E and D as the tree outgroup. Of
# course, the definition of an outgroup will depend on user criteria.
ancestor = t.get_common_ancestor("E","D")
t.set_outgroup(ancestor)
print("Tree rooted at E and D's ancestor is more basal that the others.")
print(t)
#
# /-B
# /--------|
# | | /-A
# | \--------|
# | | /-H
#---------| \--------|
# | \-F
# |
# | /-E
# \--------|
# \-D
#
# Note that setting a different outgroup, a different interpretation
# of the tree is possible
t.set_outgroup( t&"A" )
print("Tree rooted at a terminal node")
print(t)
# /-H
# /--------|
# | \-F
# /--------|
# | | /-B
# | \--------|
#---------| | /-E
# | \--------|
# | \-D
# |
# \-A
|