fastmixture2 2.0.9__tar.gz → 2.2.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.
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/MANIFEST.in +1 -2
- fastmixture2-2.2.0/PKG-INFO +215 -0
- fastmixture2-2.2.0/README.md +184 -0
- fastmixture2-2.2.0/fastmixture2/__init__.py +4 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2/defaults.py +36 -5
- fastmixture2-2.2.0/fastmixture2/em.pyx +954 -0
- fastmixture2-2.2.0/fastmixture2/fastmixture2.py +1693 -0
- fastmixture2-2.2.0/fastmixture2/functions.py +1520 -0
- fastmixture2-2.2.0/fastmixture2/gpu.py +6804 -0
- fastmixture2-2.2.0/fastmixture2/kernels.py +773 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2/main.py +22 -7
- fastmixture2-2.2.0/fastmixture2/math.pxd +370 -0
- fastmixture2-2.2.0/fastmixture2/packed.pxd +761 -0
- fastmixture2-2.2.0/fastmixture2/plink.py +617 -0
- fastmixture2-2.2.0/fastmixture2/shared.pyx +3391 -0
- fastmixture2-2.2.0/fastmixture2/sqp.pyx +3561 -0
- fastmixture2-2.2.0/fastmixture2/svd.pyx +776 -0
- fastmixture2-2.2.0/fastmixture2/utils.py +2416 -0
- fastmixture2-2.2.0/fastmixture2.egg-info/PKG-INFO +215 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2.egg-info/SOURCES.txt +6 -18
- fastmixture2-2.2.0/setup.py +106 -0
- fastmixture2-2.2.0/tests/check_portable.py +130 -0
- fastmixture2-2.2.0/tests/helpers.py +538 -0
- fastmixture2-2.2.0/tests/test_adversarial_io.py +1901 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_bootstrap.py +590 -398
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_cli.py +577 -166
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_convergence.py +347 -144
- fastmixture2-2.2.0/tests/test_cpu_scaling.py +3486 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_cross_validation.py +164 -99
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_genotypes.py +220 -167
- fastmixture2-2.2.0/tests/test_gpu_init.py +683 -0
- fastmixture2-2.2.0/tests/test_gpu_kernels.py +2139 -0
- fastmixture2-2.2.0/tests/test_gpu_modes.py +913 -0
- fastmixture2-2.2.0/tests/test_gpu_planning.py +3394 -0
- fastmixture2-2.2.0/tests/test_gpu_streaming.py +1270 -0
- fastmixture2-2.2.0/tests/test_initialization.py +695 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_likelihoods.py +510 -778
- fastmixture2-2.2.0/tests/test_numerical_equivalence.py +759 -0
- fastmixture2-2.2.0/tests/test_optimizers.py +873 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_plink_files.py +228 -243
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_restarts.py +177 -145
- fastmixture2-2.2.0/tests/test_sample_subset.py +1309 -0
- fastmixture2-2.2.0/tests/test_sqp_solver.py +490 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/test_threads.py +96 -1
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/validate_distribution.py +2 -2
- fastmixture2-2.0.9/PKG-INFO +0 -339
- fastmixture2-2.0.9/README.md +0 -308
- fastmixture2-2.0.9/fastmixture2/__init__.py +0 -1
- fastmixture2-2.0.9/fastmixture2/em.pyx +0 -1887
- fastmixture2-2.0.9/fastmixture2/fastmixture2.py +0 -1067
- fastmixture2-2.0.9/fastmixture2/functions.py +0 -1113
- fastmixture2-2.0.9/fastmixture2/gpu.py +0 -5553
- fastmixture2-2.0.9/fastmixture2/kernels.py +0 -431
- fastmixture2-2.0.9/fastmixture2/packed.pxd +0 -277
- fastmixture2-2.0.9/fastmixture2/plink.py +0 -142
- fastmixture2-2.0.9/fastmixture2/shared.pyx +0 -1983
- fastmixture2-2.0.9/fastmixture2/sqp.pyx +0 -1152
- fastmixture2-2.0.9/fastmixture2/svd.pyx +0 -311
- fastmixture2-2.0.9/fastmixture2/threads.pxd +0 -42
- fastmixture2-2.0.9/fastmixture2/utils.py +0 -1403
- fastmixture2-2.0.9/fastmixture2.egg-info/PKG-INFO +0 -339
- fastmixture2-2.0.9/setup.py +0 -55
- fastmixture2-2.0.9/tests/check_portable.py +0 -55
- fastmixture2-2.0.9/tests/helpers.py +0 -256
- fastmixture2-2.0.9/tests/test_adversarial_io.py +0 -863
- fastmixture2-2.0.9/tests/test_cpu_scaling.py +0 -1014
- fastmixture2-2.0.9/tests/test_cpu_subset.py +0 -525
- fastmixture2-2.0.9/tests/test_distribution.py +0 -84
- fastmixture2-2.0.9/tests/test_frequency_cache.py +0 -297
- fastmixture2-2.0.9/tests/test_gpu_called.py +0 -1305
- fastmixture2-2.0.9/tests/test_gpu_em.py +0 -256
- fastmixture2-2.0.9/tests/test_gpu_gl_precision.py +0 -861
- fastmixture2-2.0.9/tests/test_gpu_large.py +0 -1025
- fastmixture2-2.0.9/tests/test_gpu_modes.py +0 -390
- fastmixture2-2.0.9/tests/test_gpu_precision.py +0 -813
- fastmixture2-2.0.9/tests/test_gpu_safety.py +0 -919
- fastmixture2-2.0.9/tests/test_gpu_stat_reuse.py +0 -193
- fastmixture2-2.0.9/tests/test_gpu_streamed.py +0 -648
- fastmixture2-2.0.9/tests/test_gpu_subset.py +0 -696
- fastmixture2-2.0.9/tests/test_gpu_supervision.py +0 -156
- fastmixture2-2.0.9/tests/test_gpu_svd_cache.py +0 -258
- fastmixture2-2.0.9/tests/test_initialization.py +0 -409
- fastmixture2-2.0.9/tests/test_numerical_equivalence.py +0 -711
- fastmixture2-2.0.9/tests/test_optimizers.py +0 -427
- fastmixture2-2.0.9/tests/test_q_constraints.py +0 -388
- fastmixture2-2.0.9/tests/test_sqp_scoring.py +0 -310
- fastmixture2-2.0.9/tests/test_sqp_solver.py +0 -435
- fastmixture2-2.0.9/tests/test_subset_modes.py +0 -410
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/LICENSE +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2.egg-info/dependency_links.txt +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2.egg-info/entry_points.txt +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2.egg-info/requires.txt +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/fastmixture2.egg-info/top_level.txt +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/pyproject.toml +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/setup.cfg +0 -0
- {fastmixture2-2.0.9 → fastmixture2-2.2.0}/tests/run_tests.py +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastmixture2
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: Biobank-scale ancestry estimation in unrelated individuals
|
|
5
|
+
Author-email: "J. Meisner" <meisnerucph@gmail.com>, "L. Thunegard" <lisathunegard@icloud.com>
|
|
6
|
+
License-Expression: GPL-3.0-only
|
|
7
|
+
Project-URL: Homepage, https://github.com/MeisnerLab/fastmixture2
|
|
8
|
+
Project-URL: Documentation, https://github.com/MeisnerLab/fastmixture2#readme
|
|
9
|
+
Project-URL: Issues, https://github.com/MeisnerLab/fastmixture2/issues
|
|
10
|
+
Project-URL: Source, https://github.com/MeisnerLab/fastmixture2
|
|
11
|
+
Keywords: admixture,ancestry,bioinformatics,genomics,population-genetics
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: POSIX
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=2.0
|
|
26
|
+
Requires-Dist: scipy>=1.14
|
|
27
|
+
Requires-Dist: threadpoolctl>=3.5
|
|
28
|
+
Provides-Extra: gpu-cuda13
|
|
29
|
+
Requires-Dist: cupy-cuda13x[ctk]>=14.0; extra == "gpu-cuda13"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# fastmixture2 (v2.2.0)
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo" width="300">
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml"><img src="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg" alt="Tests"></a>
|
|
40
|
+
<a href="https://pypi.org/project/fastmixture2/"><img src="https://img.shields.io/pypi/v/fastmixture2.svg" alt="PyPI"></a>
|
|
41
|
+
<a href="https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
45
|
+
frequencies (`P`) by maximum likelihood from PLINK genotypes or ANGSD Beagle
|
|
46
|
+
genotype likelihoods. It supports unsupervised, supervised and projection modes
|
|
47
|
+
on CPU and NVIDIA CUDA.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
Use Python 3.11+. PyPI wheels support Linux (glibc) and macOS 15+ on x86-64
|
|
52
|
+
and ARM64, with AVX-512, AVX2, and NEON where available. For CUDA, use
|
|
53
|
+
`python -m pip install 'fastmixture2[gpu-cuda13]'` with a compatible NVIDIA
|
|
54
|
+
driver and pass `--gpu` when fitting.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
python -m pip install fastmixture2
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Build from source for native CPU tuning. Install a C compiler and OpenMP
|
|
61
|
+
(`brew install libomp` on macOS).
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/MeisnerLab/fastmixture2.git
|
|
65
|
+
cd fastmixture2
|
|
66
|
+
python -m pip install .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Use `python -m pip install '.[gpu-cuda13]'` for a CUDA source build.
|
|
70
|
+
For Conda, run `conda env create -f environment-cpu.yml` or use
|
|
71
|
+
`environment-gpu.yml` and activate `fastmixture2-cpu` or `fastmixture2-gpu`.
|
|
72
|
+
With [uv](https://docs.astral.sh/uv/), use `uv pip install` with the same arguments.
|
|
73
|
+
|
|
74
|
+
## Quick start
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
78
|
+
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
79
|
+
fastmixture2 --bfile chr{1..22} --K 4 5 6 --seed 42 43 --restarts 2 --threads 8 --out cohort
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`--bfile` accepts one SNP-major PLINK prefix or ordered chromosome prefixes.
|
|
83
|
+
The FAM files must have the same FID/IID pairs in the same order. `--beagle`
|
|
84
|
+
accepts gzipped ANGSD Beagle likelihoods.
|
|
85
|
+
|
|
86
|
+
Lists of K values and seeds run every combination sequentially. Fits share
|
|
87
|
+
the loaded data and reuse common initialization work where possible. Each
|
|
88
|
+
fit has its own outputs and log. For each K, keep the converged fit with the
|
|
89
|
+
highest log-likelihood and align components before comparing Q or P.
|
|
90
|
+
|
|
91
|
+
Both devices support K from 1 to 128. Remove monomorphic and uninformative
|
|
92
|
+
variants before fitting. Missing calls and uniform likelihood triplets
|
|
93
|
+
contribute no information. Unsupervised fits use SVD/ALS by default.
|
|
94
|
+
`--random-init` uses random P/Q starts for the fit and any `--exact-cv` folds.
|
|
95
|
+
|
|
96
|
+
Defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
97
|
+
Match `--threads` to your CPU allocation; on streamed `--gpu` runs, extra
|
|
98
|
+
threads also stage host tiles asynchronously. Iteration limits and likelihood
|
|
99
|
+
tolerances apply per fit stage. The tolerance is mean likelihood gain per
|
|
100
|
+
informative entry. See `fastmixture2 --help` for all options.
|
|
101
|
+
|
|
102
|
+
### Scratch and Beagle caches
|
|
103
|
+
|
|
104
|
+
Use `TMPDIR` or `SLURM_TMPDIR` for disk-backed scratch with space for input,
|
|
105
|
+
initialization and outputs. For shared filesystems, copy the panel once to
|
|
106
|
+
node-local disk and use its local prefixes. Recognized bucket mounts stage
|
|
107
|
+
mapped input once per command and publish each fit's outputs after it finishes.
|
|
108
|
+
Bucket output requires file replacement support.
|
|
109
|
+
|
|
110
|
+
Use `--gl-cache FILE` to reuse parsed Beagle data across commands or
|
|
111
|
+
`--save-gl-cache` to use `OUTPUT.gl.npy`. The cache uses about
|
|
112
|
+
`12 × variants × samples` bytes and stores sample and variant metadata
|
|
113
|
+
alongside it so `--write-info`, `--supervised` and `--projection` avoid
|
|
114
|
+
rereading the gzipped Beagle input. Invalid caches are rebuilt.
|
|
115
|
+
|
|
116
|
+
### Supervised estimation
|
|
117
|
+
|
|
118
|
+
Estimate P jointly with Q for unassigned samples, keeping reference Q rows fixed.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
122
|
+
--supervised populations.txt --out cohort.supervised
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Use labels `1` through `K` for references and `0` for unassigned samples.
|
|
126
|
+
Provide at least one reference. Supply labels in sample order or use
|
|
127
|
+
`FID IID POP` columns to validate the order. Use each Beagle sample label
|
|
128
|
+
as both FID and IID.
|
|
129
|
+
|
|
130
|
+
### Projection
|
|
131
|
+
|
|
132
|
+
Estimate Q for new samples with fixed reference P. Use `--write-info` when
|
|
133
|
+
fitting the reference panel so projection can check marker IDs and alleles.
|
|
134
|
+
Projection accepts multiple seeds with the K of the reference P.
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
fastmixture2 --bfile reference --K 5 --threads 8 --write-info --out reference
|
|
138
|
+
fastmixture2 --bfile new_samples --K 5 --threads 8 \
|
|
139
|
+
--projection reference.K5.s42.P --out new_samples.projected
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Use the same markers in order. Annotated P files include `SNP A1 A2` and
|
|
143
|
+
support allele swaps and strand complements. Remove ambiguous A/T and C/G
|
|
144
|
+
variants or use `--allow-ambiguous` when both panels share a strand convention.
|
|
145
|
+
Numeric P files assume matching alleles.
|
|
146
|
+
|
|
147
|
+
### Cross-validation
|
|
148
|
+
|
|
149
|
+
Compare K values using the same seed and number of folds. Lower scores are better.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
fastmixture2 --bfile cohort --K 4 5 6 --threads 8 --seed 42 --cv 5 --out cohort.cv
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
CV for unsupervised fits starts from the full-data estimates by default.
|
|
156
|
+
Use `--exact-cv` for independent training-only starts, `--cv-tole` for fold
|
|
157
|
+
tolerance and `--K 1` for a pooled-frequency baseline. PLINK scores use half
|
|
158
|
+
binomial deviance and Beagle scores use mean negative log marginal likelihood.
|
|
159
|
+
Check fold convergence in the log. Mapped CPU CV can use an extra BED-sized
|
|
160
|
+
scratch file.
|
|
161
|
+
|
|
162
|
+
### Bootstrap uncertainty
|
|
163
|
+
|
|
164
|
+
Estimate Q standard errors by resampling blocks of neighboring SNPs.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
168
|
+
--bootstrap 200 --bootstrap-block 1500 --out cohort
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`--bootstrap` defaults to 200 replicates with up to three iterations each.
|
|
172
|
+
Use `--bootstrap-iter` and `--bootstrap-tole` to control refits. PLINK blocks
|
|
173
|
+
stay within chromosomes and average 10 cM with a usable BIM map.
|
|
174
|
+
`--bootstrap-block` sets the length in SNPs and is required for PLINK without
|
|
175
|
+
a usable map and for Beagle. Projection conditions on P. Fixed reference
|
|
176
|
+
rows have zero standard error. Run bootstrap and CV separately.
|
|
177
|
+
|
|
178
|
+
### Restarts
|
|
179
|
+
|
|
180
|
+
`--restarts N` (default 0) applies independently to every unsupervised K and
|
|
181
|
+
seed. Each round tries a Q permutation and, at K ≥ 3, a merge/split proposal.
|
|
182
|
+
K = 1 skips restarts. Each fit keeps its best full-data likelihood and records
|
|
183
|
+
the choice in its log.
|
|
184
|
+
|
|
185
|
+
### Checkpointing
|
|
186
|
+
|
|
187
|
+
Save accepted estimates and resume an interrupted fit.
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --checkpoint run.ckpt --out cohort
|
|
191
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Checkpoint and resume require one K and seed. Resume with the same input files,
|
|
195
|
+
mode, K and seed. Use `--restarts` to add rounds after the resumed fit.
|
|
196
|
+
|
|
197
|
+
## Output
|
|
198
|
+
|
|
199
|
+
The table shows the files for `--out cohort --K 5 --seed 42`.
|
|
200
|
+
|
|
201
|
+
| File | Contents |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| `cohort.K5.s42.Q` | Ancestry proportions, one row per sample |
|
|
204
|
+
| `cohort.K5.s42.P` | Allele frequencies, one row per variant |
|
|
205
|
+
| `cohort.K5.s42.Q_se` | Q standard errors when bootstrap is requested |
|
|
206
|
+
| `cohort.K5.s42.log` | Settings, timing, convergence, likelihood and optional analysis summaries |
|
|
207
|
+
|
|
208
|
+
Rows follow input order. `--write-info` adds headers and IDs. P gives the
|
|
209
|
+
frequency of BIM A1 for PLINK and allele2 for Beagle. Projection and `--no-freqs` omit P.
|
|
210
|
+
Use separate `--out` prefixes for concurrent fits with the same K and seed.
|
|
211
|
+
|
|
212
|
+
## Authors and license
|
|
213
|
+
|
|
214
|
+
Lisa Thunegard and Jonas Meisner. Developed at **MeisnerLab** and distributed
|
|
215
|
+
under the [GNU General Public License v3.0](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE).
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# fastmixture2 (v2.2.0)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo" width="300">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml"><img src="https://github.com/MeisnerLab/fastmixture2/actions/workflows/ci.yml/badge.svg" alt="Tests"></a>
|
|
9
|
+
<a href="https://pypi.org/project/fastmixture2/"><img src="https://img.shields.io/pypi/v/fastmixture2.svg" alt="PyPI"></a>
|
|
10
|
+
<a href="https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
14
|
+
frequencies (`P`) by maximum likelihood from PLINK genotypes or ANGSD Beagle
|
|
15
|
+
genotype likelihoods. It supports unsupervised, supervised and projection modes
|
|
16
|
+
on CPU and NVIDIA CUDA.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Use Python 3.11+. PyPI wheels support Linux (glibc) and macOS 15+ on x86-64
|
|
21
|
+
and ARM64, with AVX-512, AVX2, and NEON where available. For CUDA, use
|
|
22
|
+
`python -m pip install 'fastmixture2[gpu-cuda13]'` with a compatible NVIDIA
|
|
23
|
+
driver and pass `--gpu` when fitting.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m pip install fastmixture2
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Build from source for native CPU tuning. Install a C compiler and OpenMP
|
|
30
|
+
(`brew install libomp` on macOS).
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/MeisnerLab/fastmixture2.git
|
|
34
|
+
cd fastmixture2
|
|
35
|
+
python -m pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use `python -m pip install '.[gpu-cuda13]'` for a CUDA source build.
|
|
39
|
+
For Conda, run `conda env create -f environment-cpu.yml` or use
|
|
40
|
+
`environment-gpu.yml` and activate `fastmixture2-cpu` or `fastmixture2-gpu`.
|
|
41
|
+
With [uv](https://docs.astral.sh/uv/), use `uv pip install` with the same arguments.
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --out cohort
|
|
47
|
+
fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
48
|
+
fastmixture2 --bfile chr{1..22} --K 4 5 6 --seed 42 43 --restarts 2 --threads 8 --out cohort
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`--bfile` accepts one SNP-major PLINK prefix or ordered chromosome prefixes.
|
|
52
|
+
The FAM files must have the same FID/IID pairs in the same order. `--beagle`
|
|
53
|
+
accepts gzipped ANGSD Beagle likelihoods.
|
|
54
|
+
|
|
55
|
+
Lists of K values and seeds run every combination sequentially. Fits share
|
|
56
|
+
the loaded data and reuse common initialization work where possible. Each
|
|
57
|
+
fit has its own outputs and log. For each K, keep the converged fit with the
|
|
58
|
+
highest log-likelihood and align components before comparing Q or P.
|
|
59
|
+
|
|
60
|
+
Both devices support K from 1 to 128. Remove monomorphic and uninformative
|
|
61
|
+
variants before fitting. Missing calls and uniform likelihood triplets
|
|
62
|
+
contribute no information. Unsupervised fits use SVD/ALS by default.
|
|
63
|
+
`--random-init` uses random P/Q starts for the fit and any `--exact-cv` folds.
|
|
64
|
+
|
|
65
|
+
Defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
66
|
+
Match `--threads` to your CPU allocation; on streamed `--gpu` runs, extra
|
|
67
|
+
threads also stage host tiles asynchronously. Iteration limits and likelihood
|
|
68
|
+
tolerances apply per fit stage. The tolerance is mean likelihood gain per
|
|
69
|
+
informative entry. See `fastmixture2 --help` for all options.
|
|
70
|
+
|
|
71
|
+
### Scratch and Beagle caches
|
|
72
|
+
|
|
73
|
+
Use `TMPDIR` or `SLURM_TMPDIR` for disk-backed scratch with space for input,
|
|
74
|
+
initialization and outputs. For shared filesystems, copy the panel once to
|
|
75
|
+
node-local disk and use its local prefixes. Recognized bucket mounts stage
|
|
76
|
+
mapped input once per command and publish each fit's outputs after it finishes.
|
|
77
|
+
Bucket output requires file replacement support.
|
|
78
|
+
|
|
79
|
+
Use `--gl-cache FILE` to reuse parsed Beagle data across commands or
|
|
80
|
+
`--save-gl-cache` to use `OUTPUT.gl.npy`. The cache uses about
|
|
81
|
+
`12 × variants × samples` bytes and stores sample and variant metadata
|
|
82
|
+
alongside it so `--write-info`, `--supervised` and `--projection` avoid
|
|
83
|
+
rereading the gzipped Beagle input. Invalid caches are rebuilt.
|
|
84
|
+
|
|
85
|
+
### Supervised estimation
|
|
86
|
+
|
|
87
|
+
Estimate P jointly with Q for unassigned samples, keeping reference Q rows fixed.
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
91
|
+
--supervised populations.txt --out cohort.supervised
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Use labels `1` through `K` for references and `0` for unassigned samples.
|
|
95
|
+
Provide at least one reference. Supply labels in sample order or use
|
|
96
|
+
`FID IID POP` columns to validate the order. Use each Beagle sample label
|
|
97
|
+
as both FID and IID.
|
|
98
|
+
|
|
99
|
+
### Projection
|
|
100
|
+
|
|
101
|
+
Estimate Q for new samples with fixed reference P. Use `--write-info` when
|
|
102
|
+
fitting the reference panel so projection can check marker IDs and alleles.
|
|
103
|
+
Projection accepts multiple seeds with the K of the reference P.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
fastmixture2 --bfile reference --K 5 --threads 8 --write-info --out reference
|
|
107
|
+
fastmixture2 --bfile new_samples --K 5 --threads 8 \
|
|
108
|
+
--projection reference.K5.s42.P --out new_samples.projected
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Use the same markers in order. Annotated P files include `SNP A1 A2` and
|
|
112
|
+
support allele swaps and strand complements. Remove ambiguous A/T and C/G
|
|
113
|
+
variants or use `--allow-ambiguous` when both panels share a strand convention.
|
|
114
|
+
Numeric P files assume matching alleles.
|
|
115
|
+
|
|
116
|
+
### Cross-validation
|
|
117
|
+
|
|
118
|
+
Compare K values using the same seed and number of folds. Lower scores are better.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
fastmixture2 --bfile cohort --K 4 5 6 --threads 8 --seed 42 --cv 5 --out cohort.cv
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
CV for unsupervised fits starts from the full-data estimates by default.
|
|
125
|
+
Use `--exact-cv` for independent training-only starts, `--cv-tole` for fold
|
|
126
|
+
tolerance and `--K 1` for a pooled-frequency baseline. PLINK scores use half
|
|
127
|
+
binomial deviance and Beagle scores use mean negative log marginal likelihood.
|
|
128
|
+
Check fold convergence in the log. Mapped CPU CV can use an extra BED-sized
|
|
129
|
+
scratch file.
|
|
130
|
+
|
|
131
|
+
### Bootstrap uncertainty
|
|
132
|
+
|
|
133
|
+
Estimate Q standard errors by resampling blocks of neighboring SNPs.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
137
|
+
--bootstrap 200 --bootstrap-block 1500 --out cohort
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`--bootstrap` defaults to 200 replicates with up to three iterations each.
|
|
141
|
+
Use `--bootstrap-iter` and `--bootstrap-tole` to control refits. PLINK blocks
|
|
142
|
+
stay within chromosomes and average 10 cM with a usable BIM map.
|
|
143
|
+
`--bootstrap-block` sets the length in SNPs and is required for PLINK without
|
|
144
|
+
a usable map and for Beagle. Projection conditions on P. Fixed reference
|
|
145
|
+
rows have zero standard error. Run bootstrap and CV separately.
|
|
146
|
+
|
|
147
|
+
### Restarts
|
|
148
|
+
|
|
149
|
+
`--restarts N` (default 0) applies independently to every unsupervised K and
|
|
150
|
+
seed. Each round tries a Q permutation and, at K ≥ 3, a merge/split proposal.
|
|
151
|
+
K = 1 skips restarts. Each fit keeps its best full-data likelihood and records
|
|
152
|
+
the choice in its log.
|
|
153
|
+
|
|
154
|
+
### Checkpointing
|
|
155
|
+
|
|
156
|
+
Save accepted estimates and resume an interrupted fit.
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --checkpoint run.ckpt --out cohort
|
|
160
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Checkpoint and resume require one K and seed. Resume with the same input files,
|
|
164
|
+
mode, K and seed. Use `--restarts` to add rounds after the resumed fit.
|
|
165
|
+
|
|
166
|
+
## Output
|
|
167
|
+
|
|
168
|
+
The table shows the files for `--out cohort --K 5 --seed 42`.
|
|
169
|
+
|
|
170
|
+
| File | Contents |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `cohort.K5.s42.Q` | Ancestry proportions, one row per sample |
|
|
173
|
+
| `cohort.K5.s42.P` | Allele frequencies, one row per variant |
|
|
174
|
+
| `cohort.K5.s42.Q_se` | Q standard errors when bootstrap is requested |
|
|
175
|
+
| `cohort.K5.s42.log` | Settings, timing, convergence, likelihood and optional analysis summaries |
|
|
176
|
+
|
|
177
|
+
Rows follow input order. `--write-info` adds headers and IDs. P gives the
|
|
178
|
+
frequency of BIM A1 for PLINK and allele2 for Beagle. Projection and `--no-freqs` omit P.
|
|
179
|
+
Use separate `--out` prefixes for concurrent fits with the same K and seed.
|
|
180
|
+
|
|
181
|
+
## Authors and license
|
|
182
|
+
|
|
183
|
+
Lisa Thunegard and Jonas Meisner. Developed at **MeisnerLab** and distributed
|
|
184
|
+
under the [GNU General Public License v3.0](https://github.com/MeisnerLab/fastmixture2/blob/main/LICENSE).
|
|
@@ -8,14 +8,18 @@ from numbers import Integral
|
|
|
8
8
|
K_MAX = 128
|
|
9
9
|
|
|
10
10
|
# Genotype storage and likelihood caching
|
|
11
|
-
MEMMAP_THRESHOLD_BYTES = 1 << 30 # Packed bytes
|
|
11
|
+
MEMMAP_THRESHOLD_BYTES = 1 << 30 # Packed or float32 bytes
|
|
12
|
+
INPUT_COPY_BYTES = 64 << 20
|
|
12
13
|
LIKELIHOOD_PARSE_BLOCK_BYTES = 64 << 20
|
|
14
|
+
PROJECTION_BLOCK_BYTES = 8 << 20
|
|
13
15
|
LIKELIHOOD_CACHE_HEADER_BYTES = 256
|
|
14
|
-
LIKELIHOOD_CACHE_VERSION =
|
|
16
|
+
LIKELIHOOD_CACHE_VERSION = 6
|
|
15
17
|
LIKELIHOOD_FREQUENCY_VERSION = 2
|
|
16
18
|
|
|
17
19
|
# Initialization
|
|
20
|
+
BATCH_CACHE_BYTES = 128 << 20
|
|
18
21
|
INITIALIZATION_MARKERS = 50_000
|
|
22
|
+
INITIALIZATION_SAMPLES = 50_000
|
|
19
23
|
SVD_POWER_ITERATIONS = 10
|
|
20
24
|
SVD_CHUNK_MARKERS = 4_096
|
|
21
25
|
SVD_WORKSPACE_BYTES = 512 << 20
|
|
@@ -38,8 +42,9 @@ LIKELIHOOD_CONVERGENCE_WINDOW = 10
|
|
|
38
42
|
# CUDA storage
|
|
39
43
|
GPU_TILE_BYTES = 512 << 20
|
|
40
44
|
GPU_SQP_STAT_BYTES = 512 << 20
|
|
45
|
+
GPU_SQP_FULL_STAT_BYTES = 36 << 30
|
|
41
46
|
GPU_SQP_WORKSPACE_BYTES = 128 << 20
|
|
42
|
-
GPU_BOOT_STAT_BYTES =
|
|
47
|
+
GPU_BOOT_STAT_BYTES = 36 << 30
|
|
43
48
|
GPU_MIN_TILE_BYTES = 128 << 20
|
|
44
49
|
GPU_PREFETCH_MIN_TILES = 3
|
|
45
50
|
GPU_MEMORY_RESERVE_BYTES = 512 << 20
|
|
@@ -51,8 +56,11 @@ EM_TILED_MIN_SAMPLES = 16_384
|
|
|
51
56
|
SQP_MARKER_CHUNK = 65_536
|
|
52
57
|
SQP_SAMPLE_CHUNK = 4_096
|
|
53
58
|
SQP_MARKER_WORKSPACE_BYTES = 512 << 20
|
|
59
|
+
SQP_PAIR_WORKSPACE_BYTES = 1 << 30
|
|
60
|
+
SQP_PAIR_MAX_BYTES = 8 << 30
|
|
54
61
|
SQP_SAMPLE_WORKSPACE_BYTES = 4 << 30
|
|
55
62
|
SQP_BLAS_WORKSPACE_BYTES = 64 << 20
|
|
63
|
+
CPU_READAHEAD_BYTES = 64 << 20
|
|
56
64
|
|
|
57
65
|
# ZAL acceleration
|
|
58
66
|
ZAL_DEPTH = 3
|
|
@@ -67,6 +75,7 @@ BOOT_REPLICATES = 200
|
|
|
67
75
|
BOOT_ITERATIONS = 3
|
|
68
76
|
BOOT_BLOCK_CM = 10.0
|
|
69
77
|
CHECKPOINT_INTERVAL = 25
|
|
78
|
+
CHECKPOINT_SECONDS = 600.0
|
|
70
79
|
OUTPUT_FORMAT = "%.10f"
|
|
71
80
|
|
|
72
81
|
|
|
@@ -101,13 +110,35 @@ def sqpMarkerChunk(M, K, chunk=SQP_MARKER_CHUNK):
|
|
|
101
110
|
|
|
102
111
|
|
|
103
112
|
### Bound CPU sample shards
|
|
104
|
-
def sqpSampleChunk(N, K, chunk=None):
|
|
113
|
+
def sqpSampleChunk(N, K, chunk=None, mapped=False):
|
|
105
114
|
if chunk is None:
|
|
106
|
-
chunk = 16_384 if K <= 16 else SQP_SAMPLE_CHUNK
|
|
115
|
+
chunk = 16_384 if K <= (32 if mapped else 16) else SQP_SAMPLE_CHUNK
|
|
107
116
|
n = max(1, SQP_SAMPLE_WORKSPACE_BYTES // (8 * K * (K + 1)))
|
|
108
117
|
return min(N, chunk, n)
|
|
109
118
|
|
|
110
119
|
|
|
120
|
+
### Adapt the CPU pair-statistics budget to capacity and live headroom
|
|
121
|
+
def sqpPairWorkspaceBytes(ram=0, data_bytes=0, work_bytes=0, over_ram=False, avail_ram=None):
|
|
122
|
+
base = SQP_PAIR_WORKSPACE_BYTES
|
|
123
|
+
cap = SQP_PAIR_MAX_BYTES
|
|
124
|
+
if base <= 0:
|
|
125
|
+
return 0
|
|
126
|
+
if ram > 0 and cap > base and base >= (1 << 30):
|
|
127
|
+
share = ram // 4
|
|
128
|
+
avail = (
|
|
129
|
+
share - work_bytes if over_ram else min(share, (3 * ram) // 4 - data_bytes - work_bytes)
|
|
130
|
+
)
|
|
131
|
+
budget = min(cap, max(base, avail))
|
|
132
|
+
else:
|
|
133
|
+
budget = base
|
|
134
|
+
if avail_ram is not None:
|
|
135
|
+
# Leave headroom for peer allocations and keep cached panels resident
|
|
136
|
+
free = avail_ram if over_ram else avail_ram - data_bytes
|
|
137
|
+
live = min(max(0, free) // 2, max(0, free - SQP_MARKER_WORKSPACE_BYTES))
|
|
138
|
+
budget = min(budget, live)
|
|
139
|
+
return max(0, budget)
|
|
140
|
+
|
|
141
|
+
|
|
111
142
|
### Bound the CUDA tile size
|
|
112
143
|
def gpuTileBytes(size, limit=GPU_TILE_BYTES):
|
|
113
144
|
return min(limit, max(GPU_MIN_TILE_BYTES, size // 8))
|