[Biopython-dev] String representation of trees in Bio.Phylo

Brad Chapman chapmanb at 50mail.com
Sun Apr 4 17:19:03 UTC 2010


Hi Eric;

> The new phylogenetics module Bio.Phylo supports a few new ways of displaying
> trees. I'm trying to decide which of these should be used as the informal
> string representation for whole trees, i.e. what happens when you type
> "print tree" for some newly parsed tree object.
[...[
> The pretty_print function, with the show_all option, uses 'repr' recursively
> to display the tree's nodes. I think this is probably the best choice for
> Tree.__str__, but it can be a bit cluttered if a lot of information is
> attached to each node/subtree/clade.
> 
> >>> Phylo.pretty_print(tree, show_all=True)
> Phylogeny(rooted='True', description='phyloXML allows to use either a
> "branch_length" attribute...', name='example from Prof. Joe Felsenstein's
> book "Inferring Phyl...')
>     Clade()
>         Clade(branch_length='0.06')
>             Clade(branch_length='0.102', name='A')
>             Clade(branch_length='0.23', name='B')
>         Clade(branch_length='0.4', name='C')

I like this one. Agreed that it could get ugly, but I think it shows
the structure and associated information well.


> As an alternative, we could print the tree as ASCII art, as some other
> toolkits do. However, this function is very limited -- it doesn't print
> internal node labels, and trees of more than a couple hundred nodes will
> look strange, since the drawing is compressed into a fixed number of
> character columns (default 80).
> 
> >>> Phylo.draw_ascii(tree)
>              __________________ A
>   __________|
> _|          |___________________________________________ B
>  |
>  |___________________________________________________________________________ C

This is a good idea. I think this is more useful than the current
pretty_print without show_all for getting a quick overview of the
tree.

Brad



More information about the Biopython-dev mailing list