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

feat: Add cophenetic_distances function to rust and integrate binding #70

Open
lsetiawan opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@lsetiawan
Copy link
Member

Overview

Currently, there is a cophenetic_distances function in the python package:

def cophenetic_distances(v, unrooted=False):
# Should be very similar to dist_nodes in ape
# Ancestry
A = _get_ancestry(v)
if unrooted:
A[-1, -1] = A.max() - 1
n_leaves = len(v) + 1
# Distance matrix
D = np.zeros((2 * n_leaves - 1, 2 * n_leaves - 1), dtype=np.uint32)
# Keep track of visited nodes
all_visited = []
for i in range(n_leaves - 1):
c1, c2, p = A[n_leaves - i - 2, :]
for visited in all_visited[:-1]:
dist_from_visited = D[p, visited] + 1
# c1 to visited
D[c1, visited] = dist_from_visited
D[visited, c1] = dist_from_visited
# c2 to visited
D[c2, visited] = dist_from_visited
D[visited, c2] = dist_from_visited
# c1 to c2: path length = 2
D[c1, c2] = 2
D[c2, c1] = 2
# c1 to parent: path length = 1
D[c1, p] = 1
D[p, c1] = 1
# c2 to parent: path length = 1
D[c2, p] = 1
D[p, c2] = 1
all_visited.extend([c1, c2, p])
return D[:n_leaves, :n_leaves]

We need to port this over to Rust -> Create Binding -> Integrate back to Python.

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