简体   繁体   English

python在同一根节点上根两棵树

[英]python root two trees on the same root node

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. 据我所知,在ete2中,一个树只能设置根,而不能找到该树的根,而另一棵树也可以在同一棵树上建立根。

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. 因此,在t1中,树的根源是以b和c结尾的外群。 I want to get this outgroup and root t2 on the same group. 我想将此outgroup和root t2放在同一组中。

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? 还是其他软件包中包含这种方法?

the etetoolkit provides the set_outgroup method for rooting trees. etetoolkit提供了用于生根树的set_outgroup方法。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM