Skip to content

Re root tree#50

Merged
dfornika merged 10 commits intomainfrom
re-root-tree
Feb 20, 2026
Merged

Re root tree#50
dfornika merged 10 commits intomainfrom
re-root-tree

Conversation

@dfornika
Copy link
Copy Markdown
Owner

Add the ability to re-root the tree based on a selected node. Also add the ability to ladderize the tree, either ascending or descending.

Copy link
Copy Markdown
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 pull request adds tree manipulation functionality to the phylogenetic viewer, specifically the ability to re-root trees based on a selected node and to ladderize trees in ascending or descending order.

Changes:

  • Implemented reroot-on-branch function with comprehensive edge-case handling and pairwise distance preservation
  • Implemented ladderize function to sort tree children by clade size
  • Added UI controls for Ctrl+clicking nodes to select for re-rooting and toolbar buttons for re-rooting and ladderizing operations

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/main/app/tree.cljs Core re-rooting and ladderizing algorithms with helper functions for path finding, ID stripping, and unifurcation collapsing
src/test/app/tree_test.cljs Comprehensive test suite for reroot-on-branch covering edge cases, distance preservation, and round-trip compatibility
src/main/app/state.cljs New state atoms for active-reroot-node-id and positioned-tree with proper export/import integration
src/main/app/specs.cljs Spec definitions for new state fields and reroot-on-branch function
src/main/app/components/viewer.cljs State management to capture and store positioned tree for re-rooting operations
src/main/app/components/tree.cljs Visual feedback (red circle) for selected re-root node and Ctrl+click handlers
src/main/app/components/toolbar.cljs UI buttons for re-rooting and ladderizing with appropriate enable/disable logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/app/components/toolbar.cljs Outdated
Comment thread src/main/app/components/tree.cljs Outdated
Comment thread src/main/app/components/tree.cljs Outdated
Comment thread src/main/app/components/tree.cljs Outdated
Comment thread src/main/app/state.cljs Outdated
Comment thread src/main/app/state.cljs Outdated
Comment thread src/main/app/state.cljs Outdated
Comment thread src/main/app/tree.cljs
Comment on lines +380 to +397
(defn ladderize
"Ladderizes a tree by sorting children at each node by subtree size.

Direction can be :ascending (larger clades on top, the default) or
:descending (larger clades on bottom).

This is a pure function - it doesn't modify coordinates, just reorders
the :children vectors."
([tree]
(ladderize tree :ascending))
([tree direction]
(if (empty? (:children tree))
tree
(let [ladderized-children (mapv #(ladderize % direction) (:children tree))
sorted-children (sort-by count-tips
(if (= direction :ascending) > <)
ladderized-children)]
(assoc tree :children (vec sorted-children))))))
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The ladderize function lacks test coverage. Given that the codebase has comprehensive test coverage for tree functions (including extensive tests for reroot-on-branch), the ladderize function should also have tests to verify:

  1. Correct sorting order for :ascending and :descending directions
  2. Preservation of tree structure and leaf count
  3. Behavior with edge cases like single-leaf trees or already-ladderized trees
  4. Round-trip compatibility with Newick serialization

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

dfornika and others added 3 commits February 19, 2026 16:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

@dfornika I've opened a new pull request, #51, to work on those changes. Once the pull request is ready, I'll request review from you.

dfornika and others added 2 commits February 19, 2026 16:54
* Initial plan

* Add tests for ladderize function

Co-authored-by: dfornika <145659+dfornika@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dfornika <145659+dfornika@users.noreply.github.com>
@dfornika dfornika merged commit 39cf9d4 into main Feb 20, 2026
2 checks passed
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.

3 participants