etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
782 stars 212 forks source link

root label not handled in tree.write() #663

Open cmayer opened 1 year ago

cmayer commented 1 year ago

I assign node labels to all nodes, including inner nodes: I traverse the tree with for n in t.traverse(): n.name = something

This assigns a name also to the root, which is what I want. If I call t.render("mytree.pdf", w=400, units="mm", tree_style=ts) with a ts that draws all node labels, according one of the examples in the docs: for each node I do name_face = AttrFace("name", fsize=10) faces.add_face_to_node(name_face, node, column=1, position="float")

the t.render also prints a node label at the root, which is what I want.

But the simple call: t.write(outfile="tree-with-node-labels-numbers.tre", format=8) does not write a label to the root. I tried different formats, but no luck. I am working with rooted trees and the tree that is written to the file is rooted. Do I miss something or is this a bug or a feature? I think it would be nice if the root node would also be written to the newick file if it is drawn with the show and render commands.

Gullumluvl commented 1 year ago

You should use:

t.write(outfile="tree-with-node-labels-numbers.tre", format=8, format_root_node=True)