ete icon indicating copy to clipboard operation
ete copied to clipboard

Removing dist from internal root node for write

Open moorembioinfo opened this issue 3 years ago • 1 comments

Hi!

I want to output the internal root node using format_root_node=True but ETE adds the dist (0). So:

t = Tree("(A:1,(B:1,(E:1,D:1)Internal_1:0.5)Internal_2:0.5)Root;", format=1)
t.write(format=1, format_root_node=True, outfile='outtree.newick')

Will output:

(A:1,(B:1,(E:1,D:1)Internal_1:0.5)Internal_2:0.5)Root:0;

If I first remove the dist feature from the TreeNode: t.get_tree_root().features.remove('dist') the output still contains Root:0;

Thanks in advance for any help with this!


Further info:

It appears the dist isn't being deleted. Though:

t.get_tree_root().features

Will no longer note 'dist'

print(t.get_tree_root().dist)

Will output '0.0' (so dist is still being stored rather than added upon write)

moorembioinfo avatar May 07 '21 14:05 moorembioinfo

One workaround:

t.__dict__['_dist']=''    
treestring = t.write( format=1, format_root_node=True).replace(':?','')    
with open("tree.newick", 'w') as outtree:        
    outtree.write(treestring)

moorembioinfo avatar May 18 '21 12:05 moorembioinfo