hyphaeon 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. hyphaeon-0.1.0/LICENSE +21 -0
  2. hyphaeon-0.1.0/PKG-INFO +332 -0
  3. hyphaeon-0.1.0/README.md +296 -0
  4. hyphaeon-0.1.0/hyphaeon/__init__.py +37 -0
  5. hyphaeon-0.1.0/hyphaeon/_progress.py +81 -0
  6. hyphaeon-0.1.0/hyphaeon/attribution.py +175 -0
  7. hyphaeon-0.1.0/hyphaeon/cli.py +1324 -0
  8. hyphaeon-0.1.0/hyphaeon/dataset.py +775 -0
  9. hyphaeon-0.1.0/hyphaeon/disease.py +554 -0
  10. hyphaeon-0.1.0/hyphaeon/epistasis.py +779 -0
  11. hyphaeon-0.1.0/hyphaeon/evaluation.py +667 -0
  12. hyphaeon-0.1.0/hyphaeon/filter.py +399 -0
  13. hyphaeon-0.1.0/hyphaeon/inference.py +192 -0
  14. hyphaeon-0.1.0/hyphaeon/io.py +49 -0
  15. hyphaeon-0.1.0/hyphaeon/model.py +755 -0
  16. hyphaeon-0.1.0/hyphaeon/phenotype.py +672 -0
  17. hyphaeon-0.1.0/hyphaeon/splits.py +356 -0
  18. hyphaeon-0.1.0/hyphaeon/stats.py +84 -0
  19. hyphaeon-0.1.0/hyphaeon/temporal.py +1100 -0
  20. hyphaeon-0.1.0/hyphaeon/training_data.py +408 -0
  21. hyphaeon-0.1.0/hyphaeon/weights.py +253 -0
  22. hyphaeon-0.1.0/hyphaeon.egg-info/PKG-INFO +332 -0
  23. hyphaeon-0.1.0/hyphaeon.egg-info/SOURCES.txt +45 -0
  24. hyphaeon-0.1.0/hyphaeon.egg-info/dependency_links.txt +1 -0
  25. hyphaeon-0.1.0/hyphaeon.egg-info/entry_points.txt +2 -0
  26. hyphaeon-0.1.0/hyphaeon.egg-info/requires.txt +24 -0
  27. hyphaeon-0.1.0/hyphaeon.egg-info/top_level.txt +1 -0
  28. hyphaeon-0.1.0/pyproject.toml +49 -0
  29. hyphaeon-0.1.0/setup.cfg +4 -0
  30. hyphaeon-0.1.0/tests/test_busted.py +166 -0
  31. hyphaeon-0.1.0/tests/test_disease_filter_cli.py +99 -0
  32. hyphaeon-0.1.0/tests/test_distance_mds.py +124 -0
  33. hyphaeon-0.1.0/tests/test_epistasis.py +401 -0
  34. hyphaeon-0.1.0/tests/test_evaluation.py +293 -0
  35. hyphaeon-0.1.0/tests/test_gpu_mem_guard.py +162 -0
  36. hyphaeon-0.1.0/tests/test_integration.py +218 -0
  37. hyphaeon-0.1.0/tests/test_load_alignment.py +135 -0
  38. hyphaeon-0.1.0/tests/test_parsing.py +162 -0
  39. hyphaeon-0.1.0/tests/test_phenotype.py +393 -0
  40. hyphaeon-0.1.0/tests/test_splits.py +370 -0
  41. hyphaeon-0.1.0/tests/test_stats.py +188 -0
  42. hyphaeon-0.1.0/tests/test_temporal.py +115 -0
  43. hyphaeon-0.1.0/tests/test_temporal_experimental.py +119 -0
  44. hyphaeon-0.1.0/tests/test_tokenization.py +56 -0
  45. hyphaeon-0.1.0/tests/test_training.py +225 -0
  46. hyphaeon-0.1.0/tests/test_training_data.py +268 -0
  47. hyphaeon-0.1.0/tests/test_weights.py +248 -0
hyphaeon-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sergei L. Kosakovsky Pond and HyphAeon Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,332 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyphaeon
3
+ Version: 0.1.0
4
+ Summary: HyphAeon: A Deep-Time Phylogenetic Foundation Model for Multi-Scale Evolutionary, Structural, and Clinical Genomics
5
+ Author-email: "Sergei L. Kosakovsky Pond" <spond@temple.edu>
6
+ Project-URL: Homepage, https://github.com/veg/HyphAeon
7
+ Project-URL: Bug Tracker, https://github.com/veg/HyphAeon/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: torch>=2.0.0
16
+ Requires-Dist: biopython>=1.80
17
+ Requires-Dist: numpy>=1.22.0
18
+ Requires-Dist: scipy>=1.9.0
19
+ Requires-Dist: pandas>=1.5.0
20
+ Requires-Dist: psutil>=5.9.0
21
+ Requires-Dist: huggingface-hub>=0.20.0
22
+ Requires-Dist: safetensors>=0.4.0
23
+ Requires-Dist: networkx>=3.0
24
+ Provides-Extra: tn93
25
+ Requires-Dist: tn93>=1.2.0; extra == "tn93"
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Provides-Extra: model-eval
29
+ Requires-Dist: pytest>=7.0; extra == "model-eval"
30
+ Requires-Dist: scikit-learn>=1.0; extra == "model-eval"
31
+ Provides-Extra: all
32
+ Requires-Dist: tn93>=1.2.0; extra == "all"
33
+ Requires-Dist: pytest>=7.0; extra == "all"
34
+ Requires-Dist: scikit-learn>=1.0; extra == "all"
35
+ Dynamic: license-file
36
+
37
+ <div align="center">
38
+
39
+ <img src="assets/hyphaeon_logo.png" alt="HyphAeon Logo" width="280"/>
40
+
41
+ # HyphAeon
42
+ ### A Deep-Time Phylogenetic Foundation Model for Multi-Scale Evolutionary, Structural, and Clinical Genomics
43
+
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
45
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
46
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-orange.svg)](https://pytorch.org/)
47
+
48
+ </div>
49
+
50
+ ---
51
+
52
+ **HyphAeon** is a deep-time phylogenetic foundation model designed to bridge computational phylogenetics, structural biology, and foundation AI. Built upon a 2D axial transformer backbone (**`PhyloAxialTransformer`**) with patristic distance-decay attention and classical multidimensional scaling (MDS) tree embeddings, HyphAeon ingests multi-species codon alignments and explicit evolutionary trees spanning 200 million years of deep time.
53
+
54
+ ---
55
+
56
+ > [!TIP]
57
+ > **Migrating from HyPhy?** See our comprehensive [**HyPhy to HyphAeon Migration Guide**](MIGRATION_GUIDE.md) for direct method-by-method translations (`hyphy meme` → `hyphaeon meme`, `contrast-fel` → `hyphaeon phenotype`, `prime` → `hyphaeon dms`) and biological recipes categorized by empirical data regime.
58
+
59
+ ## 🚀 Key Capabilities & Unified Commands
60
+
61
+ HyphAeon integrates six complementary phylogenetic deep learning and geometric
62
+ projection engines:
63
+
64
+ 1. **`hyphaeon meme` (Site-Level Diversifying Selection)**:
65
+ Neural episodic positive selection inference (100×–1,100× faster than standard numerical MLE and codon-MCMC models like HyPhy MEME/FEL; see ARCHITECTURE.md for detailed benchmarks) using Tree-RoPE 4D geometric branch embeddings and axial tree attention.
66
+ 2. **`hyphaeon epistasis` (3D Co-Evolution & Epistatic Sectors)**:
67
+ Multi-scale epistatic sector mining implementing phylogenetic branch attribution, exact tree hypergeometric tests, Jaccard overlap suppression, contact map recovery (C<sub>β</sub>–C<sub>β</sub> < 8 Å), and vectorized Monte Carlo permutation significance testing (`--n-permutations`, `--max-perm-p`).
68
+ 3. **`hyphaeon dms` (Digital Deep Mutational Scanning & CPDs)**:
69
+ In silico Selection Deep Mutational Scanning. Performs high-throughput sweeps of all 19 alternative amino acids across every codon position in seconds, calculating the **Epistatic Selection Sensitivity Matrix (ESSM)**, Intrinsic Mutational Plasticity (E<sub>i,i</sub>), and de novo predicting compensatory partners (s<sub>comp</sub>) that rescue human disease mutations (Compensated Pathogenic Deviations).
70
+ 4. **`hyphaeon phenotype` (PhyloWAS)**:
71
+ Directional phenotype-genotype association mapping on the unit hypersphere S<sup>M-1</sup>. Computes spectral trait energies (Ψ<sub>Spectral</sub>), exact sequenced-taxa null scaling p-values, Benjamini-Hochberg FDR q-values, **Phenotype-Associated Residue Signatures (PARS)**, macromolecular trait sector permutation testing (`--n-permutations`, `--max-perm-p`), and gene-level Brownian motion liability permulations (`--permulations`).
72
+ 5. **`hyphaeon temporal` (Continuous Surveillance Dynamics & Sweep Velocity)**:
73
+ Time-resolved episodic selection tracking using continuous logistic trajectory regression, positive sweep velocity v<sub>s</sub>(t) = max(0, d/dt â<sub>s</sub>(t)), Dynamic Time Warping (DTW) wave decomposition, and temporal SVD factor loadings. See the [**Temporal Analysis Operational Guide**](TEMPORAL_ANALYSIS_GUIDE.md).
74
+ 6. **`hyphaeon splits` (Spectral Graph Bisection & Tree-Free Clade Discovery)**:
75
+ Recovers well-supported phylogenetic macro-clades and deep hierarchical bipartitions by fusing pairwise continuous 4D MDS geometry with discrete cross-taxa attention maps. Delivers up to 28× speedups over traditional ML tree search without requiring pre-computed phylogenies. See the [**Spectral Splits & Benchmarking Report**](SPECTRAL_SPLITS_BENCHMARK.md).
76
+
77
+ ---
78
+
79
+ ## 📦 Installation
80
+
81
+ HyphAeon requires Python ≥ 3.8 and PyTorch ≥ 2.0. At runtime it auto-selects
82
+ the best available device (CUDA → Apple MPS → CPU), so no manual configuration
83
+ is needed regardless of which install path you choose.
84
+
85
+ | Method | Command | Torch | GPU? |
86
+ | :--- | :--- | :--- | :--- |
87
+ | **pip** (default) | `pip install hyphaeon` | CUDA-bundled wheel (~550 MB) | NVIDIA GPU if driver matches; else CPU |
88
+ | **pip** (CPU-only) | `pip install torch --index-url https://download.pytorch.org/whl/cpu` then `pip install hyphaeon` | CPU-only wheel (~200 MB) | CPU |
89
+ | **Bioconda** | `conda install -c bioconda hyphaeon` | CPU-only `pytorch` from conda-forge | CPU by default; swap in `pytorch-gpu` for GPU |
90
+ | **NVIDIA Jetson** | See [issue #31](https://github.com/veg/HyphAeon/issues/31) | JetPack-native wheel (cp38 only) | Jetson GPU |
91
+
92
+ To use a GPU with Bioconda, install conda-forge's GPU PyTorch variant first:
93
+
94
+ ```bash
95
+ conda create -n hyphaeon-gpu -c conda-forge pytorch-gpu
96
+ conda activate hyphaeon-gpu
97
+ conda install -c bioconda hyphaeon
98
+ ```
99
+
100
+ You can always install a specific PyTorch build before installing HyphAeon if
101
+ none of the above defaults suit your system (e.g. a particular CUDA version,
102
+ a custom wheel, or a CPU-only build on a server without GPU).
103
+
104
+ > [!NOTE]
105
+ > **Model weights** are downloaded automatically from [Hugging Face](https://huggingface.co/datamonkey/hyphaeon)
106
+ > on first use (cached in `~/.cache/hyphaeon/`). No authentication or token is
107
+ > required. Use `--model-variant viral` to select the viral-tuned variant, or
108
+ > `--weights /path/to/checkpoint` to use a local file.
109
+
110
+ ---
111
+
112
+ ## 📂 Included Benchmark Datasets
113
+
114
+ All example alignments and phylogenetic trees required to reproduce these analyses are bundled directly in the `examples/` directory:
115
+
116
+ | Dataset | Alignment File | Tree File | Taxa (N) | Codons (L) | Description & Biological Domain |
117
+ | :--- | :--- | :--- | :--- | :--- | :--- |
118
+ | **HIV-1 RT** | [`examples/HIV1_RT.fasta`](examples/HIV1_RT.fasta) | [`examples/HIV1_RT.nwk`](examples/HIV1_RT.nwk) | 476 | 335 | Retroviral Reverse Transcriptase polymerase domain (drug resistance & epistasis). |
119
+ | **Rhodopsin** | [`examples/RHO.fasta`](examples/RHO.fasta) | Auto (TN93) | 710 | 349 | Mammalian Rhodopsin visual pigments (deep-sea diving sensory adaptation). No tree file provided; uses TN93 distance estimation. |
120
+ | **Smc6** | [`examples/Smc6.fasta`](examples/Smc6.fasta) | [`examples/Smc6.nwk`](examples/Smc6.nwk) | 20 | 1,097 | Primate Smc6 structural maintenance of chromosomes (antiviral host restriction). |
121
+ | **Bat OAS1** | [`examples/bat_oas1.fasta`](examples/bat_oas1.fasta) | [`examples/bat_oas1.nwk`](examples/bat_oas1.nwk) | 18 | 351 | Chiropteran OAS1 2'-5'-oligoadenylate synthetase (innate immunity escape). |
122
+ | **Camelid VHH** | [`examples/camelid.fasta`](examples/camelid.fasta) | [`examples/camelid.nwk`](examples/camelid.nwk) | 212 | 96 | Camelid single-domain antibody heavy-chain variable domain (antigenic diversity). Used for integration testing; no dedicated example section. |
123
+
124
+ ---
125
+
126
+ ## 🔬 Reproducible Benchmark Examples
127
+
128
+ ### Example 1: Inter-Site Epistasis & Branch Co-Selection in HIV-1 Reverse Transcriptase
129
+
130
+ ```bash
131
+ # Run branch co-selection, sector mining, and export co-selection network with Monte Carlo permutation testing
132
+ hyphaeon epistasis \
133
+ -a examples/HIV1_RT.fasta \
134
+ -t examples/HIV1_RT.nwk \
135
+ --n-permutations 10000 \
136
+ --max-perm-p 0.05 \
137
+ -o examples/HIV1_RT_epistasis.json \
138
+ -c examples/HIV1_RT_edges.csv \
139
+ --graphml examples/HIV1_RT_coselection.graphml
140
+ ```
141
+
142
+ #### Key Biological Discoveries:
143
+ 1. **Unsupervised Discovery of Multi-Drug Catalytic Complexes (Q151M MDR Complex)**:
144
+ * HyphAeon places the co-evolution of residue 116 with residue 151 at **#1 overall** across all candidate pairs:
145
+ > **F116 ⟷ Q151** (Co-Sel = 0.8660, p<sub>hyper</sub> = 7.02 × 10⁻⁹, FDR q = 1.17 × 10⁻⁷)
146
+ 2. **Autonomous Dissection of Mutually Exclusive Pathways (TAM-1 vs. TAM-2)**:
147
+ * HyphAeon's branch co-selection metric autonomously isolates the **TAM-1 triad** (`M41L + L210W + T215Y`, q < 10⁻⁷) from the mutually antagonistic **TAM-2 cluster** (`D67N + K70R + K219Q`, q < 10⁻³).
148
+
149
+ #### Monte Carlo Permutation Testing for Epistatic Sectors:
150
+ To distinguish authentic structural/functional sectors from stochastic subsets of variable sites, HyphAeon tests the spectral coherence of candidate sectors against an empirical null distribution:
151
+ * **Vectorized Permutation Engine (`--n-permutations <int>`, default: `10000`)**: For a discovered sector S of size K, samples B random K-site subgraphs uniformly without replacement from active candidate sites. Coherence is computed across null batches via tensor contraction and Hermitian eigenvalue decomposition:
152
+ ```text
153
+ C(S) = λ₁(A[S, :] A[S, :]ᵀ) / Tr(A[S, :] A[S, :]ᵀ)
154
+ ```
155
+ * **Output Metrics**: Each sector reports empirical one-sided permutation p-value:
156
+ ```text
157
+ p_perm = (1/B) Σ I(C(S^(b)) ≥ C(S))
158
+ ```
159
+ along with null mean E[C<sub>null</sub>], standard deviation, 95th percentile cutoff C<sub>95</sub>, and theoretical isotropic baseline 1/K. Set `--n-permutations 0` to disable permutation testing.
160
+ * **Empirical Filtering (`--max-perm-p <float>`, default: `None`)**: Retains only sectors whose spectral coherence satisfies `p_perm ≤ threshold` (e.g., `--max-perm-p 0.05`).
161
+
162
+ ---
163
+
164
+ ### Example 2: In Silico Selection Deep Mutational Scanning (Digital DMS / ESSM)
165
+
166
+ ```bash
167
+ # Run digital DMS sweep on HIV-1 RT
168
+ hyphaeon dms -a examples/HIV1_RT.fasta -t examples/HIV1_RT.nwk -o examples/HIV1_RT_dms.json -c examples/HIV1_RT_dms.csv
169
+ ```
170
+
171
+ ---
172
+
173
+ ### Example 3: Convergent Sensory Adaptation & Spectral Tuning in Rhodopsin
174
+
175
+ ```bash
176
+ # Run PhyloWAS with trait sector permutation testing and gene-level phylogenetic permulations
177
+ hyphaeon phenotype \
178
+ -a examples/RHO.fasta \
179
+ -fg "turTru,balMus,balPhys,orcOrc,delDelp,phyCat,phoVit,halGryp,mirLeo,zalCali,odoRos" \
180
+ --n-permutations 10000 \
181
+ --max-perm-p 0.05 \
182
+ --permulations 1000 \
183
+ -o examples/RHO_marine_phenotype.json \
184
+ -c examples/RHO_marine_sites.csv
185
+ ```
186
+
187
+ #### Multi-Scale Permutation & Null Testing in PhyloWAS:
188
+ HyphAeon implements two complementary null testing layers addressing distinct evolutionary hypotheses:
189
+ 1. **Macromolecular Trait Sector Permutations (`--n-permutations <int>`, default: `10000`; `--max-perm-p <float>`, default: `None`)**:
190
+ * Following single-site phenotype association (FDR q ≤ α), HyphAeon extracts coherent epistatic sectors among trait-associated residues.
191
+ * Tests whether trait sector coherence C(S) significantly exceeds random K-site subgraphs sampled across the alignment (p<sub>perm</sub> ≤ max_perm_p), confirming that convergent phenotype adaptation drives coordinated macromolecular re-organization rather than unlinked mutations.
192
+ 2. **Gene-Level Brownian Motion Liability Permulations (`--permulations <int>`, default: `0` / parametric)**:
193
+ * Simulates neutral continuous phenotype evolution along the phylogenetic tree using Brownian motion (Saputra et al. 2021 / RERconverge null model).
194
+ * Computes empirical gene-level p-values (p<sub>gene</sub>) testing whether the length-normalized spectral energy (Ψ̄) or maximum site association (ρ<sub>max</sub>) exceeds neutral phylogenetic drift.
195
+
196
+ ---
197
+
198
+ ### Example 4: Ultra-Fast Episodic Positive Selection (`predict`), Feature Attribution (`--attribute`), & Alignment Error Filtering (`--filter`)
199
+
200
+ ```bash
201
+ # Standard per-codon episodic selection inference
202
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk -o examples/Smc6_results.json -c examples/Smc6_results.csv
203
+
204
+ # Enable mechanistic feature attribution (identifies driving species & evolutionary timing)
205
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk --attribute --attribution-min-lrt 3.84 -o examples/Smc6_attributed.json
206
+
207
+ # Run inference with automated dual-stage alignment error filtering & export cleaned alignment
208
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk --filter --filter-out-aln examples/Smc6_cleaned.fasta -c examples/Smc6_clean.csv
209
+ ```
210
+
211
+ #### 1. Mechanistic Feature Attribution (`--attribute`):
212
+ * **Single-Taxon Counterfactual Perturbation (ΔLRT)**: In silico mutates each non-consensus species back to ancestral state to rank driving taxa by marginal selection evidence explained (% Signal Explained).
213
+ * **Evolutionary Epoch Decomposition**: Classifies selection timing by weighted root patristic depth into **Recent Terminal / Tip Sweep** (≥ 0.60), **Intermediate Subclade Burst** (0.35–0.60), and **Deep Ancestral / Basal Divergence** (< 0.35), separating **Recurrent Multi-Lineage Adaptation** from single-lineage sweeps.
214
+
215
+ #### 2. Automated Alignment Error Screening (`--filter`):
216
+ * **Dual-Stage Algorithm**: Detects 1D selective clusters via exact upper-tail hypergeometric scan (p<sub>local</sub> ≤ 0.01), then evaluates the Outlier Contamination Index (OCI ≥ 0.25) to flag private frameshifts (≥ 3 contiguous radical mutations in an isolated leaf against conserved species).
217
+ * **Surgical In-Place Masking**: Automatically masks only the guilty taxon's anomalous span with `NNN` and re-evaluates the cleaned alignment in milliseconds, eliminating false positives while preserving legitimate multi-species selection.
218
+
219
+ ---
220
+
221
+ ### Example 5: Spectral Graph Bisection & Tree-Free Phylogenetic Splits (`hyphaeon splits`)
222
+
223
+ ```bash
224
+ # Basic Tree-Free Macro-Split Discovery (Outputs Newick Tree & Clade CSV)
225
+ hyphaeon splits \
226
+ -a examples/bat_oas1.fasta \
227
+ --no-tree \
228
+ -o examples/bat_oas1_spectral_tree.nwk \
229
+ -c examples/bat_oas1_clades.csv \
230
+ --cpu
231
+ ```
232
+
233
+ #### Spectral Bisection Architecture:
234
+ * **Multi-Modal Affinity Fusion**: Combines cross-taxa attention matrices ($\bar{\mathbf{A}}$) from the axial transformer, continuous 4D metric space from Multidimensional Scaling (MDS) on pairwise distances, and sequence-level latent representations into a fused affinity matrix $\mathbf{A}_{\text{fused}} = \mathbf{S}_{\text{attn}} \odot \mathbf{K}_{\text{MDS}} \odot \mathbf{K}_{\text{emb}}$.
235
+ * **Normalized Graph Laplacian & Fiedler Vector**: Partitions taxa along the Fiedler vector $\mathbf{v}_2$ of $\mathbf{L}_{\text{sym}} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A}_{\text{fused}} \mathbf{D}^{-1/2}$, quantifying macro-clade split stability via the spectral eigengap $\Delta\lambda = \lambda_3 - \lambda_2$.
236
+ * **Comprehensive Benchmarks**: See [`SPECTRAL_SPLITS_BENCHMARK.md`](SPECTRAL_SPLITS_BENCHMARK.md) for full benchmarks against IQ-TREE 2, RAxML-NG, FastTree, and Neighbor-Joining across empirical datasets.
237
+
238
+ ---
239
+
240
+ ## 🛠️ Retraining & Fine-Tuning HyphAeon
241
+
242
+ ### 1. Build per-gene training tensors
243
+
244
+ Prepare one alignment and one official HyPhy MEME JSON result per gene. Trees may be supplied as matching Newick files or embedded in the alignments:
245
+
246
+ ```bash
247
+ python training/build_training_npz.py \
248
+ --alignment_dir /path/to/training_alignments/ \
249
+ --tree_dir /path/to/trees/ \
250
+ --meme_dir /path/to/meme_results/ \
251
+ --output_dir /path/to/training_npz/
252
+ ```
253
+
254
+ ### 2. Fine-tune the foundation model
255
+
256
+ ```bash
257
+ python training/train.py \
258
+ --data_dir /path/to/training_npz/ \
259
+ --epochs 30 \
260
+ --batch_size 1 \
261
+ --lr 3e-4 \
262
+ --embed_dim 384 \
263
+ --layers 6 \
264
+ --heads 12 \
265
+ --fp16 \
266
+ --output_dir /path/to/run_weights/
267
+ ```
268
+
269
+ ---
270
+
271
+ ## ⚡ CLI Reference Summary
272
+
273
+ | Command | Action | Description |
274
+ | :--- | :--- | :--- |
275
+ | `hyphaeon meme` | Site-Level Selection | Fast per-codon LRT & selection rate prediction (100×–1,100× faster than MLE). |
276
+ | `hyphaeon epistasis` | 3D Epistatic Sectors | Co-selection networks, hypergeometric tree overlaps, and Monte Carlo sector permutations. |
277
+ | `hyphaeon dms` | Digital DMS | 19-AA in silico perturbation sweeps and Compensated Pathogenic Deviation mapping. |
278
+ | `hyphaeon phenotype`| Directional PhyloWAS | Directional trait mapping on the unit hypersphere, trait sector permutations, and liability permulations. |
279
+ | `hyphaeon temporal` | Dynamic Surveillance | Continuous logistic trajectory regression, sweep velocity, DTW waves, and temporal SVD. |
280
+ | `hyphaeon splits` | Spectral Bisection | Tree-free phylogenetic macro-splits via cross-taxa attention and MDS graph Laplacian. |
281
+ | `hyphaeon disease` | Pathogenicity Prediction | Predict disease variant effects and pathogenicity using HyphAeon attention attributions. |
282
+ | `hyphaeon filter` | Alignment QC | Automated alignment error detection and surgical masking of anomalous regions. |
283
+
284
+ ### Key Permutation Testing Arguments:
285
+
286
+ #### `hyphaeon epistasis`
287
+ | Flag | Type | Default | Description |
288
+ | :--- | :---: | :---: | :--- |
289
+ | `--n-permutations` | `int` | `10000` | Number of random K-site subset Monte Carlo permutations for sector significance testing (set `0` to disable). |
290
+ | `--max-perm-p` | `float` | `None` | Maximum empirical permutation p-value threshold to retain sectors (default retains all C(S) ≥ min_coherence). |
291
+ | `--min-coherence` | `float` | `0.50` | Minimum spectral coherence ratio C(S) = λ₁ / Tr for candidate sectors. |
292
+ | `--min-clique-size` | `int` | `3` | Minimum clique seed size for epistatic sectors. |
293
+ | `--max-overlap` | `float` | `0.50` | Maximum Jaccard overlap allowed between discovered sectors. |
294
+ | `--no-tree` / `--use-tn93` | `flag` | `False` | Estimate pairwise evolutionary distances directly from alignment via TN93 (skips tree). Requires the optional `tn93` package (`pip install hyphaeon[tn93]`) or the `tn93` binary on PATH. |
295
+
296
+ #### `hyphaeon phenotype`
297
+ | Flag | Type | Default | Description |
298
+ | :--- | :---: | :---: | :--- |
299
+ | `--n-permutations` | `int` | `10000` | Number of random K-site subset Monte Carlo permutations for trait sector significance testing (set `0` to disable). |
300
+ | `--max-perm-p` | `float` | `None` | Maximum permutation p-value threshold to retain trait sectors (default retains all C(S) ≥ 0.45). |
301
+ | `--permulations` | `int` | `0` | Number of Brownian motion phylogenetic permulations for gene-level empirical p-values (RERconverge null model; default `0` / parametric). |
302
+ | `--alpha` | `float` | `0.05` | Benjamini-Hochberg FDR significance threshold for trait-associated sites. |
303
+ | `--continuous` | `flag` | `False` | Treat trait values as continuous phylogenetic contrasts rather than discrete foreground/background. |
304
+ | `--min-taxa` | `int` | `4` | Minimum sequenced taxa required per site. |
305
+
306
+ #### `hyphaeon splits`
307
+ | Flag | Type | Default | Description |
308
+ | :--- | :---: | :---: | :--- |
309
+ | `-a` / `--alignment` | `path` | Required | Path to in-frame codon FASTA or NEXUS alignment. |
310
+ | `-t` / `--tree` | `path` | `None` | Optional Newick/NEXUS phylogenetic tree (optional if embedded, or if `--no-tree`/`--use-tn93` is set). |
311
+ | `--no-tree` / `--use-tn93` | `flag` | `False` | Skip phylogenetic tree and estimate pairwise evolutionary distances directly from alignment via TN93. Requires `tn93` (`pip install hyphaeon[tn93]`) or the `tn93` binary on PATH. |
312
+ | `--min-clade-size` | `int` | `2` | Minimum clade size floor to terminate recursive bisection. |
313
+ | `--max-depth` | `int` | `10` | Maximum tree hierarchy recursion depth. |
314
+ | `-o` / `--output` | `path` | `None` | Optional path to export derived hierarchical Newick tree (`.nwk`). |
315
+ | `-c` / `--csv` | `path` | `None` | Optional path to export split clade membership assignments (`.csv`). |
316
+ | `-w` / `--weights` | `path` | `None` | Path to local model weights file (overrides HF download). |
317
+ | `--cpu` | `flag` | `False` | Force CPU execution. |
318
+
319
+ ---
320
+
321
+ ## 📜 Citation
322
+
323
+ If you use **HyphAeon** in your research, please cite:
324
+
325
+ ```bibtex
326
+ @article{hyphaeon2026,
327
+ title={HyphAeon: Attention on Evolution Across Deep Time Transforms Comparative Genomics},
328
+ author={Kosakovsky Pond, Sergei L. and Weaver, Steven and Callan, Danielle and Zehr, Jordan D. and Lucaci, Alexander G. and Verdonk, Hannah and Selberg, Avery and Brown, Gallean and Chikina, Maria and Clark, Nathan and Makova, Kateryna D. and Martin, Darren P. and Nekrutenko, Anton},
329
+ journal={Nature Methods / Nature Biotechnology (in submission)},
330
+ year={2026}
331
+ }
332
+ ```
@@ -0,0 +1,296 @@
1
+ <div align="center">
2
+
3
+ <img src="assets/hyphaeon_logo.png" alt="HyphAeon Logo" width="280"/>
4
+
5
+ # HyphAeon
6
+ ### A Deep-Time Phylogenetic Foundation Model for Multi-Scale Evolutionary, Structural, and Clinical Genomics
7
+
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
9
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
10
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-orange.svg)](https://pytorch.org/)
11
+
12
+ </div>
13
+
14
+ ---
15
+
16
+ **HyphAeon** is a deep-time phylogenetic foundation model designed to bridge computational phylogenetics, structural biology, and foundation AI. Built upon a 2D axial transformer backbone (**`PhyloAxialTransformer`**) with patristic distance-decay attention and classical multidimensional scaling (MDS) tree embeddings, HyphAeon ingests multi-species codon alignments and explicit evolutionary trees spanning 200 million years of deep time.
17
+
18
+ ---
19
+
20
+ > [!TIP]
21
+ > **Migrating from HyPhy?** See our comprehensive [**HyPhy to HyphAeon Migration Guide**](MIGRATION_GUIDE.md) for direct method-by-method translations (`hyphy meme` → `hyphaeon meme`, `contrast-fel` → `hyphaeon phenotype`, `prime` → `hyphaeon dms`) and biological recipes categorized by empirical data regime.
22
+
23
+ ## 🚀 Key Capabilities & Unified Commands
24
+
25
+ HyphAeon integrates six complementary phylogenetic deep learning and geometric
26
+ projection engines:
27
+
28
+ 1. **`hyphaeon meme` (Site-Level Diversifying Selection)**:
29
+ Neural episodic positive selection inference (100×–1,100× faster than standard numerical MLE and codon-MCMC models like HyPhy MEME/FEL; see ARCHITECTURE.md for detailed benchmarks) using Tree-RoPE 4D geometric branch embeddings and axial tree attention.
30
+ 2. **`hyphaeon epistasis` (3D Co-Evolution & Epistatic Sectors)**:
31
+ Multi-scale epistatic sector mining implementing phylogenetic branch attribution, exact tree hypergeometric tests, Jaccard overlap suppression, contact map recovery (C<sub>β</sub>–C<sub>β</sub> < 8 Å), and vectorized Monte Carlo permutation significance testing (`--n-permutations`, `--max-perm-p`).
32
+ 3. **`hyphaeon dms` (Digital Deep Mutational Scanning & CPDs)**:
33
+ In silico Selection Deep Mutational Scanning. Performs high-throughput sweeps of all 19 alternative amino acids across every codon position in seconds, calculating the **Epistatic Selection Sensitivity Matrix (ESSM)**, Intrinsic Mutational Plasticity (E<sub>i,i</sub>), and de novo predicting compensatory partners (s<sub>comp</sub>) that rescue human disease mutations (Compensated Pathogenic Deviations).
34
+ 4. **`hyphaeon phenotype` (PhyloWAS)**:
35
+ Directional phenotype-genotype association mapping on the unit hypersphere S<sup>M-1</sup>. Computes spectral trait energies (Ψ<sub>Spectral</sub>), exact sequenced-taxa null scaling p-values, Benjamini-Hochberg FDR q-values, **Phenotype-Associated Residue Signatures (PARS)**, macromolecular trait sector permutation testing (`--n-permutations`, `--max-perm-p`), and gene-level Brownian motion liability permulations (`--permulations`).
36
+ 5. **`hyphaeon temporal` (Continuous Surveillance Dynamics & Sweep Velocity)**:
37
+ Time-resolved episodic selection tracking using continuous logistic trajectory regression, positive sweep velocity v<sub>s</sub>(t) = max(0, d/dt â<sub>s</sub>(t)), Dynamic Time Warping (DTW) wave decomposition, and temporal SVD factor loadings. See the [**Temporal Analysis Operational Guide**](TEMPORAL_ANALYSIS_GUIDE.md).
38
+ 6. **`hyphaeon splits` (Spectral Graph Bisection & Tree-Free Clade Discovery)**:
39
+ Recovers well-supported phylogenetic macro-clades and deep hierarchical bipartitions by fusing pairwise continuous 4D MDS geometry with discrete cross-taxa attention maps. Delivers up to 28× speedups over traditional ML tree search without requiring pre-computed phylogenies. See the [**Spectral Splits & Benchmarking Report**](SPECTRAL_SPLITS_BENCHMARK.md).
40
+
41
+ ---
42
+
43
+ ## 📦 Installation
44
+
45
+ HyphAeon requires Python ≥ 3.8 and PyTorch ≥ 2.0. At runtime it auto-selects
46
+ the best available device (CUDA → Apple MPS → CPU), so no manual configuration
47
+ is needed regardless of which install path you choose.
48
+
49
+ | Method | Command | Torch | GPU? |
50
+ | :--- | :--- | :--- | :--- |
51
+ | **pip** (default) | `pip install hyphaeon` | CUDA-bundled wheel (~550 MB) | NVIDIA GPU if driver matches; else CPU |
52
+ | **pip** (CPU-only) | `pip install torch --index-url https://download.pytorch.org/whl/cpu` then `pip install hyphaeon` | CPU-only wheel (~200 MB) | CPU |
53
+ | **Bioconda** | `conda install -c bioconda hyphaeon` | CPU-only `pytorch` from conda-forge | CPU by default; swap in `pytorch-gpu` for GPU |
54
+ | **NVIDIA Jetson** | See [issue #31](https://github.com/veg/HyphAeon/issues/31) | JetPack-native wheel (cp38 only) | Jetson GPU |
55
+
56
+ To use a GPU with Bioconda, install conda-forge's GPU PyTorch variant first:
57
+
58
+ ```bash
59
+ conda create -n hyphaeon-gpu -c conda-forge pytorch-gpu
60
+ conda activate hyphaeon-gpu
61
+ conda install -c bioconda hyphaeon
62
+ ```
63
+
64
+ You can always install a specific PyTorch build before installing HyphAeon if
65
+ none of the above defaults suit your system (e.g. a particular CUDA version,
66
+ a custom wheel, or a CPU-only build on a server without GPU).
67
+
68
+ > [!NOTE]
69
+ > **Model weights** are downloaded automatically from [Hugging Face](https://huggingface.co/datamonkey/hyphaeon)
70
+ > on first use (cached in `~/.cache/hyphaeon/`). No authentication or token is
71
+ > required. Use `--model-variant viral` to select the viral-tuned variant, or
72
+ > `--weights /path/to/checkpoint` to use a local file.
73
+
74
+ ---
75
+
76
+ ## 📂 Included Benchmark Datasets
77
+
78
+ All example alignments and phylogenetic trees required to reproduce these analyses are bundled directly in the `examples/` directory:
79
+
80
+ | Dataset | Alignment File | Tree File | Taxa (N) | Codons (L) | Description & Biological Domain |
81
+ | :--- | :--- | :--- | :--- | :--- | :--- |
82
+ | **HIV-1 RT** | [`examples/HIV1_RT.fasta`](examples/HIV1_RT.fasta) | [`examples/HIV1_RT.nwk`](examples/HIV1_RT.nwk) | 476 | 335 | Retroviral Reverse Transcriptase polymerase domain (drug resistance & epistasis). |
83
+ | **Rhodopsin** | [`examples/RHO.fasta`](examples/RHO.fasta) | Auto (TN93) | 710 | 349 | Mammalian Rhodopsin visual pigments (deep-sea diving sensory adaptation). No tree file provided; uses TN93 distance estimation. |
84
+ | **Smc6** | [`examples/Smc6.fasta`](examples/Smc6.fasta) | [`examples/Smc6.nwk`](examples/Smc6.nwk) | 20 | 1,097 | Primate Smc6 structural maintenance of chromosomes (antiviral host restriction). |
85
+ | **Bat OAS1** | [`examples/bat_oas1.fasta`](examples/bat_oas1.fasta) | [`examples/bat_oas1.nwk`](examples/bat_oas1.nwk) | 18 | 351 | Chiropteran OAS1 2'-5'-oligoadenylate synthetase (innate immunity escape). |
86
+ | **Camelid VHH** | [`examples/camelid.fasta`](examples/camelid.fasta) | [`examples/camelid.nwk`](examples/camelid.nwk) | 212 | 96 | Camelid single-domain antibody heavy-chain variable domain (antigenic diversity). Used for integration testing; no dedicated example section. |
87
+
88
+ ---
89
+
90
+ ## 🔬 Reproducible Benchmark Examples
91
+
92
+ ### Example 1: Inter-Site Epistasis & Branch Co-Selection in HIV-1 Reverse Transcriptase
93
+
94
+ ```bash
95
+ # Run branch co-selection, sector mining, and export co-selection network with Monte Carlo permutation testing
96
+ hyphaeon epistasis \
97
+ -a examples/HIV1_RT.fasta \
98
+ -t examples/HIV1_RT.nwk \
99
+ --n-permutations 10000 \
100
+ --max-perm-p 0.05 \
101
+ -o examples/HIV1_RT_epistasis.json \
102
+ -c examples/HIV1_RT_edges.csv \
103
+ --graphml examples/HIV1_RT_coselection.graphml
104
+ ```
105
+
106
+ #### Key Biological Discoveries:
107
+ 1. **Unsupervised Discovery of Multi-Drug Catalytic Complexes (Q151M MDR Complex)**:
108
+ * HyphAeon places the co-evolution of residue 116 with residue 151 at **#1 overall** across all candidate pairs:
109
+ > **F116 ⟷ Q151** (Co-Sel = 0.8660, p<sub>hyper</sub> = 7.02 × 10⁻⁹, FDR q = 1.17 × 10⁻⁷)
110
+ 2. **Autonomous Dissection of Mutually Exclusive Pathways (TAM-1 vs. TAM-2)**:
111
+ * HyphAeon's branch co-selection metric autonomously isolates the **TAM-1 triad** (`M41L + L210W + T215Y`, q < 10⁻⁷) from the mutually antagonistic **TAM-2 cluster** (`D67N + K70R + K219Q`, q < 10⁻³).
112
+
113
+ #### Monte Carlo Permutation Testing for Epistatic Sectors:
114
+ To distinguish authentic structural/functional sectors from stochastic subsets of variable sites, HyphAeon tests the spectral coherence of candidate sectors against an empirical null distribution:
115
+ * **Vectorized Permutation Engine (`--n-permutations <int>`, default: `10000`)**: For a discovered sector S of size K, samples B random K-site subgraphs uniformly without replacement from active candidate sites. Coherence is computed across null batches via tensor contraction and Hermitian eigenvalue decomposition:
116
+ ```text
117
+ C(S) = λ₁(A[S, :] A[S, :]ᵀ) / Tr(A[S, :] A[S, :]ᵀ)
118
+ ```
119
+ * **Output Metrics**: Each sector reports empirical one-sided permutation p-value:
120
+ ```text
121
+ p_perm = (1/B) Σ I(C(S^(b)) ≥ C(S))
122
+ ```
123
+ along with null mean E[C<sub>null</sub>], standard deviation, 95th percentile cutoff C<sub>95</sub>, and theoretical isotropic baseline 1/K. Set `--n-permutations 0` to disable permutation testing.
124
+ * **Empirical Filtering (`--max-perm-p <float>`, default: `None`)**: Retains only sectors whose spectral coherence satisfies `p_perm ≤ threshold` (e.g., `--max-perm-p 0.05`).
125
+
126
+ ---
127
+
128
+ ### Example 2: In Silico Selection Deep Mutational Scanning (Digital DMS / ESSM)
129
+
130
+ ```bash
131
+ # Run digital DMS sweep on HIV-1 RT
132
+ hyphaeon dms -a examples/HIV1_RT.fasta -t examples/HIV1_RT.nwk -o examples/HIV1_RT_dms.json -c examples/HIV1_RT_dms.csv
133
+ ```
134
+
135
+ ---
136
+
137
+ ### Example 3: Convergent Sensory Adaptation & Spectral Tuning in Rhodopsin
138
+
139
+ ```bash
140
+ # Run PhyloWAS with trait sector permutation testing and gene-level phylogenetic permulations
141
+ hyphaeon phenotype \
142
+ -a examples/RHO.fasta \
143
+ -fg "turTru,balMus,balPhys,orcOrc,delDelp,phyCat,phoVit,halGryp,mirLeo,zalCali,odoRos" \
144
+ --n-permutations 10000 \
145
+ --max-perm-p 0.05 \
146
+ --permulations 1000 \
147
+ -o examples/RHO_marine_phenotype.json \
148
+ -c examples/RHO_marine_sites.csv
149
+ ```
150
+
151
+ #### Multi-Scale Permutation & Null Testing in PhyloWAS:
152
+ HyphAeon implements two complementary null testing layers addressing distinct evolutionary hypotheses:
153
+ 1. **Macromolecular Trait Sector Permutations (`--n-permutations <int>`, default: `10000`; `--max-perm-p <float>`, default: `None`)**:
154
+ * Following single-site phenotype association (FDR q ≤ α), HyphAeon extracts coherent epistatic sectors among trait-associated residues.
155
+ * Tests whether trait sector coherence C(S) significantly exceeds random K-site subgraphs sampled across the alignment (p<sub>perm</sub> ≤ max_perm_p), confirming that convergent phenotype adaptation drives coordinated macromolecular re-organization rather than unlinked mutations.
156
+ 2. **Gene-Level Brownian Motion Liability Permulations (`--permulations <int>`, default: `0` / parametric)**:
157
+ * Simulates neutral continuous phenotype evolution along the phylogenetic tree using Brownian motion (Saputra et al. 2021 / RERconverge null model).
158
+ * Computes empirical gene-level p-values (p<sub>gene</sub>) testing whether the length-normalized spectral energy (Ψ̄) or maximum site association (ρ<sub>max</sub>) exceeds neutral phylogenetic drift.
159
+
160
+ ---
161
+
162
+ ### Example 4: Ultra-Fast Episodic Positive Selection (`predict`), Feature Attribution (`--attribute`), & Alignment Error Filtering (`--filter`)
163
+
164
+ ```bash
165
+ # Standard per-codon episodic selection inference
166
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk -o examples/Smc6_results.json -c examples/Smc6_results.csv
167
+
168
+ # Enable mechanistic feature attribution (identifies driving species & evolutionary timing)
169
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk --attribute --attribution-min-lrt 3.84 -o examples/Smc6_attributed.json
170
+
171
+ # Run inference with automated dual-stage alignment error filtering & export cleaned alignment
172
+ hyphaeon meme -a examples/Smc6.fasta -t examples/Smc6.nwk --filter --filter-out-aln examples/Smc6_cleaned.fasta -c examples/Smc6_clean.csv
173
+ ```
174
+
175
+ #### 1. Mechanistic Feature Attribution (`--attribute`):
176
+ * **Single-Taxon Counterfactual Perturbation (ΔLRT)**: In silico mutates each non-consensus species back to ancestral state to rank driving taxa by marginal selection evidence explained (% Signal Explained).
177
+ * **Evolutionary Epoch Decomposition**: Classifies selection timing by weighted root patristic depth into **Recent Terminal / Tip Sweep** (≥ 0.60), **Intermediate Subclade Burst** (0.35–0.60), and **Deep Ancestral / Basal Divergence** (< 0.35), separating **Recurrent Multi-Lineage Adaptation** from single-lineage sweeps.
178
+
179
+ #### 2. Automated Alignment Error Screening (`--filter`):
180
+ * **Dual-Stage Algorithm**: Detects 1D selective clusters via exact upper-tail hypergeometric scan (p<sub>local</sub> ≤ 0.01), then evaluates the Outlier Contamination Index (OCI ≥ 0.25) to flag private frameshifts (≥ 3 contiguous radical mutations in an isolated leaf against conserved species).
181
+ * **Surgical In-Place Masking**: Automatically masks only the guilty taxon's anomalous span with `NNN` and re-evaluates the cleaned alignment in milliseconds, eliminating false positives while preserving legitimate multi-species selection.
182
+
183
+ ---
184
+
185
+ ### Example 5: Spectral Graph Bisection & Tree-Free Phylogenetic Splits (`hyphaeon splits`)
186
+
187
+ ```bash
188
+ # Basic Tree-Free Macro-Split Discovery (Outputs Newick Tree & Clade CSV)
189
+ hyphaeon splits \
190
+ -a examples/bat_oas1.fasta \
191
+ --no-tree \
192
+ -o examples/bat_oas1_spectral_tree.nwk \
193
+ -c examples/bat_oas1_clades.csv \
194
+ --cpu
195
+ ```
196
+
197
+ #### Spectral Bisection Architecture:
198
+ * **Multi-Modal Affinity Fusion**: Combines cross-taxa attention matrices ($\bar{\mathbf{A}}$) from the axial transformer, continuous 4D metric space from Multidimensional Scaling (MDS) on pairwise distances, and sequence-level latent representations into a fused affinity matrix $\mathbf{A}_{\text{fused}} = \mathbf{S}_{\text{attn}} \odot \mathbf{K}_{\text{MDS}} \odot \mathbf{K}_{\text{emb}}$.
199
+ * **Normalized Graph Laplacian & Fiedler Vector**: Partitions taxa along the Fiedler vector $\mathbf{v}_2$ of $\mathbf{L}_{\text{sym}} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A}_{\text{fused}} \mathbf{D}^{-1/2}$, quantifying macro-clade split stability via the spectral eigengap $\Delta\lambda = \lambda_3 - \lambda_2$.
200
+ * **Comprehensive Benchmarks**: See [`SPECTRAL_SPLITS_BENCHMARK.md`](SPECTRAL_SPLITS_BENCHMARK.md) for full benchmarks against IQ-TREE 2, RAxML-NG, FastTree, and Neighbor-Joining across empirical datasets.
201
+
202
+ ---
203
+
204
+ ## 🛠️ Retraining & Fine-Tuning HyphAeon
205
+
206
+ ### 1. Build per-gene training tensors
207
+
208
+ Prepare one alignment and one official HyPhy MEME JSON result per gene. Trees may be supplied as matching Newick files or embedded in the alignments:
209
+
210
+ ```bash
211
+ python training/build_training_npz.py \
212
+ --alignment_dir /path/to/training_alignments/ \
213
+ --tree_dir /path/to/trees/ \
214
+ --meme_dir /path/to/meme_results/ \
215
+ --output_dir /path/to/training_npz/
216
+ ```
217
+
218
+ ### 2. Fine-tune the foundation model
219
+
220
+ ```bash
221
+ python training/train.py \
222
+ --data_dir /path/to/training_npz/ \
223
+ --epochs 30 \
224
+ --batch_size 1 \
225
+ --lr 3e-4 \
226
+ --embed_dim 384 \
227
+ --layers 6 \
228
+ --heads 12 \
229
+ --fp16 \
230
+ --output_dir /path/to/run_weights/
231
+ ```
232
+
233
+ ---
234
+
235
+ ## ⚡ CLI Reference Summary
236
+
237
+ | Command | Action | Description |
238
+ | :--- | :--- | :--- |
239
+ | `hyphaeon meme` | Site-Level Selection | Fast per-codon LRT & selection rate prediction (100×–1,100× faster than MLE). |
240
+ | `hyphaeon epistasis` | 3D Epistatic Sectors | Co-selection networks, hypergeometric tree overlaps, and Monte Carlo sector permutations. |
241
+ | `hyphaeon dms` | Digital DMS | 19-AA in silico perturbation sweeps and Compensated Pathogenic Deviation mapping. |
242
+ | `hyphaeon phenotype`| Directional PhyloWAS | Directional trait mapping on the unit hypersphere, trait sector permutations, and liability permulations. |
243
+ | `hyphaeon temporal` | Dynamic Surveillance | Continuous logistic trajectory regression, sweep velocity, DTW waves, and temporal SVD. |
244
+ | `hyphaeon splits` | Spectral Bisection | Tree-free phylogenetic macro-splits via cross-taxa attention and MDS graph Laplacian. |
245
+ | `hyphaeon disease` | Pathogenicity Prediction | Predict disease variant effects and pathogenicity using HyphAeon attention attributions. |
246
+ | `hyphaeon filter` | Alignment QC | Automated alignment error detection and surgical masking of anomalous regions. |
247
+
248
+ ### Key Permutation Testing Arguments:
249
+
250
+ #### `hyphaeon epistasis`
251
+ | Flag | Type | Default | Description |
252
+ | :--- | :---: | :---: | :--- |
253
+ | `--n-permutations` | `int` | `10000` | Number of random K-site subset Monte Carlo permutations for sector significance testing (set `0` to disable). |
254
+ | `--max-perm-p` | `float` | `None` | Maximum empirical permutation p-value threshold to retain sectors (default retains all C(S) ≥ min_coherence). |
255
+ | `--min-coherence` | `float` | `0.50` | Minimum spectral coherence ratio C(S) = λ₁ / Tr for candidate sectors. |
256
+ | `--min-clique-size` | `int` | `3` | Minimum clique seed size for epistatic sectors. |
257
+ | `--max-overlap` | `float` | `0.50` | Maximum Jaccard overlap allowed between discovered sectors. |
258
+ | `--no-tree` / `--use-tn93` | `flag` | `False` | Estimate pairwise evolutionary distances directly from alignment via TN93 (skips tree). Requires the optional `tn93` package (`pip install hyphaeon[tn93]`) or the `tn93` binary on PATH. |
259
+
260
+ #### `hyphaeon phenotype`
261
+ | Flag | Type | Default | Description |
262
+ | :--- | :---: | :---: | :--- |
263
+ | `--n-permutations` | `int` | `10000` | Number of random K-site subset Monte Carlo permutations for trait sector significance testing (set `0` to disable). |
264
+ | `--max-perm-p` | `float` | `None` | Maximum permutation p-value threshold to retain trait sectors (default retains all C(S) ≥ 0.45). |
265
+ | `--permulations` | `int` | `0` | Number of Brownian motion phylogenetic permulations for gene-level empirical p-values (RERconverge null model; default `0` / parametric). |
266
+ | `--alpha` | `float` | `0.05` | Benjamini-Hochberg FDR significance threshold for trait-associated sites. |
267
+ | `--continuous` | `flag` | `False` | Treat trait values as continuous phylogenetic contrasts rather than discrete foreground/background. |
268
+ | `--min-taxa` | `int` | `4` | Minimum sequenced taxa required per site. |
269
+
270
+ #### `hyphaeon splits`
271
+ | Flag | Type | Default | Description |
272
+ | :--- | :---: | :---: | :--- |
273
+ | `-a` / `--alignment` | `path` | Required | Path to in-frame codon FASTA or NEXUS alignment. |
274
+ | `-t` / `--tree` | `path` | `None` | Optional Newick/NEXUS phylogenetic tree (optional if embedded, or if `--no-tree`/`--use-tn93` is set). |
275
+ | `--no-tree` / `--use-tn93` | `flag` | `False` | Skip phylogenetic tree and estimate pairwise evolutionary distances directly from alignment via TN93. Requires `tn93` (`pip install hyphaeon[tn93]`) or the `tn93` binary on PATH. |
276
+ | `--min-clade-size` | `int` | `2` | Minimum clade size floor to terminate recursive bisection. |
277
+ | `--max-depth` | `int` | `10` | Maximum tree hierarchy recursion depth. |
278
+ | `-o` / `--output` | `path` | `None` | Optional path to export derived hierarchical Newick tree (`.nwk`). |
279
+ | `-c` / `--csv` | `path` | `None` | Optional path to export split clade membership assignments (`.csv`). |
280
+ | `-w` / `--weights` | `path` | `None` | Path to local model weights file (overrides HF download). |
281
+ | `--cpu` | `flag` | `False` | Force CPU execution. |
282
+
283
+ ---
284
+
285
+ ## 📜 Citation
286
+
287
+ If you use **HyphAeon** in your research, please cite:
288
+
289
+ ```bibtex
290
+ @article{hyphaeon2026,
291
+ title={HyphAeon: Attention on Evolution Across Deep Time Transforms Comparative Genomics},
292
+ author={Kosakovsky Pond, Sergei L. and Weaver, Steven and Callan, Danielle and Zehr, Jordan D. and Lucaci, Alexander G. and Verdonk, Hannah and Selberg, Avery and Brown, Gallean and Chikina, Maria and Clark, Nathan and Makova, Kateryna D. and Martin, Darren P. and Nekrutenko, Anton},
293
+ journal={Nature Methods / Nature Biotechnology (in submission)},
294
+ year={2026}
295
+ }
296
+ ```