[Biopython] getting the parent of a Clade

Eric Talevich eric.talevich at gmail.com
Tue Nov 2 01:20:30 UTC 2010


On Mon, Nov 1, 2010 at 1:41 AM, Michael Thon <mike.thon at gmail.com> wrote:

>
> On Oct 31, 2010, at 8:23 PM, Eric Talevich wrote:
> >
> > Is the operation you're doing here part of something you'd like to see
> implemented as a tree method?
> >
> >
> Maybe - it seems to me that if I can access children of a clade from the
> clade, then I should also be able to go the other way and access the parent.
>  I don't know how often people would need this functionality though.
>
> Does a Clade contain a reference to its tree? I have a recursive function
> that does some crunching on a Clade and then recursively processes the child
> clades.  I could pass in  the tree object as well, but I figure that a Clade
> must know about its tree so there should be some way to access it.
>

PyCogent does work that way, but Bio.Phylo's data structure is simpler -- a
Tree has a single root Clade (tree.root or tree.clade), and each Clade has a
plain Python list of child Clades (clade.clades), all the way down. It
doesn't track any references to the parent or the original tree, so the tree
can never have an inconsistent internal state... because there is no
internal state.

I haven't needed the parent references so far for the Tree/Clade methods or
my own scripts, surprisingly. Calling get_path once or twice has been
enough. (I could probably speed up common_ancestor by using the all_parents
dictionary approach in the cookbook, at the expense of memory.)

Do you or anyone else want to try plugging that all_parents function into
your code to see if it helps significantly? If it does, I could add it as a
Tree/Clade method in the next Biopython release.

Best,
Eric



More information about the Biopython mailing list