jeetsukumaran/DendroPy — pull request #4 by evoling (2012-11-15 20:21:29+00:00)
Title: translate table in nexus trees block

I've written some code to add an optional "translate" table in a nexus trees block. It should work fine with the node_label_compose_func.

If you want unit tests I'd be happy to try, but I'll need some advice (I get lots of errors with the unit tests already there). The following script demonstrates that these revisions work.

# test_setup.py usage:
# python setup.py build
# cd build/lib
# ipython
# %run /path/to/test_setup.py
from dendropy import TaxonSet, Tree, TreeList
from StringIO import StringIO

t1 = Tree(stream=StringIO("((A,B),(C,D))"), schema="newick")
t2 = Tree(stream=StringIO("((A,C),(B,D))"), schema="newick")
tlist = TreeList([t1,t2])

print "#### original"
print tlist.as_string("nexus")
print "#### with translate block"
print tlist.as_string("nexus", translate_in_trees_block=True)

def lowercase_labels(node):
try:
return node.taxon.label.lower()
except AttributeError:
return None

print "#### original + label func"
print tlist.as_string("nexus", node_label_compose_func=lowercase_labels)
print "#### with translate block + label func"
print tlist.as_string("nexus", node_label_compose_func=lowercase_labels, translate_in_trees_block=True)