[Biopython] getting the parent of a Clade

Eric Talevich eric.talevich at gmail.com
Sun Oct 31 19:23:25 UTC 2010


On Sun, Oct 31, 2010 at 1:57 PM, Eric Talevich <eric.talevich at gmail.com>wrote:

> 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?
>
>
I added a cookbook entry on the Biopython wiki for this problem:
http://biopython.org/wiki/Phylo_cookbook#Get_the_parent_of_a_clade

Cheers,
Eric



More information about the Biopython mailing list