[Biopython] phylo loop through nodes in tree

Eric Talevich eric.talevich at gmail.com
Tue Aug 26 16:35:22 UTC 2014


On Tue, Aug 26, 2014 at 3:42 AM, <def87 at gmx.de> wrote:

>  Hi,
>
> I am trying to do a tree traversal with the phylo package (just loop over
> every node). I have read the tree into a Newick tree object. Now the class
> docu of TreeMixin shows me the available methods: _filter_search seems to
> be what I need because it says that it's for tree traversals. However I
> don't want to apply a filter because I want to loop over every node in the
> tree. That will probably be easy to realize after having understood how
> _filter_search works (something like filter = 1 = true for all = loop over
> all nodes). But there is no documentation for this function and I don't
> understand how it works by just reading what its arguments are:
> _filter_search(self, filter_func, order, follow_attrs)
> Could someone please tell me how to loop over every node (I need each node
> as a clade object, something like "for node in tree:")? I couldn't find
> anything regarding _filter_search in the cookbook.
>
> Regards,
> Robert
>

Hi Robert,

The method to traverse a Newick tree is called find_clades():
http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec237

Example:

from Bio import Phylo
tree = Phylo.read("example.nwk", "newick")
for clade in tree.find_clades(): print clade.name


I see now that this isn't explained very well in the tutorial; sorry about
that.

All the best,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20140826/4d5f9ab8/attachment.html>


More information about the Biopython mailing list