Tracy Heath
unread,Mar 4, 2012, 2:37:32 PM3/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DendroPy Users
Dear DendroPy Users:
Jeet recently sent me some clarifications on how the annotate function
works. He wrote the following:
So, you would take advantage of Python's dynamic on-the-fly extension
of object properties to create the fields that you need, and then
specify that these fields are annotations.
node.var = 0.3
node.annotate('var')
This way you don't have to worry about the formatting etc.: you can
write out standard hot comments or NHX or whatever. In principle, you
should also be able to write out NExML annotations, but I *think* it
is broken. Furthermore, the values that will be written out will be
the values of the object, so you can create the annotation in one part
of the code, and update it in other places.
More extended example:
tree.are_cats_are_cuter_than_dogs = True
tree.annotate('are_cats_are_cuter_than_dogs')
tree.but_dogs_are_cute_too = True
tree.annotate('but_dogs_are_cute_too')
for nd in tree.postorder_node_iter():
nd.size = None
nd.annotate('size')
nd.color = None
nd.annotate('color')
...
...
(some other part of the code)
...
...
for nd in tree.postorder_node_iter():
nd.size = my_fancy_size_calculator(nd)
if nd.size / nd.age > 1:
nd.color = 'green'
else:
nd.color = 'red
Another example:
The client-code way to write a newick string is:
tree.as_string("newick", ...)
For example:
#! /usr/bin/env python
import random
import dendropy
tree = dendropy.Tree.get_from_string("(A, (B, (C,D)))", "newick")
tree.field = "hello"
tree.annotate('field')
for nd in tree.postorder_node_iter():
nd.field = random.gauss(0, 1)
nd.annotate('field')
print tree.as_string("newick",
annotations_as_comments=True)