[Biopython] getting the parent of a Clade

Eric Talevich eric.talevich at gmail.com
Sun Oct 31 17:57:07 UTC 2010


On Sun, Oct 31, 2010 at 12:03 PM, Michael Thon <mike.thon at gmail.com> wrote:

> I have a Clade object and I need to access its parent clade.  I thought
> that clade.root should do this but this seems to contain a reference to
> itself:
>
> (Pdb) main_clade == main_clade.root
> True
>
> Is there some other way?
> Thanks
> Mike
>
>
Hi Mike,

You can do this, assuming you have the original tree object (call it
"tree"):

parent = tree.get_path(main_clade)[-2]

This is an O(n) operation on the tree, so if you need to do it repeatedly on
a large tree, it's faster to call tree.get_path(clade) once outside the loop
and then reuse the resulting list.

Is the operation you're doing here part of something you'd like to see
implemented as a tree method?

-Eric



More information about the Biopython mailing list