Error on Midpoint Method Rooting

42 views
Skip to first unread message

Nima Emami

unread,
Sep 2, 2012, 1:45:31 AM9/2/12
to dendrop...@googlegroups.com
Hi,

I am using python2.7, trying to root newick trees. For some reason, while certain trees work perfectly, other trees that are almost topologically identical induce infinite looping. 

Example:

>>> import dendropy
>>> def root(tree_string):
...         dendroTree = dendropy.Tree.get_from_string(tree_string, "newick")
...         dendroTree.reroot_at_midpoint(update_splits=False)
...         return dendroTree.as_string('newick')
...
>>> root('(HUMAN_Q8TDW4:0.27463,(PONAB_Q2IBE1:0.0,PANTR_Q2QLE9:0.0):0.01832,GORGO_Q2IBE8:0.02673)')
'[&R] (HUMAN_Q8TDW4:0.15068,((PONAB_Q2IBE1:0.0,PANTR_Q2QLE9:0.0):0.01832,GORGO_Q2IBE8:0.02673):0.12395);\n'
>>> root('(GORGO_Q0MQH3:0.00325,(HUMAN_Q6IBA0:0.0,PANTR_Q0MQH4:0.0):0.00014,PONAB_Q5RBE9:0.00325)')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in root
  File "build/bdist.linux-x86_64/egg/dendropy/dataobject/tree.py", line 1238, in reroot_at_midpoint
KeyboardInterrupt

Can anybody suggest why this is happening and / or suggest a solution? I greatly appreciate your assistance in resolving this, thank you!

-Nima

Chunxiang Li

unread,
Nov 20, 2012, 5:59:42 AM11/20/12
to dendrop...@googlegroups.com
Recently, I encountered a similar problem. After going through the source code of "reroot_at_midpoint" in Dendropy 3.12.0, it will induce infinite looping
when the midpoint should be one of the existing internal node. The following is the code fragment:

while cur_node is not mrca_node:
            if cur_node.edge.length > plen:
                target_edge = cur_node.edge
                head_node_edge_len = plen #cur_node.edge.length - plen
                plen = 0
                break
            elif cur_node.edge.length < plen:
                plen -= cur_node.edge.length
                cur_node = cur_node.parent_node
            else:
                break_on_node = cur_node
                #solution
                break         #when find the  midpoint, it should break the loop
My solution is to override the original function just adding "break" after finding the midpoint is on one node.  Waiting for other wiser solutions :) 

Jeet Sukumaran

unread,
Dec 4, 2012, 5:49:23 PM12/4/12
to DendroPy Users
I'll fix this in the next release. Perhaps you might like to submit
this as an issue on GitHub?
Reply all
Reply to author
Forward
0 new messages