feat: cophenetic distances from matrix format#34
Merged
Neclow merged 2 commits intosbhattlab:mainfrom May 16, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR updates the cophenetic distance functions to work uniformly with vector and matrix inputs in both Rust and Python while removing the deprecated "unrooted" argument from the Rust API. Key changes include:
- Removing the "unrooted" parameter and adding a new function (cophenetic_distances_with_bls) to handle branch lengths in Rust.
- Modifying the Python binding and test cases to align the API with external libraries ("ape" and "ete3").
- Bumping the Rust version from 0.1.1 to 0.2.0.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| py-phylo2vec/tests/test_metrics.py | Updated tests to use np.allclose and introduced a MAX_N_LEAVES_COPH constant for testing scope. |
| py-phylo2vec/src/lib.rs | Removed the unrooted argument and added a new function for branch-length based cophenetic distances. |
| py-phylo2vec/phylo2vec/metrics/pairwise.py | Adjusted function signature to accept vector or matrix and added a deprecation warning for unrooted. |
| phylo2vec/src/tree_vec/ops/vector.rs | Modified the cophenetic distance computation to incorporate branch lengths from the matrix. |
| phylo2vec/src/tree_vec/ops/matrix/mod.rs | Added tests and documentation for the new matrix-based cophenetic distances computation. |
| phylo2vec/Cargo.toml | Version bump from 0.1.1 to 0.2.0 |
Comments suppressed due to low confidence (1)
phylo2vec/src/tree_vec/ops/vector.rs:393
- Verify that the logic for accumulating branch lengths (using 'bl1' and 'bl2') in the distance update loop correctly reflects the intended cophenetic distance computation; a brief comment explaining the math here would enhance code clarity.
let dist1 = dist[p][visited] + bl1;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cophenetic distance functions work with a vector (topological distance) or a matrix (traditional cophenetic distance with branch lengths) in Rust and Python.
Argument
unrootedwas removed from the Rust API: the priority is to be compatible withapeandete3.apepreserves branch lengths with unrooting, and so doesete3with themode='keep'option (etetoolkit/ete#344), meaning that there's no need for an optional "unrooted" argument in these functions.Bumped the rust version from 0.1.1 --> 0.2.0