Skip to content

feat: cophenetic distances from matrix format#34

Merged
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:cophenetic_with_bls
May 16, 2025
Merged

feat: cophenetic distances from matrix format#34
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:cophenetic_with_bls

Conversation

@Neclow
Copy link
Collaborator

@Neclow Neclow commented May 16, 2025

Cophenetic distance functions work with a vector (topological distance) or a matrix (traditional cophenetic distance with branch lengths) in Rust and Python.

Argument unrooted was removed from the Rust API: the priority is to be compatible with ape and ete3. ape preserves branch lengths with unrooting, and so does ete3 with the mode='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

@Neclow Neclow requested a review from Copilot May 16, 2025 09:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

@Neclow Neclow merged commit 3e3ac78 into sbhattlab:main May 16, 2025
7 checks passed
@Neclow Neclow deleted the cophenetic_with_bls branch May 16, 2025 09:50
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

Successfully merging this pull request may close these issues.

2 participants