fastmixture2 2.0.5__tar.gz → 2.0.6__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.5/fastmixture2.egg-info → fastmixture2-2.0.6}/PKG-INFO +46 -54
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/README.md +45 -53
- fastmixture2-2.0.6/fastmixture2/__init__.py +1 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/defaults.py +1 -3
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/fastmixture2.py +15 -5
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/functions.py +154 -72
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/gpu.py +305 -160
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/kernels.py +22 -2
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/main.py +1 -1
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/plink.py +37 -8
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/shared.pyx +25 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/sqp.pyx +37 -5
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/utils.py +91 -20
- {fastmixture2-2.0.5 → fastmixture2-2.0.6/fastmixture2.egg-info}/PKG-INFO +46 -54
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/helpers.py +11 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_bootstrap.py +9 -5
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_cli.py +4 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_cpu_scaling.py +204 -1
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_cpu_subset.py +142 -8
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_cross_validation.py +5 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_frequency_cache.py +76 -1
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_called.py +236 -229
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_gl_precision.py +47 -4
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_large.py +6 -6
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_precision.py +2 -2
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_safety.py +75 -3
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_subset.py +115 -5
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_initialization.py +15 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_likelihoods.py +4 -3
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_plink_files.py +176 -1
- fastmixture2-2.0.6/tests/test_restarts.py +853 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_subset_modes.py +7 -5
- fastmixture2-2.0.5/fastmixture2/__init__.py +0 -1
- fastmixture2-2.0.5/tests/test_restarts.py +0 -362
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/LICENSE +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/MANIFEST.in +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/em.pyx +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/packed.pxd +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/svd.pyx +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2/threads.pxd +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2.egg-info/SOURCES.txt +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2.egg-info/dependency_links.txt +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2.egg-info/entry_points.txt +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2.egg-info/requires.txt +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/fastmixture2.egg-info/top_level.txt +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/pyproject.toml +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/setup.cfg +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/setup.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/check_portable.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/run_tests.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_adversarial_io.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_convergence.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_distribution.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_genotypes.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_em.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_modes.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_stat_reuse.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_streamed.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_supervision.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_gpu_svd_cache.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_numerical_equivalence.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_optimizers.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_q_constraints.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_sqp_scoring.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_sqp_solver.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/test_threads.py +0 -0
- {fastmixture2-2.0.5 → fastmixture2-2.0.6}/tests/validate_distribution.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastmixture2
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.6
|
|
4
4
|
Summary: Biobank-scale ancestry estimation in unrelated individuals
|
|
5
5
|
Author-email: "J. Meisner" <meisnerucph@gmail.com>, "L. Thunegard" <lisathunegard@icloud.com>
|
|
6
6
|
License-Expression: GPL-3.0-only
|
|
@@ -31,15 +31,20 @@ Dynamic: license-file
|
|
|
31
31
|
|
|
32
32
|
# fastmixture2
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo: a snake-shaped 2 intertwined with a colorful DNA helix" 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>
|
|
37
43
|
|
|
38
44
|
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
39
45
|
frequencies (`P`) by maximum likelihood. It reads SNP-major PLINK genotypes
|
|
40
|
-
or ANGSD Beagle genotype likelihoods. Unsupervised
|
|
41
|
-
|
|
42
|
-
All modes use safeguarded SQP/ZAL updates on CPU or, with `--gpu`, on NVIDIA CUDA.
|
|
46
|
+
or ANGSD Beagle genotype likelihoods. Unsupervised, supervised and projection
|
|
47
|
+
modes run on CPU or, with `--gpu`, on NVIDIA CUDA.
|
|
43
48
|
|
|
44
49
|
## Installation
|
|
45
50
|
|
|
@@ -70,7 +75,7 @@ conda activate fastmixture2-cpu
|
|
|
70
75
|
|
|
71
76
|
For GPU use, select `environment-gpu.yml` and activate `fastmixture2-gpu`.
|
|
72
77
|
|
|
73
|
-
PyPI wheels cover Linux (glibc) and macOS
|
|
78
|
+
PyPI wheels cover Linux (glibc) and macOS 15 or newer, on x86-64 and ARM64.
|
|
74
79
|
They use AVX2 on supported x86-64 CPUs and NEON on ARM64, including Apple Silicon:
|
|
75
80
|
|
|
76
81
|
```bash
|
|
@@ -117,7 +122,7 @@ fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
|
117
122
|
- `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
|
|
118
123
|
internally. Exactly uniform triplets contribute no ancestry information.
|
|
119
124
|
|
|
120
|
-
Per-chromosome inputs are fitted jointly without
|
|
125
|
+
Per-chromosome inputs are memory-mapped and fitted jointly without a merged BED:
|
|
121
126
|
|
|
122
127
|
```bash
|
|
123
128
|
fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
@@ -126,9 +131,7 @@ fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
|
126
131
|
The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
|
|
127
132
|
such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
|
|
128
133
|
in the same order. Marker rows, including annotated P output, follow the supplied
|
|
129
|
-
file order.
|
|
130
|
-
per marker (8 bytes on 64-bit systems) and bounded transfer tiles. This works
|
|
131
|
-
with CPU, CUDA, supervised estimation, projection, CV, bootstrap and checkpoints.
|
|
134
|
+
file order. Per-chromosome input works on CPU and CUDA in all modes.
|
|
132
135
|
|
|
133
136
|
Perform sample and variant QC first. For each K, try several seeds and keep
|
|
134
137
|
the converged fit with the highest log-likelihood. Component labels may change
|
|
@@ -139,15 +142,6 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
|
|
|
139
142
|
in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
|
|
140
143
|
Resuming a checkpoint retains its saved estimates.
|
|
141
144
|
|
|
142
|
-
Add `--restarts N` to try N additional restart attempts in unsupervised mode (default 0).
|
|
143
|
-
Each starts from the original finished fit, permutes Q columns while retaining P, and
|
|
144
|
-
jointly refines a fresh genome-wide 50,000-SNP subset. Smaller panels use all SNPs.
|
|
145
|
-
Larger panels then project P and refit the full data. Only full-data improvements are
|
|
146
|
-
retained. This works with both input formats on CPU and CUDA, uses `--seed`,
|
|
147
|
-
and keeps the same `--iter` and `--tole` per stage. CV and bootstrap retain their
|
|
148
|
-
usual refit settings.
|
|
149
|
-
At K = 1 it has no effect.
|
|
150
|
-
|
|
151
145
|
Add `--gpu` to use CUDA with either input format:
|
|
152
146
|
|
|
153
147
|
```bash
|
|
@@ -158,36 +152,20 @@ CPU and CUDA support `1 <= K <= 128` for both input formats in all modes.
|
|
|
158
152
|
CUDA keeps input data on the GPU when they fit and streams in blocks otherwise.
|
|
159
153
|
Small CPU/GPU differences can arise from floating-point arithmetic.
|
|
160
154
|
|
|
161
|
-
At K > 1, unsupervised
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
subset likelihood refinement.
|
|
170
|
-
|
|
171
|
-
Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
|
|
172
|
-
into a temporary memory-mapped file. CUDA streams the subset when it does not
|
|
173
|
-
fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
|
|
174
|
-
storage.
|
|
175
|
-
|
|
176
|
-
Refinement uses safeguarded SQP/ZAL with EM/QN rescue when needed, for both
|
|
177
|
-
input formats and all modes. CPU refinement uses float64. CUDA uses mixed
|
|
178
|
-
SQP statistics before final float64 refinement. Parameters, constrained solves,
|
|
179
|
-
EM/QN and likelihood checks stay in float64. EM/QN runs on CUDA for both
|
|
180
|
-
resident and streamed input. PLINK rescue falls back to CPU if a CUDA allocation
|
|
181
|
-
fails.
|
|
182
|
-
|
|
183
|
-
Workspaces use bounded blocks. Input storage, Q, P and optimizer history are
|
|
184
|
-
additional allocations that grow with panel size and K.
|
|
155
|
+
At K > 1, unsupervised fits use SVD/ALS on up to 50,000 genome-wide SNPs, with
|
|
156
|
+
subset refinement for larger panels. All modes use safeguarded SQP/ZAL with EM/QN
|
|
157
|
+
rescue and float64 likelihood checks. CPU fitting uses float64. CUDA uses
|
|
158
|
+
mixed precision followed by float64 refinement.
|
|
159
|
+
|
|
160
|
+
Processing uses bounded tiles. Total memory still grows with panel size and K.
|
|
161
|
+
Temporary files use `TMPDIR`. For large panels, point it to disk-backed scratch
|
|
162
|
+
with sufficient space.
|
|
185
163
|
|
|
186
164
|
The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
187
|
-
`--threads`
|
|
165
|
+
`--threads` also controls CPU work during GPU fits.
|
|
188
166
|
The optimizer scales the tolerance by observed genotypes or informative
|
|
189
167
|
likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
|
|
190
|
-
|
|
168
|
+
Run `fastmixture2 --help` for the full CLI.
|
|
191
169
|
|
|
192
170
|
### Beagle cache
|
|
193
171
|
|
|
@@ -282,7 +260,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
|
282
260
|
```
|
|
283
261
|
|
|
284
262
|
`--bootstrap` defaults to 200 replicates. Each replicate starts from the
|
|
285
|
-
full-data fit and takes up to three
|
|
263
|
+
full-data fit and takes up to three refinement iterations.
|
|
286
264
|
Use `--bootstrap-iter` for longer refits. Add `--bootstrap-tole` to stop at a mean
|
|
287
265
|
likelihood gain per informative entry, within that iteration limit. The log
|
|
288
266
|
reports refit termination. Short refits give a local estimate of uncertainty.
|
|
@@ -296,6 +274,23 @@ Add `--gpu` for CUDA refits. Projection errors are conditional on the supplied
|
|
|
296
274
|
P matrix. Supervised reference samples have zero Q uncertainty. Bootstrap and
|
|
297
275
|
CV must be run separately.
|
|
298
276
|
|
|
277
|
+
### Restarts
|
|
278
|
+
|
|
279
|
+
Try additional unsupervised fits with `--restarts N` (default 0):
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --restarts 6 --out cohort
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Each round tries a Q-column permutation and a component merge/split mutation,
|
|
286
|
+
followed by full-data refits. Panels above 50,000 SNPs use fresh subsets.
|
|
287
|
+
For K >= 3, N rounds add up to 2N full-data fits. Outputs and checkpoints
|
|
288
|
+
retain the best full-data fit.
|
|
289
|
+
|
|
290
|
+
Restarts support both input formats on CPU and CUDA, use `--seed`, and keep
|
|
291
|
+
the same `--iter` and `--tole` per stage. K = 2 uses only Q permutations.
|
|
292
|
+
At K = 1 they have no effect.
|
|
293
|
+
|
|
299
294
|
### Checkpointing
|
|
300
295
|
|
|
301
296
|
Save accepted estimates and resume an interrupted CPU or GPU fit:
|
|
@@ -307,7 +302,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
|
307
302
|
|
|
308
303
|
Keep the same input, supervision and projection files when resuming.
|
|
309
304
|
With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
|
|
310
|
-
requested number of additional
|
|
305
|
+
requested number of additional restart rounds after the resumed fit.
|
|
311
306
|
|
|
312
307
|
## Output
|
|
313
308
|
|
|
@@ -325,10 +320,8 @@ Rows follow input order and columns correspond to components. Use
|
|
|
325
320
|
P. Projection does not write P. For PLINK, P is the frequency of BIM A1.
|
|
326
321
|
For Beagle, it is the frequency of allele2.
|
|
327
322
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
likelihoods before output rounding. Console likelihoods use six decimal
|
|
331
|
-
places. Numbers have no thousands separators.
|
|
323
|
+
Matrices use ten decimal places. Logs retain full-precision likelihoods and
|
|
324
|
+
iteration counts, including ALS when used.
|
|
332
325
|
|
|
333
326
|
Outputs, checkpoints and caches use standard file permissions controlled by
|
|
334
327
|
your umask.
|
|
@@ -338,7 +331,6 @@ numerical failure. Unsuccessful fits retain the best accepted parameters.
|
|
|
338
331
|
|
|
339
332
|
Parallel jobs should use distinct output prefixes. Build each likelihood cache
|
|
340
333
|
with one job, then reuse it across fits, or use a separate cache path per job.
|
|
341
|
-
fastmixture2 does not create filesystem locks or require private lock directories.
|
|
342
334
|
|
|
343
335
|
## Authors and license
|
|
344
336
|
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
# fastmixture2
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/fastmixture2-logo-small-wordmark.png" alt="fastmixture2 logo: a snake-shaped 2 intertwined with a colorful DNA helix" 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>
|
|
6
12
|
|
|
7
13
|
`fastmixture2` estimates ancestry proportions (`Q`) and ancestral allele
|
|
8
14
|
frequencies (`P`) by maximum likelihood. It reads SNP-major PLINK genotypes
|
|
9
|
-
or ANGSD Beagle genotype likelihoods. Unsupervised
|
|
10
|
-
|
|
11
|
-
All modes use safeguarded SQP/ZAL updates on CPU or, with `--gpu`, on NVIDIA CUDA.
|
|
15
|
+
or ANGSD Beagle genotype likelihoods. Unsupervised, supervised and projection
|
|
16
|
+
modes run on CPU or, with `--gpu`, on NVIDIA CUDA.
|
|
12
17
|
|
|
13
18
|
## Installation
|
|
14
19
|
|
|
@@ -39,7 +44,7 @@ conda activate fastmixture2-cpu
|
|
|
39
44
|
|
|
40
45
|
For GPU use, select `environment-gpu.yml` and activate `fastmixture2-gpu`.
|
|
41
46
|
|
|
42
|
-
PyPI wheels cover Linux (glibc) and macOS
|
|
47
|
+
PyPI wheels cover Linux (glibc) and macOS 15 or newer, on x86-64 and ARM64.
|
|
43
48
|
They use AVX2 on supported x86-64 CPUs and NEON on ARM64, including Apple Silicon:
|
|
44
49
|
|
|
45
50
|
```bash
|
|
@@ -86,7 +91,7 @@ fastmixture2 --beagle cohort.beagle.gz --K 5 --threads 8 --out cohort.gl
|
|
|
86
91
|
- `--beagle` takes a gzipped ANGSD Beagle file. Likelihood triplets are normalized
|
|
87
92
|
internally. Exactly uniform triplets contribute no ancestry information.
|
|
88
93
|
|
|
89
|
-
Per-chromosome inputs are fitted jointly without
|
|
94
|
+
Per-chromosome inputs are memory-mapped and fitted jointly without a merged BED:
|
|
90
95
|
|
|
91
96
|
```bash
|
|
92
97
|
fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
@@ -95,9 +100,7 @@ fastmixture2 --bfile chr{1..22} --K 5 --threads 8 --out cohort
|
|
|
95
100
|
The shell expands `chr{1..22}` in chromosome order. Explicit prefixes also work,
|
|
96
101
|
such as `--bfile chr1 chr2 chr3`. All FAM files must have identical FID/IID pairs
|
|
97
102
|
in the same order. Marker rows, including annotated P output, follow the supplied
|
|
98
|
-
file order.
|
|
99
|
-
per marker (8 bytes on 64-bit systems) and bounded transfer tiles. This works
|
|
100
|
-
with CPU, CUDA, supervised estimation, projection, CV, bootstrap and checkpoints.
|
|
103
|
+
file order. Per-chromosome input works on CPU and CUDA in all modes.
|
|
101
104
|
|
|
102
105
|
Perform sample and variant QC first. For each K, try several seeds and keep
|
|
103
106
|
the converged fit with the highest log-likelihood. Component labels may change
|
|
@@ -108,15 +111,6 @@ frequencies. It uses `--seed` and works with either input format on CPU or CUDA
|
|
|
108
111
|
in unsupervised mode. With `--exact-cv`, each fold also starts randomly.
|
|
109
112
|
Resuming a checkpoint retains its saved estimates.
|
|
110
113
|
|
|
111
|
-
Add `--restarts N` to try N additional restart attempts in unsupervised mode (default 0).
|
|
112
|
-
Each starts from the original finished fit, permutes Q columns while retaining P, and
|
|
113
|
-
jointly refines a fresh genome-wide 50,000-SNP subset. Smaller panels use all SNPs.
|
|
114
|
-
Larger panels then project P and refit the full data. Only full-data improvements are
|
|
115
|
-
retained. This works with both input formats on CPU and CUDA, uses `--seed`,
|
|
116
|
-
and keeps the same `--iter` and `--tole` per stage. CV and bootstrap retain their
|
|
117
|
-
usual refit settings.
|
|
118
|
-
At K = 1 it has no effect.
|
|
119
|
-
|
|
120
114
|
Add `--gpu` to use CUDA with either input format:
|
|
121
115
|
|
|
122
116
|
```bash
|
|
@@ -127,36 +121,20 @@ CPU and CUDA support `1 <= K <= 128` for both input formats in all modes.
|
|
|
127
121
|
CUDA keeps input data on the GPU when they fit and streams in blocks otherwise.
|
|
128
122
|
Small CPU/GPU differences can arise from floating-point arithmetic.
|
|
129
123
|
|
|
130
|
-
At K > 1, unsupervised
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
subset likelihood refinement.
|
|
139
|
-
|
|
140
|
-
Subsets exceeding 512 MiB on CPU or 256 MiB on CUDA are built in bounded blocks
|
|
141
|
-
into a temporary memory-mapped file. CUDA streams the subset when it does not
|
|
142
|
-
fit in VRAM. Temporary files use `TMPDIR`, which can point to disk-backed scratch
|
|
143
|
-
storage.
|
|
144
|
-
|
|
145
|
-
Refinement uses safeguarded SQP/ZAL with EM/QN rescue when needed, for both
|
|
146
|
-
input formats and all modes. CPU refinement uses float64. CUDA uses mixed
|
|
147
|
-
SQP statistics before final float64 refinement. Parameters, constrained solves,
|
|
148
|
-
EM/QN and likelihood checks stay in float64. EM/QN runs on CUDA for both
|
|
149
|
-
resident and streamed input. PLINK rescue falls back to CPU if a CUDA allocation
|
|
150
|
-
fails.
|
|
151
|
-
|
|
152
|
-
Workspaces use bounded blocks. Input storage, Q, P and optimizer history are
|
|
153
|
-
additional allocations that grow with panel size and K.
|
|
124
|
+
At K > 1, unsupervised fits use SVD/ALS on up to 50,000 genome-wide SNPs, with
|
|
125
|
+
subset refinement for larger panels. All modes use safeguarded SQP/ZAL with EM/QN
|
|
126
|
+
rescue and float64 likelihood checks. CPU fitting uses float64. CUDA uses
|
|
127
|
+
mixed precision followed by float64 refinement.
|
|
128
|
+
|
|
129
|
+
Processing uses bounded tiles. Total memory still grows with panel size and K.
|
|
130
|
+
Temporary files use `TMPDIR`. For large panels, point it to disk-backed scratch
|
|
131
|
+
with sufficient space.
|
|
154
132
|
|
|
155
133
|
The defaults are `--threads 1`, `--seed 42`, `--iter 1000` and `--tole 1e-10`.
|
|
156
|
-
`--threads`
|
|
134
|
+
`--threads` also controls CPU work during GPU fits.
|
|
157
135
|
The optimizer scales the tolerance by observed genotypes or informative
|
|
158
136
|
likelihood triplets. `--iter` and `--tole` apply to each refinement stage.
|
|
159
|
-
|
|
137
|
+
Run `fastmixture2 --help` for the full CLI.
|
|
160
138
|
|
|
161
139
|
### Beagle cache
|
|
162
140
|
|
|
@@ -251,7 +229,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 \
|
|
|
251
229
|
```
|
|
252
230
|
|
|
253
231
|
`--bootstrap` defaults to 200 replicates. Each replicate starts from the
|
|
254
|
-
full-data fit and takes up to three
|
|
232
|
+
full-data fit and takes up to three refinement iterations.
|
|
255
233
|
Use `--bootstrap-iter` for longer refits. Add `--bootstrap-tole` to stop at a mean
|
|
256
234
|
likelihood gain per informative entry, within that iteration limit. The log
|
|
257
235
|
reports refit termination. Short refits give a local estimate of uncertainty.
|
|
@@ -265,6 +243,23 @@ Add `--gpu` for CUDA refits. Projection errors are conditional on the supplied
|
|
|
265
243
|
P matrix. Supervised reference samples have zero Q uncertainty. Bootstrap and
|
|
266
244
|
CV must be run separately.
|
|
267
245
|
|
|
246
|
+
### Restarts
|
|
247
|
+
|
|
248
|
+
Try additional unsupervised fits with `--restarts N` (default 0):
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
fastmixture2 --bfile cohort --K 5 --threads 8 --restarts 6 --out cohort
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Each round tries a Q-column permutation and a component merge/split mutation,
|
|
255
|
+
followed by full-data refits. Panels above 50,000 SNPs use fresh subsets.
|
|
256
|
+
For K >= 3, N rounds add up to 2N full-data fits. Outputs and checkpoints
|
|
257
|
+
retain the best full-data fit.
|
|
258
|
+
|
|
259
|
+
Restarts support both input formats on CPU and CUDA, use `--seed`, and keep
|
|
260
|
+
the same `--iter` and `--tole` per stage. K = 2 uses only Q permutations.
|
|
261
|
+
At K = 1 they have no effect.
|
|
262
|
+
|
|
268
263
|
### Checkpointing
|
|
269
264
|
|
|
270
265
|
Save accepted estimates and resume an interrupted CPU or GPU fit:
|
|
@@ -276,7 +271,7 @@ fastmixture2 --bfile cohort --K 5 --threads 8 --resume run.ckpt --out cohort
|
|
|
276
271
|
|
|
277
272
|
Keep the same input, supervision and projection files when resuming.
|
|
278
273
|
With `--restarts`, checkpoints retain the best full-data fit. Resuming runs the
|
|
279
|
-
requested number of additional
|
|
274
|
+
requested number of additional restart rounds after the resumed fit.
|
|
280
275
|
|
|
281
276
|
## Output
|
|
282
277
|
|
|
@@ -294,10 +289,8 @@ Rows follow input order and columns correspond to components. Use
|
|
|
294
289
|
P. Projection does not write P. For PLINK, P is the frequency of BIM A1.
|
|
295
290
|
For Beagle, it is the frequency of allele2.
|
|
296
291
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
likelihoods before output rounding. Console likelihoods use six decimal
|
|
300
|
-
places. Numbers have no thousands separators.
|
|
292
|
+
Matrices use ten decimal places. Logs retain full-precision likelihoods and
|
|
293
|
+
iteration counts, including ALS when used.
|
|
301
294
|
|
|
302
295
|
Outputs, checkpoints and caches use standard file permissions controlled by
|
|
303
296
|
your umask.
|
|
@@ -307,7 +300,6 @@ numerical failure. Unsuccessful fits retain the best accepted parameters.
|
|
|
307
300
|
|
|
308
301
|
Parallel jobs should use distinct output prefixes. Build each likelihood cache
|
|
309
302
|
with one job, then reuse it across fits, or use a separate cache path per job.
|
|
310
|
-
fastmixture2 does not create filesystem locks or require private lock directories.
|
|
311
303
|
|
|
312
304
|
## Authors and license
|
|
313
305
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.0.6"
|
|
@@ -30,9 +30,6 @@ ALS_TOLERANCE = 1e-4
|
|
|
30
30
|
|
|
31
31
|
# Refinement
|
|
32
32
|
GPU_SQP_EXACT_POLISH_ITERATIONS = 2
|
|
33
|
-
GPU_SQP_Q_REUSE_MIN_K = 10
|
|
34
|
-
GPU_SQP_Q_REUSE_DELAY = 8
|
|
35
|
-
GPU_SQP_Q_CACHE_BYTES = 64 << 20
|
|
36
33
|
LIKELIHOOD_TRUST_RADIUS = 0.02
|
|
37
34
|
# Halve the step before falling back to EM
|
|
38
35
|
LIKELIHOOD_BACKTRACK_STEPS = 3
|
|
@@ -42,6 +39,7 @@ LIKELIHOOD_CONVERGENCE_WINDOW = 10
|
|
|
42
39
|
GPU_TILE_BYTES = 512 << 20
|
|
43
40
|
GPU_SQP_STAT_BYTES = 512 << 20
|
|
44
41
|
GPU_SQP_WORKSPACE_BYTES = 128 << 20
|
|
42
|
+
GPU_BOOT_STAT_BYTES = 64 << 20
|
|
45
43
|
GPU_MIN_TILE_BYTES = 128 << 20
|
|
46
44
|
GPU_PREFETCH_MIN_TILES = 3
|
|
47
45
|
GPU_MEMORY_RESERVE_BYTES = 512 << 20
|
|
@@ -514,8 +514,11 @@ def methodInfo(args, use_gpu, mode):
|
|
|
514
514
|
f"Convergence: {defaults.LIKELIHOOD_CONVERGENCE_WINDOW}-iteration window | "
|
|
515
515
|
"independent float64 EM check",
|
|
516
516
|
]
|
|
517
|
-
if args.restarts:
|
|
518
|
-
|
|
517
|
+
if args.restarts and args.K > 1:
|
|
518
|
+
n = args.restarts if args.K >= 3 else 0
|
|
519
|
+
res.append(
|
|
520
|
+
f"Restarts: {args.restarts} rounds | Q permutations {args.restarts} | merge/split {n}"
|
|
521
|
+
)
|
|
519
522
|
return res
|
|
520
523
|
|
|
521
524
|
|
|
@@ -574,7 +577,11 @@ def cvRun(G, P0, Q0, q_nrm0, K, rng, run):
|
|
|
574
577
|
if run.get("random_init", False):
|
|
575
578
|
P, Q = utils.initializeRandom(X, K, rng)
|
|
576
579
|
else:
|
|
577
|
-
|
|
580
|
+
|
|
581
|
+
def log(val):
|
|
582
|
+
functions.logInfo(run, f"CV fold {f + 1}: {val}")
|
|
583
|
+
|
|
584
|
+
P, Q = utils.initializeUnsupervised(X, K, rng, strict=False, run={"log": log})
|
|
578
585
|
f_run = dict(run)
|
|
579
586
|
f_run.pop("log", None)
|
|
580
587
|
f_run["quiet"] = True
|
|
@@ -810,6 +817,7 @@ def _run(args, stack):
|
|
|
810
817
|
boot_h, b_chr = utils.bootBlock(args.bfile, M, args.bootstrap_block)
|
|
811
818
|
|
|
812
819
|
run = {
|
|
820
|
+
"seed": args.seed,
|
|
813
821
|
"iter": args.iter,
|
|
814
822
|
"tole": args.tole,
|
|
815
823
|
"check": check,
|
|
@@ -916,8 +924,9 @@ def _run(args, stack):
|
|
|
916
924
|
else:
|
|
917
925
|
P, Q = resumed[:2]
|
|
918
926
|
|
|
919
|
-
#
|
|
920
|
-
|
|
927
|
+
# Restarts reuse pooled frequencies for full-marker projection
|
|
928
|
+
if not args.restarts:
|
|
929
|
+
G.pop("freq", None)
|
|
921
930
|
|
|
922
931
|
# Reject input changes during parsing or initialization
|
|
923
932
|
if inputKey(args) != src_key:
|
|
@@ -951,6 +960,7 @@ def _run(args, stack):
|
|
|
951
960
|
if args.restarts:
|
|
952
961
|
rs_rng = np.random.default_rng(np.random.SeedSequence([args.seed, 0x5253]))
|
|
953
962
|
res = functions.restartRun(G, P, Q, q_nrm, rs_rng, run, res, args.restarts)
|
|
963
|
+
G.pop("freq", None)
|
|
954
964
|
|
|
955
965
|
# Refit isolated entry-masked folds from scalable or exact starts
|
|
956
966
|
if args.cv is not None:
|