Skip to content

50% improvement on build_newick#17

Merged
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:build_newick
May 1, 2025
Merged

50% improvement on build_newick#17
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:build_newick

Conversation

@Neclow
Copy link
Collaborator

@Neclow Neclow commented May 1, 2025

New functions are proposed to build a Newick string from get_pairs() instead of get_ancestry(), thus eliminating an extra step. Moreover, we get rid of recursion, which incurs a higher overload for a large number of leaves.

image
0003_8e8e0117f2b02383612646152fb193e9042e4b09_20250501_112011.json

@Neclow Neclow requested review from Copilot and lsetiawan and removed request for lsetiawan May 1, 2025 11:24
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 refactors the tree-building functionality for Newick strings by switching from recursive ancestry‐based construction to a more efficient iterative pairs‐based approach, leading to improved performance.

  • Refactored build_newick functions to use pairs instead of ancestry arrays
  • Eliminated recursion in favor of iterative caching methods
  • Updated associated API calls and tests accordingly

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
py-phylo2vec/src/lib.rs Updated build_newick to accept pairs instead of ancestry triples
py-phylo2vec/phylo2vec/base/to_newick.py Removed the legacy _build_newick function
phylo2vec/src/tree_vec/ops/newick/mod.rs Replaced recursive Newick string construction with an iterative, cache‑based method and updated build_newick_with_bls
phylo2vec/src/tree_vec/ops/mod.rs Modified to_newick_from_vector/from_matrix functions to use get_pairs
Comments suppressed due to low confidence (3)

phylo2vec/src/tree_vec/ops/newick/mod.rs:229

  • [nitpick] Consider renaming the 'cache' variable (used to collect node strings) to a more descriptive name (e.g., 'node_strings') for improved code clarity.
for (i, &(c1, c2)) in pairs.iter().enumerate() {

py-phylo2vec/src/lib.rs:42

  • The function signature now uses 'input_pairs' instead of 'input_ancestry'. Please ensure that all downstream calls and documentation are updated to reflect this change.
fn build_newick(input_pairs: Vec<(usize, usize)>) -> String {

phylo2vec/src/tree_vec/ops/mod.rs:22

  • Switching from 'get_ancestry' to 'get_pairs' simplifies the tree construction process; ensure that the related documentation and in-code comments are updated accordingly.
let pairs: Pairs = get_pairs(v);

@Neclow Neclow merged commit a06ed36 into sbhattlab:main May 1, 2025
7 checks passed
@Neclow Neclow deleted the build_newick branch May 14, 2025 10:11
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