How to correctly update an empty ete3.Tree object with a newick formatted tree string [Python]?

65 Views Asked by At

I'm creating a class that inherits from ete3.Tree. I want to add a newick formatted string to the object but I can't figure out the correct way to update the object. I want t2 below to be the same structure as t1 and by structure I mean to be the same as me build the t2 object like I did t1 but from an empty ete3.Tree object.

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'}

How can I do this? I understand that they will not be the same hash but the _children attribute looks different between the 2 instantiations.

Python version 3.6.4 
ete3 version: 3.1.1
0

There are 0 best solutions below