Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch lengths in output newick tree appear to be double distances from distance matrix #13

Open
apetkau opened this issue Oct 31, 2024 · 0 comments

Comments

@apetkau
Copy link
Member

apetkau commented Oct 31, 2024

The branch lengths in the output newick tree when performing e.g., gas mcluster appear to be double the distances in the distance matrix.

Example Input

For example, given the following distance matrix:

dists	sample1	sample2	sample3
sample1	0	1	2
sample2	1	0	3
sample3	2	3	0

From https://github.com/phac-nml/gasclustering/blob/main/tests/data/clusters/expected_tree_hamming.nwk

Example output

The below is an example newick tree:

((sample2:1.000000,sample1:1.000000):0.75,sample3:2.500000);

From https://github.com/phac-nml/gasclustering/blob/main/tests/data/clusters/expected_tree_hamming.nwk

Comparison

The distance from the above distance matrix between sample1 and sample2 is 1.

But, if you add up the branch lengths in the newick file between sample1 and sample2 you get 1 + 1 = 2.

Possible cause

A possible cause is in the buildNewick function:

def buildNewick(self,node, newick, parentdist, leaf_names):
if node.is_leaf():
return "%s:%f%s" % (leaf_names[node.id], parentdist - node.dist, newick)
else:
if len(newick) > 0:
newick = f"):{(parentdist - node.dist) / 2}{newick}"
else:
newick = ");"

Internal branch lengths are being divided by 2 here, but not branch lengths leading directly to leaves.

Credit

Credit goes to @kylacochrane, @apetkau, and @jrober84 for finding the issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant