vhamster 1.3.1__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.
vhamster-1.3.1/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Lawrence Berkeley National Laboratory
2
+ NON-COMMERCIAL USE ONLY LICENSE
3
+
4
+ V-HAMSTeR Copyright (c) 2026, The Regents of the University of California, through Lawrence Berkeley National Laboratory (“Berkeley Lab”) subject to receipt of any required approvals from the U.S. Dept. of Energy. All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ (3) Neither the name of the University of California, Berkeley Lab, U.S. Dept. of Energy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Berkeley Lab.
13
+
14
+ (4) Use of the software, in source or binary form is for NON-COMMERCIAL USE purposes ONLY. The software is not available for commercial use. If you have any questions regarding this software, please contact Berkeley Lab at IPO@lbl.gov.
15
+
16
+ (5) User agrees to indemnify, defend, and hold harmless Berkeley Lab, the U.S. Government, the software developers, the software sponsors, and their agents, officers, and employees, against any and all claims, suits, losses, damage, costs, fees, and expenses arising out of or in connection with this Agreement. User agrees to pay all costs incurred by Berkeley Lab in enforcing this provision, including reasonable attorney fees.
17
+
18
+ (6) In the event User creates any bug fixes, patches, upgrades, updates, modifications, derivative works or enhancements to the source code or binary code of the software ("Enhancements") User hereby grants Berkeley Lab and the U.S. Government a paid-up, non-exclusive, irrevocable, worldwide license in the Enhancements to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: vhamster
3
+ Version: 1.3.1
4
+ Summary: VHAMSTeR ensemble inference CLI
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: click<9,>=8.3
9
+ Requires-Dist: loguru<1,>=0.7
10
+ Requires-Dist: numpy<3,>=2.4
11
+ Requires-Dist: polars<2,>=1.39
12
+ Requires-Dist: torch<3,>=2.11
13
+ Requires-Dist: tqdm<5,>=4.67
14
+ Requires-Dist: transformers<6,>=5.4
15
+ Requires-Dist: peft<1,>=0.18
16
+ Requires-Dist: biopython<2,>=1.87
17
+ Requires-Dist: pyrodigal-gv<0.4,>=0.3.2
18
+ Requires-Dist: scikit-learn<2,>=1.8
19
+ Requires-Dist: joblib<2,>=1.4
20
+ Requires-Dist: huggingface_hub<2,>=0.23
21
+ Requires-Dist: xgboost<3,>=2.1
22
+ Dynamic: license-file
23
+
24
+ # VHAMSTeR
25
+ ![](vhamsterlogo.png)
26
+
27
+
28
+ **V**irus **H**ost **A**ssignment **M**odel using **S**equence **T**ransformers and **R**eading-frames
29
+
30
+ VHAMSTeR uses a genomic language model to predict the host of a virus as one of: animal, plant, fungi, protist, or prokaryote.
31
+
32
+ It is designed for viral sequences up to 10 kbp. Longer sequences are split
33
+ into 10 kbp chunks (with a `_chunk<start>_<end>` suffix appended to the accession).
34
+ Each chunk is scored independently, and the chunk predictions are mean-pooled to
35
+ produce a genome-level consensus prediction.
36
+
37
+ ## Dependencies
38
+
39
+ ### Python packages (installed automatically)
40
+
41
+ - `click`
42
+ - `loguru`
43
+ - `torch`
44
+ - `transformers`
45
+ - `peft`
46
+ - `numpy`
47
+ - `polars`
48
+ - `biopython`
49
+ - `pyrodigal-gv`
50
+ - `tqdm`
51
+ - `scikit-learn`
52
+ - `xgboost`
53
+ - `joblib`
54
+
55
+ ### External tools
56
+
57
+ - `mmseqs2` — used for geNomad marker search. If you use the conda environment (see below), it is included automatically. Otherwise install it via conda/mamba:
58
+
59
+ ```bash
60
+ conda install -c bioconda mmseqs2
61
+ ```
62
+
63
+ Alternatively, precompiled static binaries are available from the [MMseqs2 GitHub releases](https://github.com/soedinglab/MMseqs2/releases).
64
+
65
+ ### geNomad database
66
+
67
+ A geNomad database is required at runtime. `vhamster-install-models` downloads it automatically from [Zenodo](https://zenodo.org/records/14886553). If you have an existing geNomad database you can point to it with `--genomad-db` instead.
68
+
69
+ ## Installation
70
+
71
+ ### pip (editable install from repo)
72
+
73
+ Clone the repository and install from the repository root:
74
+
75
+ ```bash
76
+ git clone https://code.jgi.doe.gov/SusieGrigson/vhamster.git
77
+ cd vhamster
78
+ pip install -e .
79
+ ```
80
+
81
+ This installs all Python dependencies listed in `pyproject.toml` and registers the
82
+ `vhamster` and `vhamster-install-models` shell commands.
83
+
84
+ > **Note:** `mmseqs2` is not a Python package and must be installed separately (see above).
85
+
86
+ ### Optional GPU support
87
+
88
+ CUDA is only needed if you want to run on GPU. CPU inference is supported and is
89
+ often fast enough unless you are processing a large amount of data.
90
+
91
+ If you want GPU support, install a PyTorch build that matches your CUDA version.
92
+ Visit https://pytorch.org/get-started/locally/ to get the right command for your
93
+ setup, for example:
94
+
95
+ ```bash
96
+ # CUDA 12.1
97
+ pip install torch --index-url https://download.pytorch.org/whl/cu121
98
+
99
+ # CPU only
100
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
101
+ ```
102
+
103
+ If you already ran `pip install -e .`, installing the appropriate PyTorch build
104
+ afterward is fine and will replace the default wheel if needed.
105
+
106
+ ### Conda environment (recommended for HPC)
107
+
108
+ An `environment.yml` is provided that includes `mmseqs2` from `bioconda`. If you
109
+ want GPU support, edit the `pytorch-cuda` version to match your cluster before running:
110
+
111
+ ```bash
112
+ conda env create -f environment.yml
113
+ conda activate vhamster
114
+ pip install -e .
115
+ ```
116
+
117
+ ## Model installation
118
+
119
+ Model installation is a separate step after installing `vhamster` itself.
120
+
121
+ This downloads the pretrained model weights from [HuggingFace](https://huggingface.co/DOEJGI/vhamster-models) and the geNomad marker database from [Zenodo](https://zenodo.org/records/14886553):
122
+
123
+ ```bash
124
+ vhamster-install-models
125
+ ```
126
+
127
+ By default, everything is installed into an environment-scoped location in the active Python
128
+ environment: `site-packages/vhamster_models_v1.3.0`.
129
+
130
+ If that default location is not writable, install to your own directory instead:
131
+
132
+ ```bash
133
+ vhamster-install-models -o /path/to/my_vhamster_models
134
+ ```
135
+
136
+ Reinstall if needed:
137
+
138
+ ```bash
139
+ vhamster-install-models -f
140
+ ```
141
+
142
+ The installer places files at:
143
+ - `<install_root>/fold_0/` … `<install_root>/fold_4/` — ensemble model weights
144
+ - `<install_root>/proportional_vector_scaling_scalar_nll_notclassbalanced_posthoc_fungi_nolength.json` — calibration parameters
145
+ - `<install_root>/genomad_db/` — geNomad marker database
146
+
147
+ Once installed, vhamster will find the geNomad database automatically. If you have an existing geNomad database elsewhere, you can point to it with `--genomad-db`:
148
+
149
+ ```bash
150
+ vhamster \
151
+ --fasta input.fasta \
152
+ --output results/ \
153
+ --genomad-db /path/to/genomad_db
154
+ ```
155
+
156
+ If your models are stored in a non-default location, pass the path with `--ensemble-dir`:
157
+
158
+ ```bash
159
+ vhamster \
160
+ --fasta input.fasta \
161
+ --output results/ \
162
+ --ensemble-dir /path/to/vhamster_models_v1.3.0
163
+ ```
164
+
165
+ Runtime logs are written to `<output>/<prefix>.log` and also shown in the
166
+ terminal.
167
+
168
+ ## Quick-start example
169
+
170
+ A test genome (accession NC_110914.1) is included in `test_data/`. After
171
+ installing `vhamster` and running `vhamster-install-models`, run from the
172
+ repository root:
173
+
174
+ ```bash
175
+ vhamster \
176
+ --fasta test_data/escherichia_phage.fasta \
177
+ --output results/test_run \
178
+ --prefix escherichia_phage
179
+ ```
180
+
181
+ If your model files are stored in a non-default location:
182
+
183
+ ```bash
184
+ vhamster \
185
+ --fasta test_data/escherichia_phage.fasta \
186
+ --output results/test_run \
187
+ --prefix escherichia_phage \
188
+ --ensemble-dir /path/to/vhamster_models_v1.3.0
189
+ ```
190
+
191
+ This writes two files:
192
+
193
+ | File | Contents |
194
+ |------|----------|
195
+ | `results/test_run/escherichia_phage.chunks.tsv` | Per-chunk predictions |
196
+ | `results/test_run/escherichia_phage.genomes.tsv` | Genome-level consensus |
197
+
198
+ The `predicted_host` column in the genome file should read **Prokaryote** for
199
+ this *Escherichia* phage.
200
+
201
+ ---
202
+
203
+ ## Run
204
+
205
+ Minimal example (models at their default installed location):
206
+
207
+ ```bash
208
+ vhamster \
209
+ --fasta /path/to/input.fasta \
210
+ --output /path/to/results_dir
211
+ ```
212
+
213
+ Add a custom output prefix:
214
+
215
+ ```bash
216
+ vhamster \
217
+ --fasta /path/to/input.fasta \
218
+ --output /path/to/results_dir \
219
+ --prefix sampleA
220
+ ```
221
+
222
+ Use a custom ensemble directory:
223
+
224
+ ```bash
225
+ vhamster \
226
+ --fasta /path/to/input.fasta \
227
+ --output /path/to/results_dir \
228
+ --ensemble-dir /path/to/vhamster_models_v1.3.0
229
+ ```
230
+
231
+ Run using a single fold (for example, only `fold_3`):
232
+
233
+ ```bash
234
+ vhamster \
235
+ --fasta /path/to/input.fasta \
236
+ --output /path/to/results_dir \
237
+ --fold-index 3
238
+ ```
239
+
240
+ Use a non-default calibration parameters file:
241
+
242
+ ```bash
243
+ vhamster \
244
+ --fasta /path/to/input.fasta \
245
+ --output /path/to/results_dir \
246
+ --calibration-params /path/to/proportional_vector_scaling_scalar_nll_notclassbalanced_posthoc_fungi_nolength.json
247
+ ```
248
+
249
+ ## Two-stage pipeline (HPC)
250
+
251
+ For large datasets, the CPU-intensive feature extraction (PyRodigal + MMseqs2) and the GPU-intensive GLM inference can be run as two separate jobs. This lets you pipeline batches: one batch's features are computed on a CPU node while the previous batch's GLM inference runs on a GPU node.
252
+
253
+ **Stage 1 — feature extraction (CPU node, no GPU needed):**
254
+
255
+ ```bash
256
+ vhamster-features \
257
+ --fasta batch_001.fasta \
258
+ --output features/batch_001 \
259
+ --prefix batch_001
260
+ ```
261
+
262
+ This writes:
263
+ - `features/batch_001/batch_001.arch_features.tsv` — per-chunk architectural features
264
+ - `features/batch_001/batch_001.genomad_hits.json` — geNomad marker hits
265
+ - `features/batch_001/batch_001.gene_predictions.tsv` — per-gene annotations
266
+
267
+ **Stage 2 — GLM inference (GPU node):**
268
+
269
+ ```bash
270
+ vhamster \
271
+ --fasta batch_001.fasta \
272
+ --output results/batch_001 \
273
+ --prefix batch_001 \
274
+ --precomputed-features features/batch_001
275
+ ```
276
+
277
+ The `--chunk-size` and `--overlap` values must match between the two stages (defaults are the same, so no flags needed if you use defaults for both).
278
+
279
+
280
+ ## Outputs
281
+
282
+ For prefix `sampleA`, the unconditional output files are:
283
+ - `/path/to/results_dir/sampleA.chunks.tsv` — per-chunk predictions
284
+ - `/path/to/results_dir/sampleA.genomes.tsv` — genome-level consensus (mean-pooled over chunks)
285
+ - `/path/to/results_dir/sampleA.folds.tsv` — per-fold predictions and GLM gate weights for all 5 ensemble members
286
+
287
+ If the `--verbose` flag is passed, an additional file is generated:
288
+ - `/path/to/results_dir/sampleA.verbose.tsv` — detailed per-fold uncalibrated stream probabilities, uncalibrated ensemble probabilities, and raw feature arrays.
289
+
290
+ ### Chunk Naming Convention
291
+ Sequences longer than the specified chunk size (default 10 kbp) are split into smaller fragments. The `accession` column for these fragments will include a `_chunk<start>_<end>` suffix (e.g., `NC_007026.1_chunk0_10000`). You can use this suffix or the `sampleA.genomes.tsv` file to join chunk-level predictions back to your original input sequences.
292
+
293
+ ### File Schemas
294
+
295
+ **Chunk file columns include:**
296
+ - `accession`, `predicted_host`, `confidence`
297
+ - calibrated class probability columns
298
+ - `prokaryote_score`, `eukaryote_score`
299
+
300
+ **Genome file columns include:**
301
+ - `genome`, `predicted_host`, `confidence`
302
+ - calibrated class probability columns
303
+ - `prokaryote_score`, `eukaryote_score`
304
+
305
+ **Folds file columns include:**
306
+ - `accession`, `fold`, `predicted_host`, `confidence`, `glm_gate_weight`
307
+ - calibrated class probability columns
308
+
309
+ **Verbose file columns include:**
310
+ - `accession`, `fold`, `n_genes`, `predicted_host`, `confidence`, `glm_gate_weight`
311
+ - calibrated class probability columns
312
+ - `xgb_<class>` (pure, uncalibrated XGBoost probabilities)
313
+ - `glm_<class>` (pure, uncalibrated GLM probabilities)
314
+ - `uncalibrated_ensemble_<class>` (the exact mathematical output of the dynamic gate before temperature scaling)
315
+ - All raw architectural and marker features
316
+
317
+ ## Performance & Batching Tips
318
+
319
+ **1. Batch your inputs into a single FASTA file**
320
+ The geNomad marker search relies on MMseqs2, which has a high fixed startup cost (often 1–2 minutes) to load the marker database into memory. This cost is incurred every time `vhamster` runs.
321
+
322
+ To avoid paying this startup penalty multiple times, **do not run vhamster in a bash loop over individual files**. Instead, concatenate your sequences into a single multi-FASTA file and run `vhamster` once:
323
+
324
+ ```
325
+ # Inefficient (Loads DB 3 times)
326
+ vhamster --fasta seq1.fasta --output out/ --prefix seq1
327
+ vhamster --fasta seq2.fasta --output out/ --prefix seq2
328
+ vhamster --fasta seq3.fasta --output out/ --prefix seq3
329
+
330
+ # Highly Efficient (Loads DB once)
331
+ cat seq1.fasta seq2.fasta seq3.fasta > all_seqs.fasta
332
+ vhamster --fasta all_seqs.fasta --output out/ --prefix all_seqs
333
+ ```
334
+ ## Citation
335
+ Preprint coming soon!
336
+
337
+ ## Citation
338
+
339
+ **Preprint coming soon!**
340
+
341
+ If you use VHAMSTeR in your research, please also cite the foundational tools that power our feature extraction pipeline:
342
+
343
+ * **geNomad (Viral marker database and specificity concepts):**
344
+ Camargo, A. P., Roux, S., Schulz, F., Babinski, M., Xu, Y., Hu, B., Chain, P. S. G., Nayfach, S., & Kyrpides, N. C. (2023). Identification of mobile genetic elements with geNomad. *Nature Biotechnology*, 42, 277-280. [https://doi.org/10.1038/s41587-023-01953-y](https://doi.org/10.1038/s41587-023-01953-y)
345
+
346
+ * **Pyrodigal-gv / Prodigal (Viral gene prediction):**
347
+ Larralde, M. (2022). Pyrodigal: Python bindings and interface to Prodigal. *Journal of Open Source Software*, 7(72), 4296. [https://doi.org/10.21105/joss.04296](https://doi.org/10.21105/joss.04296)
348
+ Hyatt, D., Chen, G. L., LoCascio, P. F., Land, M. L., Larimer, F. W., & Hauser, L. J. (2010). Prodigal: prokaryotic gene recognition and translation initiation site identification. *BMC Bioinformatics*, 11(1), 1-11. [https://doi.org/10.1186/1471-2105-11-119](https://doi.org/10.1186/1471-2105-11-119)
349
+
350
+ * **MMseqs2 (Fast protein sequence search):**
351
+ Steinegger, M., & Söding, J. (2017). MMseqs2 enables sensitive protein sequence searching for the analysis of massive data sets. *Nature Biotechnology*, 35(11), 1026-1028. [https://doi.org/10.1038/nbt.3988](https://doi.org/10.1038/nbt.3988)
352
+
353
+ ## License Agreement
354
+ Lawrence Berkeley National Laboratory
355
+ NON-COMMERCIAL USE ONLY LICENSE
356
+
357
+ V-HAMSTeR Copyright (c) 2026, The Regents of the University of California, through Lawrence Berkeley National Laboratory (“Berkeley Lab”) subject to receipt of any required approvals from the U.S. Dept. of Energy. All rights reserved.
358
+
359
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
360
+
361
+ (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
362
+
363
+ (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
364
+
365
+ (3) Neither the name of the University of California, Berkeley Lab, U.S. Dept. of Energy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Berkeley Lab.
366
+
367
+ (4) Use of the software, in source or binary form is for NON-COMMERCIAL USE purposes ONLY. The software is not available for commercial use. If you have any questions regarding this software, please contact Berkeley Lab at IPO@lbl.gov.
368
+
369
+ (5) User agrees to indemnify, defend, and hold harmless Berkeley Lab, the U.S. Government, the software developers, the software sponsors, and their agents, officers, and employees, against any and all claims, suits, losses, damage, costs, fees, and expenses arising out of or in connection with this Agreement. User agrees to pay all costs incurred by Berkeley Lab in enforcing this provision, including reasonable attorney fees.
370
+
371
+ (6) In the event User creates any bug fixes, patches, upgrades, updates, modifications, derivative works or enhancements to the source code or binary code of the software ("Enhancements") User hereby grants Berkeley Lab and the U.S. Government a paid-up, non-exclusive, irrevocable, worldwide license in the Enhancements to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.
372
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
373
+
374
+ ## Copyright Notice
375
+ V-HAMSTeR Copyright (c) 2026, The Regents of the University of California, through Lawrence Berkeley National Laboratory (“Berkeley Lab”) subject to receipt of any required approvals from the U.S. Dept. of Energy. All rights reserved.
376
+ If you have questions about your rights to use or distribute this software, please contact Berkeley Lab's Intellectual Property Office at IPO@lbl.gov.
377
+ NOTICE: This Software was developed under Contract No. DE-AC02-05CH11231 with the Department of Energy (“DOE”). During the period of commercialization or such other time period specified by DOE, the U.S. Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, and perform publicly and display publicly, by or on behalf of the U.S. Government. Subsequent to that period, the U.S. Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable, worldwide license in the Software to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so. The specific term of the license can be identified by inquiry made to Lawrence Berkeley National Laboratory or DOE. NEITHER THE UNITED STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY DATA, APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
378
+
379
+