如何使用newick格式的树字符串[Python]正确更新空的ete3.Tree对象?

2024-05-13 23:22:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个从ete3.Tree继承的类。我想向对象添加一个newick格式的字符串,但我想不出更新对象的正确方法我希望下面的t2t1的结构相同,所谓结构,我的意思是与我一样构建t2对象,就像我构建t1一样,但它是从一个空的ete3.Tree对象生成的。

import ete3
newick = "(((petal_width:0.098798,petal_length:0.098798):0.334371,sepal_length:0.433169):1.171322,sepal_width:1.604490);"
t1 = ete3.Tree(newick=newick, name="hello")
t2 = ete3.Tree(name="hello")
t2.add_child(child=ete3.Tree(newick))
print(t1 == t2)
print(t1.__dict__)
print()
print(t2.__dict__)
# False
# {'_children': [Tree node '' (-0x7fffffffed514b1c), Tree node 'sepal_width' (0x12aeb4a9)], '_up': None, '_dist': 0.0, '_support': 1.0, '_img_style': None, 'features': {'dist', 'support', 'name'}, 'name': 'hello'}

# {'_children': [Tree node '' (-0x7fffffffed514ba1)], '_up': None, '_dist': 1.0, '_support': 1.0, '_img_style': None, 'features': {'dist', 'support', 'name'}, 'name': 'hello'}

我该怎么做?我知道它们将不是相同的散列,但是_children属性在两个实例化之间看起来不同

Python version 3.6.4 
ete3 version: 3.1.1

Tags: 对象namenonetreesupporthellodistwidth