niemasd / TreeSwift

TreeSwift: Fast tree module for Python 3
https://niema.net/TreeSwift
GNU General Public License v3.0
75 stars 14 forks source link

tree.diameter() does not take single branch into consideration #14

Closed YaosenLin closed 3 years ago

YaosenLin commented 4 years ago
dists = sorted(d[c]+c.edge_length for c in node.children)
d[node] = dists[-1]; max_pair = dists[-1]+dists[-2]

the dists[-2] can cause index out of range exception.

niemasd commented 3 years ago

Thanks for catching that, and sorry for the delay! Fixed in TreeSwift v1.1.17:

https://github.com/niemasd/TreeSwift/blob/ea90060a1570fbdf013762504a83fec3741e436e/treeswift/Tree.py#L295-L300