[Biopython] getting the parent of a Clade
Michael Thon
mike.thon at gmail.com
Mon Nov 1 05:41:41 UTC 2010
On Oct 31, 2010, at 8:23 PM, Eric Talevich wrote:
>
>
> 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?
>
>
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.
Thanks
Mike
> 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