$ show veg/phylotree.js
phylotree.js is a JavaScript library for phylogenetic tree visualization and analysis, designed for web-based applications. It provides robust parsing of multiple tree formats (Newick, PhyloXML, NEXUS, NEXML, BEAST), interactive SVG rendering via D3, and a suite of analytical utilities including metrics (Sackin's index, pairwise distances, root-to-tip regression), clustering algorithms (Cluster Picker, PhyloPart), and tree construction (neighbor joining). The library is modular, with separate modules for formats, rendering, metrics, and clustering, and includes CLI tools for common operations like rerooting, tagging, and validation. It is used in production at phylotree.hyphy.org and supports real-world phylogenetic workflows in molecular epidemiology and evolutionary biology. While the codebase demonstrates solid engineering with reusable patterns like an event emitter and a robust Newick parser, it shows signs of technical drift with legacy dependencies (underscore, lodash, moment) and some unused code.
The LLM identified 3 files worth highlighting for reuse:
Implements a lightweight event emitter mixin (on/off/emit) for decoupling tree interactions (nodeClick, selectionChange, rerooted) from rendering logic. This pattern is self-contained, requires no internal dependencies, and can be extracted into any JavaScript project needing custom event handling.
A robust Newick parser that handles standard Newick, NHX annotations, BEAST-style tags, bootstrap values, and branch lengths. It is isolated from the rest of the library (only depends on basic string operations) and can be reused in any JavaScript project requiring tree parsing, with minimal adaptation for custom tag formats.
Manages multiple named selection sets with distinct colors and mutual exclusion. Provides addToSet, removeFromSet, getSetMembers, and clearSet methods. This module is self-contained and demonstrates a clean pattern for managing overlapping selections in interactive visualizations, reusable outside phylogenetics.