[Biopython-dev] String representation of trees in Bio.Phylo
Eric Talevich
eric.talevich at gmail.com
Fri Apr 9 06:39:27 UTC 2010
Hi Brad et al.,
I guess I can turn this into a specific proposal now, and if no one objects,
just do it:
On Sun, Apr 4, 2010 at 1:19 PM, Brad Chapman <chapmanb at 50mail.com> wrote:
> 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.
>
Action items:
1. Move the pretty_print(show_all=True) code into Tree.__str__, leaving
__repr__ as it is, since pretty_print relies on it.
2. Remove the pretty_print function from Bio.Phylo._utils, dropping the
show_all=False functionality altogether since Tree.__str__ is more
informative and draw_ascii is prettier.
Wrinkle: Making Subtrees work the same way would break a few things -- I've
been treating str(clade) as something that generates a short, useful label
for the node, like clade.name if it's available. For example, draw_ascii
uses it this to get taxon labels.
This means "print tree" shows the whole recursive object tree, while "print
tree.root" shows a label for the node, which is just the class name
("Clade") if no name is set. Are we OK with this?
Thanks,
Eric
> 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