This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Displaying attributes on Tree nodes ETE

Hi,

I am trying to display attributes of a tree. The tree has been loaded in newick format with attributes (annotated in the newick file) e.g.:

"Genes" , "Identical", "Duplicated" etc.

When I try to make an image of the tree with these attributes I get an error. I am able to print the attributes and tree as ascii.

t=Tree('sampleGeneTree.tree', format=1)

ts = TreeStyle()
ts.show_leaf_name = True

def my_layout(node):
    #dont include root
    if not node.is_leaf() and node.up:
        #add attributes 
        node.add_face(TextFace(node.name), column=1, position="branch-right")
        node.add_face(AttrFace(node.Genes, text_prefix="/"), column=2, position="branch-top")

ts.layout_fn = my_layout

ts.show(tre_style=ts)

This gives this error :

AttributeError: 'TreeNode' object has no attribute '10'

10 is the value of the node.Genes.

What am I doing wrong here?

Thanks

ete phylogenetics python

1 answer

AttrFace receives the name of an attribute as the first argument. Use TextFace for static values

...
node.add_face(AttrFace("Genes", text_prefix="/"), column=2, position="branch-top")
...

Ah, thank you.

Log in to answer this question.