Conversation
There was a problem hiding this comment.
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-branchfunction with comprehensive edge-case handling and pairwise distance preservation - Implemented
ladderizefunction 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.
| (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)))))) |
There was a problem hiding this comment.
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:
- Correct sorting order for :ascending and :descending directions
- Preservation of tree structure and leaf count
- Behavior with edge cases like single-leaf trees or already-ladderized trees
- Round-trip compatibility with Newick serialization
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* 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>
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.