Dendropy でいくつかの系統発生学を行っています。チュートリアルに従って、フィルター (ラムダ関数) を使用してツリーのすべての葉をトラバースしようとしています。
ラムダ関数を使用すると、反復子が leaf_iter の場合にエラーが発生しますが、反復子が他のもの (postorder_node_iterate など) の場合は発生しません。私は何が欠けていますか?
トレースバックは数百行の長さなので、抜粋を示します。
Traceback (most recent call last):
File "<pyshell#274>", line 1, in <module>
for node in tree_test.leaf_iter(survival):
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 915, in leaf_iter
for node in self.seed_node.leaf_iter(filter_fn=filter_fn):
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 2444, in leaf_iter
for node in self.postorder_iter(filter_fn):
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 2427, in postorder_iter
if filter_fn is None or filter_fn(node):
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 2441, in <lambda>
filter_fn = lambda x: x.is_leaf() and filter_fn(x) or None
[... line 2441 ...]
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 2441, in <lambda>
filter_fn = lambda x: x.is_leaf() and filter_fn(x) or None
File "build\bdist.win32\egg\dendropy\dataobject\tree.py", line 2537, in is_leaf
return bool(not self._child_nodes)
RuntimeError: maximum recursion depth exceeded while calling a Python object
問題をテストするには、チュートリアルからほとんど抜粋した次のコードを使用できます。
#call a bit of modules and build a simulated tree
import dendropy
import random
from dendropy import TaxonSet, Tree, TreeList, treesim
taxa = dendropy.TaxonSet(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
tree_test = treesim.birth_death(0.4, 0.1, ntax=8, taxon_set=taxa, repeat_until_success=True)
#define an evolutionary character
def evolve_char(tree, start=1.0):
for node in tree.preorder_node_iter():
if node.parent_node is None:
node.value = 1.0
else:
node.value = random.gauss(node.parent_node.value, node.edge.length)
return tree
#evolve the character on the simulated tree
evolve_char(tree_test)
#positive_char select the nodes with positive character
positive_char = lambda node: True if node.value > 0. else False
#iter with postorder_node_iter (no problem)
for node in tree_test.postorder_node_iter():
print("Node %s with value %s" % (node.taxon, node.value))
for node in tree_test.leaf_iter(positive_char):
print("Node %s with value %s" % (node.taxon, node.value))
#iter with leaf_iter without filtering (no problem)
for node in tree_test.leaf_iter():
print("Node %s with value %s" % (node.taxon, node.value))
#iter with leaf_iter and filtering (problem!)
for node in tree_test.leaf_iter(positive_char):
print("Node %s with value %s" % (node.taxon, node.value))