Displaying attributes on Tree nodes ETE
1
0
Entering edit mode
8.9 years ago
moranr ▴ 290

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 • 3.0k views
ADD COMMENT
3
Entering edit mode
8.9 years ago
jhc ★ 3.0k

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")
...
ADD COMMENT
0
Entering edit mode

Ah, thank you.

ADD REPLY

Login before adding your answer.

Traffic: 1846 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6