You can annotate ete trees using any type of data. Just give a name to every node, create a tree structure using such names, and annotate the tree with the coordinates.
from ete2 import Tree
name2coord = {
'a': [1, 1],
'b': [1, 1],
'c': [1, 0],
'd': [0, 1],
}
# Use format 1 to read node names of all internal nodes from the newick string
t = Tree('((a:1.1, b:1.2)c:0.9, d:0.8);', format=1)
for n in t.get_descendants():
n.add_features(coord = name2coord[n.name])
# Now you can operate with the tree and node coordinates in a very easy way:
for leaf in t.iter_leaves():
print leaf.name, leaf.coord
# a [1, 1]
# b [1, 1]
# d [0, 1]
print t.search_nodes(coord=[1,0])
# [Tree node 'c' (0x2ea635)]
You can copy, save and restore annotated trees using pickle:
t.copy('cpickle')
# or
import cPickle
cPickle.dump(t, open('mytree.pkl', 'w'))
tree = cPickle.load(open('mytree.pkl'))