postorder docs

7 views
Skip to first unread message

Yan Wong

unread,
Sep 4, 2015, 7:13:55 AM9/4/15
to DendroPy Users

postorder_node_iter(filter_fn=None)[source]
Post-order iterator over nodes of tree.

Visits nodes in self, with each node visited first followed by its children. 

Shouldn't that be "each node visited after its children"?

Yan

Jeet Sukumaran

unread,
Sep 4, 2015, 11:15:51 AM9/4/15
to dendrop...@googlegroups.com
Yes, it should. I will correct it. Thanks for pointing it out.
> --
> You received this message because you are subscribed to the Google
> Groups "DendroPy Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dendropy-user...@googlegroups.com
> <mailto:dendropy-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeetsu...@gmail.com
--------------------------------------
Blog/Personal Pages:
http://jeetworks.org/
GitHub Repositories:
http://github.com/jeetsukumaran
Photographs (as stream):
http://www.flickr.com/photos/jeetsukumaran/
Photographs (by galleries):
http://www.flickr.com/photos/jeetsukumaran/sets/
--------------------------------------

Yan Wong

unread,
Sep 4, 2015, 1:18:44 PM9/4/15
to DendroPy Users
On thew subject of documentation, https://pythonhosted.org/DendroPy/library/treemodel.html?highlight=find_node#dendropy.datamodel.treemodel.Tree.find_node says "will return all nodes which have an attribute ‘genes’ and this value is not None.". But as I understand, this only returns the *first* node for which that is true (rather than all nodes), which is what the other parts of the documentation imply.

In fact, a function which returns (say) all nodes according to a filter would be helpful for me (I'm trying to match node labels against a regexp).

Jeet Sukumaran

unread,
Sep 4, 2015, 9:46:48 PM9/4/15
to dendrop...@googlegroups.com
You are right, this is another documentation issue that needs to be
corrected.

I think it would be reasonable to support a function along the lines
that you describe, called, e.g. "find_nodes()". Will add it to the
"TODO" pile as well. Thanks for the suggestion.

-- jeet

Jeet Sukumaran

unread,
Sep 4, 2015, 9:51:40 PM9/4/15
to dendrop...@googlegroups.com
If you need the below-described functionality immediately, something
like the following should work:

nodes = [nd for nd in tree if filter_fn(nd)]

or equivalently:

nodes = [nd for nd in tree.preorder_node_iter(filter_fn)]

Of course, if you do not need the entire collection of nodes, then
simply passing the filter function to the iterator works as well:

for nd in tree.preorder_node_iter(filter_fn):
... do stuff here ...

On 9/4/15 1:18 PM, Yan Wong wrote:

Yan Wong

unread,
Sep 5, 2015, 6:18:24 AM9/5/15
to DendroPy Users
On Saturday, 5 September 2015 02:51:40 UTC+1, Jeet Sukumaran wrote:
If you need the below-described functionality immediately, something
like the following should work:

Thanks. I actually meant to say "taxa" rather than "nodes", e.g. grep using a regexp throughout the taxon namespace. But your alternative will work find for normal trees.

Cheers

Yan
Reply all
Reply to author
Forward
0 new messages