etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
786 stars 214 forks source link

ZeroDivisionError: float division by zero #273

Open codemeleon opened 7 years ago

codemeleon commented 7 years ago

Hi,

I am trying draw circular tree style using "from ete3 import Tree, TreeStyle, NodeStyle, SeqMotifFace". However, I am following error


ZeroDivisionError Traceback (most recent call last)

in () 109 node.add_face(seqFace, i, "aligned") 110 --> 111 n = tree.render(file_name="folA_tempS.png", tree_style=ts 112 # h=1000, w=100, 113 # dpi=300, #units="px" /home/devil/anaconda3/lib/python3.4/site-packages/ete3/coretype/tree.py in render(self, file_name, layout, w, h, tree_style, units, dpi) 1360 return drawer.render_tree(self, file_name, w=w, h=h, 1361 layout=layout, tree_style=tree_style, -> 1362 units=units, dpi=dpi) 1363 1364 def copy(self, method="cpickle"): /home/devil/anaconda3/lib/python3.4/site-packages/ete3/treeview/drawer.py in render_tree(t, imgName, w, h, layout, tree_style, header, units, dpi) 102 n.add_feature("_nid", nid) 103 scene, img = init_scene(t, layout, tree_style) --> 104 tree_item, n2i, n2f = render(t, img) 105 106 scene.init_values(t, img, n2i, n2f) /home/devil/anaconda3/lib/python3.4/site-packages/ete3/treeview/qt4_render.py in render(root_node, img, hide_root) 287 update_branch_lengths(root_node, n2i, n2f, img) 288 else: --> 289 img._scale = crender.calculate_optimal_scale(root_node, n2i, rot_step, img) 290 #print "OPTIMAL circular scale", img._scale 291 update_branch_lengths(root_node, n2i, n2f, img) /home/devil/anaconda3/lib/python3.4/site-packages/ete3/treeview/qt4_circular_render.py in calculate_optimal_scale(root_node, n2i, rot_step, img) 380 for node in visited_nodes: 381 if n2i[node].heights[5]: --> 382 new_scale = (rad - (n2sumwidth[node] + root_opening)) / n2sumdist[node] 383 min_alg_scale = min(new_scale, min_alg_scale) if min_alg_scale is not None else new_scale 384 if min_alg_scale is not None and min_alg_scale > best_scale: ZeroDivisionError: float division by zero

This error doesn't appear with normal tree style.

Thanks.

jhcepas commented 7 years ago

are all the branches zero-length in your tree? I think that might be the cause

codemeleon commented 7 years ago

Yes. There were some branches of zero-length. I have replaced them with very small value. Now it working.

Thanks

jhcepas commented 7 years ago

let's keep the issue open. I think this should be handled by ETE