trellis-protein 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 (37) hide show
  1. trellis_protein-0.1.0/LICENSE.md +25 -0
  2. trellis_protein-0.1.0/PKG-INFO +332 -0
  3. trellis_protein-0.1.0/README.md +287 -0
  4. trellis_protein-0.1.0/pyproject.toml +30 -0
  5. trellis_protein-0.1.0/setup.cfg +4 -0
  6. trellis_protein-0.1.0/tests/test_auspice_io.py +129 -0
  7. trellis_protein-0.1.0/tests/test_cache.py +126 -0
  8. trellis_protein-0.1.0/tests/test_energy.py +151 -0
  9. trellis_protein-0.1.0/tests/test_fitness.py +118 -0
  10. trellis_protein-0.1.0/tests/test_fold_bb.py +270 -0
  11. trellis_protein-0.1.0/tests/test_fold_enum.py +221 -0
  12. trellis_protein-0.1.0/tests/test_generate_trajectories.py +55 -0
  13. trellis_protein-0.1.0/tests/test_genetic_code.py +177 -0
  14. trellis_protein-0.1.0/tests/test_lattice.py +85 -0
  15. trellis_protein-0.1.0/tests/test_ligand.py +125 -0
  16. trellis_protein-0.1.0/tests/test_phylogeny.py +145 -0
  17. trellis_protein-0.1.0/tests/test_sswm.py +195 -0
  18. trellis_protein-0.1.0/tests/test_trajectory_io.py +234 -0
  19. trellis_protein-0.1.0/trellis/__init__.py +1 -0
  20. trellis_protein-0.1.0/trellis/auspice_io.py +116 -0
  21. trellis_protein-0.1.0/trellis/cache.py +43 -0
  22. trellis_protein-0.1.0/trellis/energy.py +113 -0
  23. trellis_protein-0.1.0/trellis/fitness.py +99 -0
  24. trellis_protein-0.1.0/trellis/fold_bb.py +172 -0
  25. trellis_protein-0.1.0/trellis/fold_enum.py +696 -0
  26. trellis_protein-0.1.0/trellis/genetic_code.py +105 -0
  27. trellis_protein-0.1.0/trellis/lattice.py +112 -0
  28. trellis_protein-0.1.0/trellis/ligand.py +91 -0
  29. trellis_protein-0.1.0/trellis/mj_matrix.csv +21 -0
  30. trellis_protein-0.1.0/trellis/phylogeny.py +153 -0
  31. trellis_protein-0.1.0/trellis/sswm.py +251 -0
  32. trellis_protein-0.1.0/trellis/trajectory_io.py +105 -0
  33. trellis_protein-0.1.0/trellis_protein.egg-info/PKG-INFO +332 -0
  34. trellis_protein-0.1.0/trellis_protein.egg-info/SOURCES.txt +35 -0
  35. trellis_protein-0.1.0/trellis_protein.egg-info/dependency_links.txt +1 -0
  36. trellis_protein-0.1.0/trellis_protein.egg-info/requires.txt +12 -0
  37. trellis_protein-0.1.0/trellis_protein.egg-info/top_level.txt +2 -0
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trevor Bedford
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.
22
+
23
+ ## Additional Notes on LLM-Generated Content
24
+
25
+ This repository contains a mix of code authored by the repository owner and code generated by large language models (LLMs). While the MIT License applies to the code as a whole, I do not assert copyright over any portions of the code that were generated by LLMs, as the copyright status of such content may vary depending on jurisdiction. Users are encouraged to independently verify the copyright status of LLM-generated portions before reuse or redistribution.
@@ -0,0 +1,332 @@
1
+ Metadata-Version: 2.4
2
+ Name: trellis-protein
3
+ Version: 0.1.0
4
+ Summary: Lattice protein synthetic data for evolutionary trajectory models
5
+ Author: Trevor Bedford
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Trevor Bedford
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ ## Additional Notes on LLM-Generated Content
29
+
30
+ This repository contains a mix of code authored by the repository owner and code generated by large language models (LLMs). While the MIT License applies to the code as a whole, I do not assert copyright over any portions of the code that were generated by LLMs, as the copyright status of such content may vary depending on jurisdiction. Users are encouraged to independently verify the copyright status of LLM-generated portions before reuse or redistribution.
31
+
32
+ Requires-Python: >=3.11
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE.md
35
+ Requires-Dist: numpy>=1.24
36
+ Requires-Dist: numba>=0.58
37
+ Requires-Dist: zstandard>=0.21
38
+ Provides-Extra: aws
39
+ Requires-Dist: boto3>=1.28; extra == "aws"
40
+ Provides-Extra: analysis
41
+ Requires-Dist: matplotlib>=3.7; extra == "analysis"
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=7.0; extra == "dev"
44
+ Dynamic: license-file
45
+
46
+ # trellis
47
+
48
+ Lattice protein synthetic data for evolutionary trajectory models.
49
+
50
+ Trellis generates evolutionary trajectories on a lattice-protein fitness
51
+ landscape. Proteins are 18-residue chains on a 2D square lattice, folded by
52
+ exhaustive enumeration with a Miyazawa-Jernigan contact potential and numba
53
+ JIT-compiled scoring. Fitness is fraction-folded times native binding energy
54
+ to a fixed lattice ligand, following Bloom et al. (2004). Evolution proceeds
55
+ under SSWM dynamics at the DNA level: single-nucleotide mutations arise and
56
+ fix according to Kimura fixation probabilities. Output is written in a FASTA
57
+ format compatible with the
58
+ [blab/trajectories](https://github.com/blab/trajectories) preprocessing
59
+ pipeline.
60
+
61
+ For technical details, see [FOLDING.md](FOLDING.md) (lattice geometry, MJ
62
+ potential, folding algorithms, mean-field pruning) and
63
+ [EVOLUTION.md](EVOLUTION.md) (fitness function, genetic code, SSWM dynamics).
64
+ The full design history is in [`notes/`](notes/).
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ pip install trellis-protein
70
+ ```
71
+
72
+ Downstream code imports as `trellis` (the PyPI distribution is published as
73
+ `trellis-protein` because `trellis` is taken). For local development on
74
+ this repo:
75
+
76
+ ```bash
77
+ pip install -e ".[dev]"
78
+ ```
79
+
80
+ Requires Python >= 3.11. Runtime dependencies: `numpy`, `numba`,
81
+ `zstandard`. Optional extras: `[aws]` (boto3, for `scripts/s3.py`),
82
+ `[analysis]` (matplotlib), `[dev]` (pytest).
83
+
84
+ ## Fold a single sequence
85
+
86
+ `scripts/fold_sequence.py` folds a single amino acid or DNA sequence
87
+ and prints native energy, partition function, conformation coordinates,
88
+ and wall time. With a ligand, it also reports ensemble-averaged binding
89
+ energy and fitness.
90
+
91
+ ```bash
92
+ # Fold an amino acid sequence
93
+ python scripts/fold_sequence.py --aa ACDEFGHIKLMNPQRSTVWY
94
+
95
+ # Fold with a ligand (reports binding energy and fitness)
96
+ python scripts/fold_sequence.py --aa ACDEFGHIKLMNPQRSTVWY --ligand-sequence FWYL
97
+
98
+ # Machine-readable JSON output
99
+ python scripts/fold_sequence.py --aa ACDEFG --json
100
+ ```
101
+
102
+ ## Generate and visualize a single trajectory
103
+
104
+ `scripts/generate_viz_trajectory.py` runs a short SSWM trajectory and
105
+ writes a JSON snapshot for the interactive D3 dashboard. A live example is
106
+ at https://blab.github.io/trellis/viz/.
107
+
108
+ ```bash
109
+ python scripts/generate_viz_trajectory.py
110
+ ```
111
+
112
+ This runs with defaults (`--chain-length 10 --n-steps 100 --Ne 50
113
+ --temperature 1.0 --seed 42`) and writes `viz/viz_trajectory_data.json`.
114
+ Serve the repo root and open `viz/index.html`:
115
+
116
+ ```bash
117
+ python -m http.server 8000
118
+ # open http://localhost:8000/viz/index.html
119
+ ```
120
+
121
+ See [`viz/README.md`](viz/README.md) for details.
122
+
123
+ ## Generate trajectories
124
+
125
+ `scripts/generate_trajectories.py` is the main CLI for bulk trajectory
126
+ generation. It runs SSWM trajectories in parallel, splits into train/test
127
+ sets, and packages them as compressed FASTA shards.
128
+
129
+ ```bash
130
+ # Generate 1000 trajectories for a single ligand
131
+ python scripts/generate_trajectories.py \
132
+ --n-trajectories 1000 \
133
+ --n-steps 100 \
134
+ --chain-length 18 \
135
+ --ligand-sequence KEMN \
136
+ --Ne 50 \
137
+ --n-workers 8 \
138
+ --seed 42
139
+
140
+ # Generate trajectories across multiple random ligands
141
+ python scripts/generate_trajectories.py \
142
+ --n-random-ligands 8 \
143
+ --n-trajectories 100 \
144
+ --chain-length 18 \
145
+ --Ne 50 \
146
+ --n-workers 32 \
147
+ --seed 42
148
+ ```
149
+
150
+ Output:
151
+
152
+ ```
153
+ results/trellis-18aa-KEMN/
154
+ ├── forwards-train-000.tar.zst
155
+ ├── forwards-test-000.tar.zst
156
+ └── metadata.json
157
+ ```
158
+
159
+ Each worker process loads its own MJ matrix, ligand, and conformation
160
+ database. Per-trajectory RNG streams are created via `SeedSequence.spawn()`
161
+ for reproducibility regardless of worker count. See
162
+ [BENCHMARK.md](BENCHMARK.md) for timing data.
163
+
164
+ ## Generate phylogenies
165
+
166
+ `scripts/generate_phylogeny.py` generates a single phylogenetic tree via
167
+ Yule-with-sampling on SSWM dynamics. At each time step, active lineages
168
+ may speciate (rate beta), get sampled as tips (rate psi), or continue as
169
+ single daughters. Mutations are drawn from SSWM fixation probabilities.
170
+ Output is Auspice v2 JSON viewable at [auspice.us](https://auspice.us).
171
+
172
+ ```bash
173
+ # Generate a phylogeny with default parameters
174
+ # Default is 18-mer, which may take a while
175
+ python scripts/generate_phylogeny.py --output results/phylogeny.json
176
+
177
+ # Specify ligand and specify protein length
178
+ python scripts/generate_phylogeny.py \
179
+ --chain-length 12 \
180
+ --ligand-sequence KEMN \
181
+ --output results/phylogeny.json
182
+ ```
183
+
184
+ Key parameters:
185
+ - `--beta`: speciation probability per lineage per step (default 0.08)
186
+ - `--psi`: sampling probability per lineage per step (default 0.05)
187
+ - `--min-active`: minimum active lineages preserved against sampling (default 1)
188
+ - `--max-active`: cap on active lineages per step (default 100)
189
+ - `--max-nodes`: hard cap on total tree size (default 5000)
190
+
191
+ ## Evaluation interface
192
+
193
+ `trellis.sswm.compute_sswm_probabilities` exposes the ground-truth SSWM
194
+ fixation-probability distribution over all single-nucleotide neighbors of
195
+ a reference DNA sequence. Downstream evaluation code uses this as the
196
+ oracle when scoring how well a learned model has recovered the fitness
197
+ landscape.
198
+
199
+ ```python
200
+ from trellis.cache import FitnessCache
201
+ from trellis.energy import load_mj_matrix
202
+ from trellis.fitness import compute_fitness_aa
203
+ from trellis.fold_enum import enumerate_conformations
204
+ from trellis.genetic_code import translate
205
+ from trellis.ligand import create_ligand
206
+ from trellis.sswm import compute_sswm_probabilities, pfix_for_target
207
+
208
+ # One-time setup per ligand
209
+ mj = load_mj_matrix()
210
+ ligand = create_ligand("KEMN", anchor=(0, -1))
211
+ db = enumerate_conformations(18, ligand)
212
+ cache = FitnessCache()
213
+
214
+ # Per-reference evaluation
215
+ ref_aa = translate(ref_dna)
216
+ if ref_aa not in cache:
217
+ cache.put(ref_aa, compute_fitness_aa(ref_aa, ligand, mj, 1.0, db=db))
218
+ ref_fitness = cache.get(ref_aa).fitness
219
+
220
+ mutant_dnas, ground_truth = compute_sswm_probabilities(
221
+ ref_dna, ref_fitness, ligand, mj, Ne=50.0, temperature=1.0,
222
+ fitness_cache=cache, db=db,
223
+ )
224
+ # ground_truth sums to 1 (or is all zeros if every neighbor is lethal)
225
+
226
+ # Single mutation lookup
227
+ p = pfix_for_target(ref_dna, target_dna, ligand, mj,
228
+ Ne=50.0, temperature=1.0,
229
+ fitness_cache=cache, db=db)
230
+ ```
231
+
232
+ Share the `FitnessCache` across all evaluations for a given ligand —
233
+ folding is the dominant cost, and the cache amortizes it.
234
+
235
+ The CLI `scripts/pfix_distribution.py` exercises the same API for
236
+ exploration:
237
+
238
+ ```bash
239
+ # Full distribution for a reference sequence
240
+ python scripts/pfix_distribution.py \
241
+ --reference CTCTGCAACACAACACGGCTCGATGTTCTCTATGGAGAATGTGACTGCGCGCTG \
242
+ --ligand KEMN --Ne 50
243
+
244
+ # Single-mutation P_fix as JSON
245
+ python scripts/pfix_distribution.py \
246
+ --reference <ref-dna> --target <neighbor-dna> \
247
+ --ligand KEMN --Ne 50 --json
248
+ ```
249
+
250
+ ## Sync results with S3
251
+
252
+ `scripts/s3.py` moves dataset directories between local `results/` and S3.
253
+ Requires environment variables `S3_BUCKET`, `AWS_ACCESS_KEY_ID`, and
254
+ `AWS_SECRET_ACCESS_KEY`. Install the optional AWS dependency with
255
+ `pip install -e ".[aws]"`.
256
+
257
+ ```bash
258
+ # List available datasets on S3
259
+ python scripts/s3.py list
260
+
261
+ # Download a specific dataset
262
+ python scripts/s3.py pull trellis-18aa-KEMN
263
+
264
+ # Download all datasets
265
+ python scripts/s3.py pull --all
266
+
267
+ # Upload a dataset to S3
268
+ python scripts/s3.py push trellis-18aa-KEMN
269
+ ```
270
+
271
+ Both subcommands prompt before overwriting existing data; pass `--force`
272
+ to skip confirmation.
273
+
274
+ ## Run tests
275
+
276
+ ```bash
277
+ pytest
278
+ ```
279
+
280
+ Or a single module:
281
+
282
+ ```bash
283
+ pytest tests/test_lattice.py -v
284
+ pytest tests/test_energy.py -v
285
+ ```
286
+
287
+ ## Repository layout
288
+
289
+ ```
290
+ trellis/
291
+ ├── trellis/
292
+ │ ├── __init__.py
293
+ │ ├── lattice.py # 2D lattice, SAW enumeration
294
+ │ ├── energy.py # MJ matrix, conformation energy
295
+ │ ├── fold_bb.py # branch-and-bound folding (reference)
296
+ │ ├── fold_enum.py # pre-enumeration folding (production)
297
+ │ ├── ligand.py # ligand placement, binding energy
298
+ │ ├── fitness.py # fitness function
299
+ │ ├── genetic_code.py # codon table, translation, mutations
300
+ │ ├── sswm.py # SSWM trajectory generation
301
+ │ ├── phylogeny.py # phylogenetic tree generation
302
+ │ ├── auspice_io.py # Auspice v2 JSON serialization
303
+ │ ├── trajectory_io.py # FASTA / tar.zst output
304
+ │ ├── cache.py # fitness cache
305
+ │ └── mj_matrix.csv # MJ 1985 contact potential
306
+ ├── tests/
307
+ ├── scripts/
308
+ │ ├── generate_trajectories.py # bulk parallel trajectory generation
309
+ │ ├── generate_phylogeny.py # single phylogenetic tree generation
310
+ │ ├── generate_viz_trajectory.py # single trajectory for D3 dashboard
311
+ │ ├── pfix_distribution.py # SSWM fixation-probability distribution
312
+ │ ├── fold_sequence.py # fold a single sequence
313
+ │ ├── inspect_shard.py # inspect / extract tar.zst shards
314
+ │ ├── s3.py # push/pull results to/from S3
315
+ │ ├── benchmark.py # single-worker pipeline benchmark
316
+ │ └── benchmark_bb_vs_enum.py # B&B vs pre-enumeration comparison
317
+ ├── viz/
318
+ │ ├── index.html # D3 dashboard
319
+ │ └── README.md
320
+ ├── notes/ # design history and rationale
321
+ ├── FOLDING.md # folding technical reference
322
+ ├── EVOLUTION.md # evolutionary model technical reference
323
+ ├── BENCHMARK.md # performance benchmarks
324
+ ├── PRODUCTION.md # production run instructions
325
+ ├── pyproject.toml
326
+ ├── LICENSE.md
327
+ └── README.md
328
+ ```
329
+
330
+ ## Todo
331
+
332
+ 1. Overview analysis of these 1000 trajectories, confirm that they don't converge
@@ -0,0 +1,287 @@
1
+ # trellis
2
+
3
+ Lattice protein synthetic data for evolutionary trajectory models.
4
+
5
+ Trellis generates evolutionary trajectories on a lattice-protein fitness
6
+ landscape. Proteins are 18-residue chains on a 2D square lattice, folded by
7
+ exhaustive enumeration with a Miyazawa-Jernigan contact potential and numba
8
+ JIT-compiled scoring. Fitness is fraction-folded times native binding energy
9
+ to a fixed lattice ligand, following Bloom et al. (2004). Evolution proceeds
10
+ under SSWM dynamics at the DNA level: single-nucleotide mutations arise and
11
+ fix according to Kimura fixation probabilities. Output is written in a FASTA
12
+ format compatible with the
13
+ [blab/trajectories](https://github.com/blab/trajectories) preprocessing
14
+ pipeline.
15
+
16
+ For technical details, see [FOLDING.md](FOLDING.md) (lattice geometry, MJ
17
+ potential, folding algorithms, mean-field pruning) and
18
+ [EVOLUTION.md](EVOLUTION.md) (fitness function, genetic code, SSWM dynamics).
19
+ The full design history is in [`notes/`](notes/).
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install trellis-protein
25
+ ```
26
+
27
+ Downstream code imports as `trellis` (the PyPI distribution is published as
28
+ `trellis-protein` because `trellis` is taken). For local development on
29
+ this repo:
30
+
31
+ ```bash
32
+ pip install -e ".[dev]"
33
+ ```
34
+
35
+ Requires Python >= 3.11. Runtime dependencies: `numpy`, `numba`,
36
+ `zstandard`. Optional extras: `[aws]` (boto3, for `scripts/s3.py`),
37
+ `[analysis]` (matplotlib), `[dev]` (pytest).
38
+
39
+ ## Fold a single sequence
40
+
41
+ `scripts/fold_sequence.py` folds a single amino acid or DNA sequence
42
+ and prints native energy, partition function, conformation coordinates,
43
+ and wall time. With a ligand, it also reports ensemble-averaged binding
44
+ energy and fitness.
45
+
46
+ ```bash
47
+ # Fold an amino acid sequence
48
+ python scripts/fold_sequence.py --aa ACDEFGHIKLMNPQRSTVWY
49
+
50
+ # Fold with a ligand (reports binding energy and fitness)
51
+ python scripts/fold_sequence.py --aa ACDEFGHIKLMNPQRSTVWY --ligand-sequence FWYL
52
+
53
+ # Machine-readable JSON output
54
+ python scripts/fold_sequence.py --aa ACDEFG --json
55
+ ```
56
+
57
+ ## Generate and visualize a single trajectory
58
+
59
+ `scripts/generate_viz_trajectory.py` runs a short SSWM trajectory and
60
+ writes a JSON snapshot for the interactive D3 dashboard. A live example is
61
+ at https://blab.github.io/trellis/viz/.
62
+
63
+ ```bash
64
+ python scripts/generate_viz_trajectory.py
65
+ ```
66
+
67
+ This runs with defaults (`--chain-length 10 --n-steps 100 --Ne 50
68
+ --temperature 1.0 --seed 42`) and writes `viz/viz_trajectory_data.json`.
69
+ Serve the repo root and open `viz/index.html`:
70
+
71
+ ```bash
72
+ python -m http.server 8000
73
+ # open http://localhost:8000/viz/index.html
74
+ ```
75
+
76
+ See [`viz/README.md`](viz/README.md) for details.
77
+
78
+ ## Generate trajectories
79
+
80
+ `scripts/generate_trajectories.py` is the main CLI for bulk trajectory
81
+ generation. It runs SSWM trajectories in parallel, splits into train/test
82
+ sets, and packages them as compressed FASTA shards.
83
+
84
+ ```bash
85
+ # Generate 1000 trajectories for a single ligand
86
+ python scripts/generate_trajectories.py \
87
+ --n-trajectories 1000 \
88
+ --n-steps 100 \
89
+ --chain-length 18 \
90
+ --ligand-sequence KEMN \
91
+ --Ne 50 \
92
+ --n-workers 8 \
93
+ --seed 42
94
+
95
+ # Generate trajectories across multiple random ligands
96
+ python scripts/generate_trajectories.py \
97
+ --n-random-ligands 8 \
98
+ --n-trajectories 100 \
99
+ --chain-length 18 \
100
+ --Ne 50 \
101
+ --n-workers 32 \
102
+ --seed 42
103
+ ```
104
+
105
+ Output:
106
+
107
+ ```
108
+ results/trellis-18aa-KEMN/
109
+ ├── forwards-train-000.tar.zst
110
+ ├── forwards-test-000.tar.zst
111
+ └── metadata.json
112
+ ```
113
+
114
+ Each worker process loads its own MJ matrix, ligand, and conformation
115
+ database. Per-trajectory RNG streams are created via `SeedSequence.spawn()`
116
+ for reproducibility regardless of worker count. See
117
+ [BENCHMARK.md](BENCHMARK.md) for timing data.
118
+
119
+ ## Generate phylogenies
120
+
121
+ `scripts/generate_phylogeny.py` generates a single phylogenetic tree via
122
+ Yule-with-sampling on SSWM dynamics. At each time step, active lineages
123
+ may speciate (rate beta), get sampled as tips (rate psi), or continue as
124
+ single daughters. Mutations are drawn from SSWM fixation probabilities.
125
+ Output is Auspice v2 JSON viewable at [auspice.us](https://auspice.us).
126
+
127
+ ```bash
128
+ # Generate a phylogeny with default parameters
129
+ # Default is 18-mer, which may take a while
130
+ python scripts/generate_phylogeny.py --output results/phylogeny.json
131
+
132
+ # Specify ligand and specify protein length
133
+ python scripts/generate_phylogeny.py \
134
+ --chain-length 12 \
135
+ --ligand-sequence KEMN \
136
+ --output results/phylogeny.json
137
+ ```
138
+
139
+ Key parameters:
140
+ - `--beta`: speciation probability per lineage per step (default 0.08)
141
+ - `--psi`: sampling probability per lineage per step (default 0.05)
142
+ - `--min-active`: minimum active lineages preserved against sampling (default 1)
143
+ - `--max-active`: cap on active lineages per step (default 100)
144
+ - `--max-nodes`: hard cap on total tree size (default 5000)
145
+
146
+ ## Evaluation interface
147
+
148
+ `trellis.sswm.compute_sswm_probabilities` exposes the ground-truth SSWM
149
+ fixation-probability distribution over all single-nucleotide neighbors of
150
+ a reference DNA sequence. Downstream evaluation code uses this as the
151
+ oracle when scoring how well a learned model has recovered the fitness
152
+ landscape.
153
+
154
+ ```python
155
+ from trellis.cache import FitnessCache
156
+ from trellis.energy import load_mj_matrix
157
+ from trellis.fitness import compute_fitness_aa
158
+ from trellis.fold_enum import enumerate_conformations
159
+ from trellis.genetic_code import translate
160
+ from trellis.ligand import create_ligand
161
+ from trellis.sswm import compute_sswm_probabilities, pfix_for_target
162
+
163
+ # One-time setup per ligand
164
+ mj = load_mj_matrix()
165
+ ligand = create_ligand("KEMN", anchor=(0, -1))
166
+ db = enumerate_conformations(18, ligand)
167
+ cache = FitnessCache()
168
+
169
+ # Per-reference evaluation
170
+ ref_aa = translate(ref_dna)
171
+ if ref_aa not in cache:
172
+ cache.put(ref_aa, compute_fitness_aa(ref_aa, ligand, mj, 1.0, db=db))
173
+ ref_fitness = cache.get(ref_aa).fitness
174
+
175
+ mutant_dnas, ground_truth = compute_sswm_probabilities(
176
+ ref_dna, ref_fitness, ligand, mj, Ne=50.0, temperature=1.0,
177
+ fitness_cache=cache, db=db,
178
+ )
179
+ # ground_truth sums to 1 (or is all zeros if every neighbor is lethal)
180
+
181
+ # Single mutation lookup
182
+ p = pfix_for_target(ref_dna, target_dna, ligand, mj,
183
+ Ne=50.0, temperature=1.0,
184
+ fitness_cache=cache, db=db)
185
+ ```
186
+
187
+ Share the `FitnessCache` across all evaluations for a given ligand —
188
+ folding is the dominant cost, and the cache amortizes it.
189
+
190
+ The CLI `scripts/pfix_distribution.py` exercises the same API for
191
+ exploration:
192
+
193
+ ```bash
194
+ # Full distribution for a reference sequence
195
+ python scripts/pfix_distribution.py \
196
+ --reference CTCTGCAACACAACACGGCTCGATGTTCTCTATGGAGAATGTGACTGCGCGCTG \
197
+ --ligand KEMN --Ne 50
198
+
199
+ # Single-mutation P_fix as JSON
200
+ python scripts/pfix_distribution.py \
201
+ --reference <ref-dna> --target <neighbor-dna> \
202
+ --ligand KEMN --Ne 50 --json
203
+ ```
204
+
205
+ ## Sync results with S3
206
+
207
+ `scripts/s3.py` moves dataset directories between local `results/` and S3.
208
+ Requires environment variables `S3_BUCKET`, `AWS_ACCESS_KEY_ID`, and
209
+ `AWS_SECRET_ACCESS_KEY`. Install the optional AWS dependency with
210
+ `pip install -e ".[aws]"`.
211
+
212
+ ```bash
213
+ # List available datasets on S3
214
+ python scripts/s3.py list
215
+
216
+ # Download a specific dataset
217
+ python scripts/s3.py pull trellis-18aa-KEMN
218
+
219
+ # Download all datasets
220
+ python scripts/s3.py pull --all
221
+
222
+ # Upload a dataset to S3
223
+ python scripts/s3.py push trellis-18aa-KEMN
224
+ ```
225
+
226
+ Both subcommands prompt before overwriting existing data; pass `--force`
227
+ to skip confirmation.
228
+
229
+ ## Run tests
230
+
231
+ ```bash
232
+ pytest
233
+ ```
234
+
235
+ Or a single module:
236
+
237
+ ```bash
238
+ pytest tests/test_lattice.py -v
239
+ pytest tests/test_energy.py -v
240
+ ```
241
+
242
+ ## Repository layout
243
+
244
+ ```
245
+ trellis/
246
+ ├── trellis/
247
+ │ ├── __init__.py
248
+ │ ├── lattice.py # 2D lattice, SAW enumeration
249
+ │ ├── energy.py # MJ matrix, conformation energy
250
+ │ ├── fold_bb.py # branch-and-bound folding (reference)
251
+ │ ├── fold_enum.py # pre-enumeration folding (production)
252
+ │ ├── ligand.py # ligand placement, binding energy
253
+ │ ├── fitness.py # fitness function
254
+ │ ├── genetic_code.py # codon table, translation, mutations
255
+ │ ├── sswm.py # SSWM trajectory generation
256
+ │ ├── phylogeny.py # phylogenetic tree generation
257
+ │ ├── auspice_io.py # Auspice v2 JSON serialization
258
+ │ ├── trajectory_io.py # FASTA / tar.zst output
259
+ │ ├── cache.py # fitness cache
260
+ │ └── mj_matrix.csv # MJ 1985 contact potential
261
+ ├── tests/
262
+ ├── scripts/
263
+ │ ├── generate_trajectories.py # bulk parallel trajectory generation
264
+ │ ├── generate_phylogeny.py # single phylogenetic tree generation
265
+ │ ├── generate_viz_trajectory.py # single trajectory for D3 dashboard
266
+ │ ├── pfix_distribution.py # SSWM fixation-probability distribution
267
+ │ ├── fold_sequence.py # fold a single sequence
268
+ │ ├── inspect_shard.py # inspect / extract tar.zst shards
269
+ │ ├── s3.py # push/pull results to/from S3
270
+ │ ├── benchmark.py # single-worker pipeline benchmark
271
+ │ └── benchmark_bb_vs_enum.py # B&B vs pre-enumeration comparison
272
+ ├── viz/
273
+ │ ├── index.html # D3 dashboard
274
+ │ └── README.md
275
+ ├── notes/ # design history and rationale
276
+ ├── FOLDING.md # folding technical reference
277
+ ├── EVOLUTION.md # evolutionary model technical reference
278
+ ├── BENCHMARK.md # performance benchmarks
279
+ ├── PRODUCTION.md # production run instructions
280
+ ├── pyproject.toml
281
+ ├── LICENSE.md
282
+ └── README.md
283
+ ```
284
+
285
+ ## Todo
286
+
287
+ 1. Overview analysis of these 1000 trajectories, confirm that they don't converge
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "trellis-protein"
7
+ version = "0.1.0"
8
+ description = "Lattice protein synthetic data for evolutionary trajectory models"
9
+ readme = "README.md"
10
+ license = {file = "LICENSE.md"}
11
+ requires-python = ">=3.11"
12
+ authors = [
13
+ {name = "Trevor Bedford"},
14
+ ]
15
+ dependencies = [
16
+ "numpy>=1.24",
17
+ "numba>=0.58",
18
+ "zstandard>=0.21",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ aws = ["boto3>=1.28"]
23
+ analysis = ["matplotlib>=3.7"]
24
+ dev = ["pytest>=7.0"]
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["trellis*"]
28
+
29
+ [tool.setuptools.package-data]
30
+ trellis = ["mj_matrix.csv"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+