adamixture 1.0.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.
- adamixture-1.0.0/.github/workflows/release.yml +127 -0
- adamixture-1.0.0/.gitignore +150 -0
- adamixture-1.0.0/PKG-INFO +150 -0
- adamixture-1.0.0/README.md +122 -0
- adamixture-1.0.0/adamixture/__init__.py +1 -0
- adamixture-1.0.0/adamixture/_version.py +34 -0
- adamixture-1.0.0/adamixture/entry.py +114 -0
- adamixture-1.0.0/adamixture/model/__init__.py +0 -0
- adamixture-1.0.0/adamixture/model/adamixture.py +160 -0
- adamixture-1.0.0/adamixture/model/em_adam.py +139 -0
- adamixture-1.0.0/adamixture/src/__init__.py +0 -0
- adamixture-1.0.0/adamixture/src/evaluation.py +153 -0
- adamixture-1.0.0/adamixture/src/main.py +66 -0
- adamixture-1.0.0/adamixture/src/snp_reader.py +81 -0
- adamixture-1.0.0/adamixture/src/svd.py +145 -0
- adamixture-1.0.0/adamixture/src/utils.py +65 -0
- adamixture-1.0.0/adamixture/src/utils_c/__init__.py +1 -0
- adamixture-1.0.0/adamixture/src/utils_c/em.c +29500 -0
- adamixture-1.0.0/adamixture/src/utils_c/em.pyx +190 -0
- adamixture-1.0.0/adamixture/src/utils_c/rsvd.c +31294 -0
- adamixture-1.0.0/adamixture/src/utils_c/rsvd.pyx +107 -0
- adamixture-1.0.0/adamixture/src/utils_c/tools.c +30292 -0
- adamixture-1.0.0/adamixture/src/utils_c/tools.pyx +178 -0
- adamixture-1.0.0/adamixture.egg-info/PKG-INFO +150 -0
- adamixture-1.0.0/adamixture.egg-info/SOURCES.txt +34 -0
- adamixture-1.0.0/adamixture.egg-info/dependency_links.txt +1 -0
- adamixture-1.0.0/adamixture.egg-info/entry_points.txt +2 -0
- adamixture-1.0.0/adamixture.egg-info/requires.txt +10 -0
- adamixture-1.0.0/adamixture.egg-info/top_level.txt +1 -0
- adamixture-1.0.0/assets/logo.png +0 -0
- adamixture-1.0.0/pyproject.toml +16 -0
- adamixture-1.0.0/setup.cfg +46 -0
- adamixture-1.0.0/setup.py +66 -0
- adamixture-1.0.0/tests/test_smoke.py +19 -0
- adamixture-1.0.0/tox.ini +36 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
name: Build and Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
tests:
|
|
9
|
+
name: Run tests
|
|
10
|
+
runs-on: ${{ matrix.platform }}
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
platform: [ubuntu-latest, macos-14]
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: ${{ matrix.python-version }}
|
|
22
|
+
|
|
23
|
+
- name: Configure OpenMP (Linux)
|
|
24
|
+
if: runner.os == 'Linux'
|
|
25
|
+
run: |
|
|
26
|
+
sudo apt-get install -y libgomp1
|
|
27
|
+
echo "CC=gcc" >> $GITHUB_ENV
|
|
28
|
+
echo "CFLAGS=-fopenmp" >> $GITHUB_ENV
|
|
29
|
+
echo "LDFLAGS=-fopenmp" >> $GITHUB_ENV
|
|
30
|
+
|
|
31
|
+
- name: Install OpenMP (macOS only)
|
|
32
|
+
if: runner.os == 'macOS'
|
|
33
|
+
run: |
|
|
34
|
+
brew install libomp
|
|
35
|
+
LIBOMP_PREFIX=$(brew --prefix libomp)
|
|
36
|
+
echo "CC=/usr/bin/clang" >> $GITHUB_ENV
|
|
37
|
+
echo "CFLAGS=-Xpreprocessor -fopenmp -I${LIBOMP_PREFIX}/include" >> $GITHUB_ENV
|
|
38
|
+
echo "LDFLAGS=-L${LIBOMP_PREFIX}/lib -lomp -Wl,-rpath,${LIBOMP_PREFIX}/lib" >> $GITHUB_ENV
|
|
39
|
+
|
|
40
|
+
- name: Install dependencies
|
|
41
|
+
run: |
|
|
42
|
+
python -m pip install --upgrade pip
|
|
43
|
+
python -m pip install tox
|
|
44
|
+
|
|
45
|
+
- name: Test with tox
|
|
46
|
+
uses: GabrielBB/xvfb-action@v1
|
|
47
|
+
with:
|
|
48
|
+
run: python -m tox
|
|
49
|
+
env:
|
|
50
|
+
PLATFORM: ${{ matrix.platform }}
|
|
51
|
+
|
|
52
|
+
build_wheels:
|
|
53
|
+
name: Build wheels on ${{ matrix.os }}
|
|
54
|
+
needs: tests
|
|
55
|
+
runs-on: ${{ matrix.os }}
|
|
56
|
+
strategy:
|
|
57
|
+
matrix:
|
|
58
|
+
os: [ubuntu-latest, macos-14]
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v4
|
|
62
|
+
|
|
63
|
+
- name: Install OpenMP (macOS)
|
|
64
|
+
if: runner.os == 'macOS'
|
|
65
|
+
run: brew install libomp
|
|
66
|
+
|
|
67
|
+
- name: Build wheels
|
|
68
|
+
uses: pypa/cibuildwheel@v2.19.2
|
|
69
|
+
env:
|
|
70
|
+
CIBW_BUILD: cp310-* cp311-* cp312-*
|
|
71
|
+
CIBW_SKIP: "pp* *musllinux* *i686*"
|
|
72
|
+
|
|
73
|
+
CIBW_ARCHS_LINUX: "x86_64"
|
|
74
|
+
|
|
75
|
+
CIBW_ARCHS_MACOS: "x86_64 arm64"
|
|
76
|
+
|
|
77
|
+
CIBW_ENVIRONMENT_MACOS: >
|
|
78
|
+
MACOSX_DEPLOYMENT_TARGET=14.0
|
|
79
|
+
CC=/usr/bin/clang
|
|
80
|
+
CFLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include"
|
|
81
|
+
LDFLAGS="-L$(brew --prefix libomp)/lib -lomp -Wl,-rpath,$(brew --prefix libomp)/lib"
|
|
82
|
+
|
|
83
|
+
CIBW_ENVIRONMENT_LINUX: >
|
|
84
|
+
CFLAGS="-fopenmp"
|
|
85
|
+
LDFLAGS="-fopenmp"
|
|
86
|
+
|
|
87
|
+
- uses: actions/upload-artifact@v4
|
|
88
|
+
with:
|
|
89
|
+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
|
|
90
|
+
path: ./wheelhouse/*.whl
|
|
91
|
+
|
|
92
|
+
build_sdist:
|
|
93
|
+
name: Build source distribution
|
|
94
|
+
needs: tests
|
|
95
|
+
runs-on: ubuntu-latest
|
|
96
|
+
steps:
|
|
97
|
+
- uses: actions/checkout@v4
|
|
98
|
+
- name: Build sdist
|
|
99
|
+
run: pipx run build --sdist
|
|
100
|
+
- uses: actions/upload-artifact@v4
|
|
101
|
+
with:
|
|
102
|
+
name: manual-sdist
|
|
103
|
+
path: dist/*.tar.gz
|
|
104
|
+
|
|
105
|
+
upload_pypi:
|
|
106
|
+
needs: [build_wheels, build_sdist]
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
environment: pypi
|
|
109
|
+
permissions:
|
|
110
|
+
id-token: write
|
|
111
|
+
steps:
|
|
112
|
+
- uses: actions/download-artifact@v4
|
|
113
|
+
with:
|
|
114
|
+
pattern: cibw-*
|
|
115
|
+
path: dist
|
|
116
|
+
merge-multiple: true
|
|
117
|
+
|
|
118
|
+
- uses: actions/download-artifact@v4
|
|
119
|
+
with:
|
|
120
|
+
name: manual-sdist
|
|
121
|
+
path: dist
|
|
122
|
+
merge-multiple: true
|
|
123
|
+
|
|
124
|
+
- name: Publish to PyPI
|
|
125
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
126
|
+
with:
|
|
127
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
95
|
+
__pypackages__/
|
|
96
|
+
|
|
97
|
+
# Celery stuff
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
celerybeat.pid
|
|
100
|
+
|
|
101
|
+
# SageMath parsed files
|
|
102
|
+
*.sage.py
|
|
103
|
+
|
|
104
|
+
# Environments
|
|
105
|
+
.env
|
|
106
|
+
.venv
|
|
107
|
+
env/
|
|
108
|
+
venv/
|
|
109
|
+
ENV/
|
|
110
|
+
env.bak/
|
|
111
|
+
venv.bak/
|
|
112
|
+
|
|
113
|
+
# Spyder project settings
|
|
114
|
+
.spyderproject
|
|
115
|
+
.spyproject
|
|
116
|
+
|
|
117
|
+
# Rope project settings
|
|
118
|
+
.ropeproject
|
|
119
|
+
|
|
120
|
+
# mkdocs documentation
|
|
121
|
+
/site
|
|
122
|
+
|
|
123
|
+
# mypy
|
|
124
|
+
.mypy_cache/
|
|
125
|
+
.dmypy.json
|
|
126
|
+
dmypy.json
|
|
127
|
+
|
|
128
|
+
# Pyre type checker
|
|
129
|
+
.pyre/
|
|
130
|
+
|
|
131
|
+
# Data folder contents
|
|
132
|
+
**/data/**
|
|
133
|
+
|
|
134
|
+
# wandb
|
|
135
|
+
**/wandb/**
|
|
136
|
+
|
|
137
|
+
# logs
|
|
138
|
+
logs/
|
|
139
|
+
|
|
140
|
+
# outputs
|
|
141
|
+
outputs/
|
|
142
|
+
|
|
143
|
+
# figures
|
|
144
|
+
**figures**
|
|
145
|
+
|
|
146
|
+
# DS_Store
|
|
147
|
+
**/.DS_Store
|
|
148
|
+
|
|
149
|
+
# Version file
|
|
150
|
+
neural_admixture/_version.py
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adamixture
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: ADAMIXTURE: Adaptive First-Order Optimization for Biobank-Scale Ancestry Inference
|
|
5
|
+
Home-page: https://github.com/AI-sandbox/adamixture
|
|
6
|
+
Author: Joan Saurina Ricós
|
|
7
|
+
Author-email: joansaurinaricos@gmail.com
|
|
8
|
+
License: CC BY-NC 4.0
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Requires-Dist: configargparse>=1.5.3
|
|
20
|
+
Requires-Dist: Cython>3.0.0
|
|
21
|
+
Requires-Dist: numpy>2.0.0
|
|
22
|
+
Requires-Dist: setuptools>=61.0
|
|
23
|
+
Provides-Extra: testing
|
|
24
|
+
Requires-Dist: tox; extra == "testing"
|
|
25
|
+
Requires-Dist: pytest; extra == "testing"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
27
|
+
Requires-Dist: pytest-mock; extra == "testing"
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+

|
|
34
|
+
[](https://zenodo.org/badge/latestdoi/331290967)
|
|
35
|
+
|
|
36
|
+
# ADAMIXTURE: Adaptive First-Order Optimization for Biobank-Scale Ancestry Inference
|
|
37
|
+
|
|
38
|
+
ADAMIXTURE is an unsupervised global ancestry inference method that scales the ADMIXTURE model to biobank-sized datasets. It combines the Expectation–Maximization (EM) framework with the ADAM first-order optimizer, enabling parameter updates after a single EM step. This approach accelerates convergence while maintaining comparable or improved accuracy, substantially reducing runtime on large genotype datasets. For more information, we recommend reading [our pre-print]().
|
|
39
|
+
|
|
40
|
+
The software can be invoked via CLI and has a similar interface to ADMIXTURE (_e.g._ the output format is completely interchangeable).
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
## System requirements
|
|
45
|
+
|
|
46
|
+
### Hardware requirements
|
|
47
|
+
The successful usage of this package requires a computer with enough RAM to be able to handle the large datasets the network has been designed to work with. Due to this, we recommend using compute clusters whenever available to avoid memory issues.
|
|
48
|
+
|
|
49
|
+
### Software requirements
|
|
50
|
+
|
|
51
|
+
We recommend creating a fresh Python 3.10 virtual environment using `virtualenv` (or `conda`), and then install the package `adamixture` there. As an example, for `virtualenv`, one should launch the following commands:
|
|
52
|
+
|
|
53
|
+
```console
|
|
54
|
+
$ virtualenv --python=python3.9 ~/venv/nadmenv
|
|
55
|
+
$ source ~/venv/nadmenv/bin/activate
|
|
56
|
+
(nadmenv) $ pip install adamixture
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Installation Guide
|
|
60
|
+
|
|
61
|
+
The package can be easily installed in at most a few minutes using `pip` (make sure to add the `--upgrade` flag if updating the version):
|
|
62
|
+
|
|
63
|
+
```console
|
|
64
|
+
(nadmenv) $ pip install adamixture
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Running ADAMIXTURE
|
|
68
|
+
|
|
69
|
+
To train a model, simply invoke the following commands from the root directory of the project. For more info about all the arguments, please run `adamixture --help`. Note that VCF and BED are supported as of now:
|
|
70
|
+
|
|
71
|
+
As an example, the following ADMIXTURE call
|
|
72
|
+
|
|
73
|
+
```console
|
|
74
|
+
$ ./admixture snps_data.bed 8 -s 42
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
would be mimicked in ADAMIXTURE by running
|
|
78
|
+
|
|
79
|
+
```console
|
|
80
|
+
$ adamixture --k 8 --data_path snps_data.bed --save_dir SAVE_PATH --init_file INIT_FILE --name snps_data --seed 42
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Two files will be output to the `SAVE_PATH` directory (the `name` parameter will be used to create the whole filenames):
|
|
84
|
+
|
|
85
|
+
- A `.P` file, similar to ADMIXTURE.
|
|
86
|
+
- A `.Q` file, similar to ADMIXTURE.
|
|
87
|
+
|
|
88
|
+
Logs are printed to the `stdout` channel by default. If you want to save them to a file, you can use the command `tee` along with a pipe:
|
|
89
|
+
|
|
90
|
+
```console
|
|
91
|
+
$ adamixture --k 8 ... | tee run.log
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Other options
|
|
95
|
+
|
|
96
|
+
- `--lr` (float, default: `0.005`):
|
|
97
|
+
Learning rate used by the Adam optimizer in the EM updates.
|
|
98
|
+
|
|
99
|
+
- `--min_lr` (float, default: `1e-6`):
|
|
100
|
+
Minimum learning rate used by the Adam optimizer in the EM updates.
|
|
101
|
+
|
|
102
|
+
- `--lr_decay` (float, default: `0.5`):
|
|
103
|
+
Learning rate decay factor.
|
|
104
|
+
|
|
105
|
+
- `--beta1` (float, default: `0.80`):
|
|
106
|
+
Exponential decay rate for the first moment estimates in Adam.
|
|
107
|
+
|
|
108
|
+
- `--beta2` (float, default: `0.88`):
|
|
109
|
+
Exponential decay rate for the second moment estimates in Adam.
|
|
110
|
+
|
|
111
|
+
- `--reg_adam` (float, default: `1e-8`):
|
|
112
|
+
Numerical stability constant (epsilon) for the Adam optimizer.
|
|
113
|
+
|
|
114
|
+
- `--seed` (int, default: `42`):
|
|
115
|
+
Random number generator seed for reproducibility.
|
|
116
|
+
|
|
117
|
+
- `--k` (int, required):
|
|
118
|
+
Number of ancestral populations (clusters) to infer.
|
|
119
|
+
|
|
120
|
+
- `--max_iter` (int, default: `1500`):
|
|
121
|
+
Maximum number of Adam-EM iterations.
|
|
122
|
+
|
|
123
|
+
- `--check` (int, default: `5`):
|
|
124
|
+
Frequency (in iterations) at which the log-likelihood is evaluated.
|
|
125
|
+
|
|
126
|
+
- `--max_als` (int, default: `1000`):
|
|
127
|
+
Maximum number of iterations for the ALS solver.
|
|
128
|
+
|
|
129
|
+
- `--tole_als` (float, default: `1e-4`):
|
|
130
|
+
Convergence tolerance for the ALS optimization.
|
|
131
|
+
|
|
132
|
+
- `--reg_als` (float, default: `1e-5`):
|
|
133
|
+
Regularization parameter for ALS.
|
|
134
|
+
|
|
135
|
+
- `--power` (int, default: `5`):
|
|
136
|
+
Number of power iterations used in randomized SVD (RSVD).
|
|
137
|
+
|
|
138
|
+
- `--tole_svd` (float, default: `1e-1`):
|
|
139
|
+
Convergence tolerance for the SVD approximation.
|
|
140
|
+
|
|
141
|
+
- `--threads` (int, default: `1`):
|
|
142
|
+
Number of CPU threads used during execution.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
**NOTICE**: This software is available for use free of charge for academic research use only. Academic users may fork this repository and modify and improve to suit their research needs, but also inherit these terms and must include a licensing notice to that effect. Commercial users, for profit companies or consultants, and non-profit institutions not qualifying as "academic research" should contact the authors for a separate license. This applies to this repository directly and any other repository that includes source, executables, or git commands that pull/clone this repository as part of its function. Such repositories, whether ours or others, must include this notice.
|
|
147
|
+
|
|
148
|
+
## Cite
|
|
149
|
+
|
|
150
|
+
When using this software, please cite the following pre-print:
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](https://zenodo.org/badge/latestdoi/331290967)
|
|
7
|
+
|
|
8
|
+
# ADAMIXTURE: Adaptive First-Order Optimization for Biobank-Scale Ancestry Inference
|
|
9
|
+
|
|
10
|
+
ADAMIXTURE is an unsupervised global ancestry inference method that scales the ADMIXTURE model to biobank-sized datasets. It combines the Expectation–Maximization (EM) framework with the ADAM first-order optimizer, enabling parameter updates after a single EM step. This approach accelerates convergence while maintaining comparable or improved accuracy, substantially reducing runtime on large genotype datasets. For more information, we recommend reading [our pre-print]().
|
|
11
|
+
|
|
12
|
+
The software can be invoked via CLI and has a similar interface to ADMIXTURE (_e.g._ the output format is completely interchangeable).
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## System requirements
|
|
17
|
+
|
|
18
|
+
### Hardware requirements
|
|
19
|
+
The successful usage of this package requires a computer with enough RAM to be able to handle the large datasets the network has been designed to work with. Due to this, we recommend using compute clusters whenever available to avoid memory issues.
|
|
20
|
+
|
|
21
|
+
### Software requirements
|
|
22
|
+
|
|
23
|
+
We recommend creating a fresh Python 3.10 virtual environment using `virtualenv` (or `conda`), and then install the package `adamixture` there. As an example, for `virtualenv`, one should launch the following commands:
|
|
24
|
+
|
|
25
|
+
```console
|
|
26
|
+
$ virtualenv --python=python3.9 ~/venv/nadmenv
|
|
27
|
+
$ source ~/venv/nadmenv/bin/activate
|
|
28
|
+
(nadmenv) $ pip install adamixture
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Installation Guide
|
|
32
|
+
|
|
33
|
+
The package can be easily installed in at most a few minutes using `pip` (make sure to add the `--upgrade` flag if updating the version):
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
(nadmenv) $ pip install adamixture
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Running ADAMIXTURE
|
|
40
|
+
|
|
41
|
+
To train a model, simply invoke the following commands from the root directory of the project. For more info about all the arguments, please run `adamixture --help`. Note that VCF and BED are supported as of now:
|
|
42
|
+
|
|
43
|
+
As an example, the following ADMIXTURE call
|
|
44
|
+
|
|
45
|
+
```console
|
|
46
|
+
$ ./admixture snps_data.bed 8 -s 42
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
would be mimicked in ADAMIXTURE by running
|
|
50
|
+
|
|
51
|
+
```console
|
|
52
|
+
$ adamixture --k 8 --data_path snps_data.bed --save_dir SAVE_PATH --init_file INIT_FILE --name snps_data --seed 42
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Two files will be output to the `SAVE_PATH` directory (the `name` parameter will be used to create the whole filenames):
|
|
56
|
+
|
|
57
|
+
- A `.P` file, similar to ADMIXTURE.
|
|
58
|
+
- A `.Q` file, similar to ADMIXTURE.
|
|
59
|
+
|
|
60
|
+
Logs are printed to the `stdout` channel by default. If you want to save them to a file, you can use the command `tee` along with a pipe:
|
|
61
|
+
|
|
62
|
+
```console
|
|
63
|
+
$ adamixture --k 8 ... | tee run.log
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Other options
|
|
67
|
+
|
|
68
|
+
- `--lr` (float, default: `0.005`):
|
|
69
|
+
Learning rate used by the Adam optimizer in the EM updates.
|
|
70
|
+
|
|
71
|
+
- `--min_lr` (float, default: `1e-6`):
|
|
72
|
+
Minimum learning rate used by the Adam optimizer in the EM updates.
|
|
73
|
+
|
|
74
|
+
- `--lr_decay` (float, default: `0.5`):
|
|
75
|
+
Learning rate decay factor.
|
|
76
|
+
|
|
77
|
+
- `--beta1` (float, default: `0.80`):
|
|
78
|
+
Exponential decay rate for the first moment estimates in Adam.
|
|
79
|
+
|
|
80
|
+
- `--beta2` (float, default: `0.88`):
|
|
81
|
+
Exponential decay rate for the second moment estimates in Adam.
|
|
82
|
+
|
|
83
|
+
- `--reg_adam` (float, default: `1e-8`):
|
|
84
|
+
Numerical stability constant (epsilon) for the Adam optimizer.
|
|
85
|
+
|
|
86
|
+
- `--seed` (int, default: `42`):
|
|
87
|
+
Random number generator seed for reproducibility.
|
|
88
|
+
|
|
89
|
+
- `--k` (int, required):
|
|
90
|
+
Number of ancestral populations (clusters) to infer.
|
|
91
|
+
|
|
92
|
+
- `--max_iter` (int, default: `1500`):
|
|
93
|
+
Maximum number of Adam-EM iterations.
|
|
94
|
+
|
|
95
|
+
- `--check` (int, default: `5`):
|
|
96
|
+
Frequency (in iterations) at which the log-likelihood is evaluated.
|
|
97
|
+
|
|
98
|
+
- `--max_als` (int, default: `1000`):
|
|
99
|
+
Maximum number of iterations for the ALS solver.
|
|
100
|
+
|
|
101
|
+
- `--tole_als` (float, default: `1e-4`):
|
|
102
|
+
Convergence tolerance for the ALS optimization.
|
|
103
|
+
|
|
104
|
+
- `--reg_als` (float, default: `1e-5`):
|
|
105
|
+
Regularization parameter for ALS.
|
|
106
|
+
|
|
107
|
+
- `--power` (int, default: `5`):
|
|
108
|
+
Number of power iterations used in randomized SVD (RSVD).
|
|
109
|
+
|
|
110
|
+
- `--tole_svd` (float, default: `1e-1`):
|
|
111
|
+
Convergence tolerance for the SVD approximation.
|
|
112
|
+
|
|
113
|
+
- `--threads` (int, default: `1`):
|
|
114
|
+
Number of CPU threads used during execution.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
**NOTICE**: This software is available for use free of charge for academic research use only. Academic users may fork this repository and modify and improve to suit their research needs, but also inherit these terms and must include a licensing notice to that effect. Commercial users, for profit companies or consultants, and non-profit institutions not qualifying as "academic research" should contact the authors for a separate license. This applies to this repository directly and any other repository that includes source, executables, or git commands that pull/clone this repository as part of its function. Such repositories, whether ours or others, must include this notice.
|
|
119
|
+
|
|
120
|
+
## Cite
|
|
121
|
+
|
|
122
|
+
When using this software, please cite the following pre-print:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ._version import __version__, __version_tuple__
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '1.0.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 0, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g54c5573ac'
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
from typing import List
|
|
4
|
+
import configargparse
|
|
5
|
+
import time
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
|
|
9
|
+
from ._version import __version__
|
|
10
|
+
from .src import utils
|
|
11
|
+
|
|
12
|
+
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(message)s")
|
|
13
|
+
log = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
def parse_args(argv: List[str]):
|
|
16
|
+
"""Training arguments parser"""
|
|
17
|
+
parser = configargparse.ArgumentParser(
|
|
18
|
+
prog='adamixture',
|
|
19
|
+
description='Population clustering using ADAM-EM.',
|
|
20
|
+
config_file_parser_class=configargparse.YAMLConfigFileParser
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
parser.add_argument('--lr', type=float, default=0.005, help='Learning rate')
|
|
24
|
+
parser.add_argument('--beta1', type=float, default=0.80, help='Adam beta1 (1st moment decay)')
|
|
25
|
+
parser.add_argument('--beta2', type=float, default=0.88, help='Adam beta2 (2nd moment decay)')
|
|
26
|
+
parser.add_argument('--reg_adam', type=float, default=1e-8, help='Adam epsilon for numerical stability')
|
|
27
|
+
|
|
28
|
+
parser.add_argument('--lr_decay', type=float, default=0.5, help='Learning rate decay factor')
|
|
29
|
+
parser.add_argument('--min_lr', type=float, default=1e-6, help='Minimum learning rate value')
|
|
30
|
+
|
|
31
|
+
parser.add_argument('--seed', required=False, type=int, default=42, help='Seed')
|
|
32
|
+
parser.add_argument('--k', required=False, type=int, help='Number of populations/clusters.')
|
|
33
|
+
|
|
34
|
+
parser.add_argument('--save_dir', required=True, type=str, help='Save model in this directory')
|
|
35
|
+
parser.add_argument('--data_path', required=True, type=str, help='Path containing the main data')
|
|
36
|
+
parser.add_argument('--name', required=True, type=str, help='Experiment/model name')
|
|
37
|
+
parser.add_argument('--threads', required=False, default=1, type=int, help='Number of threads to be used in the execution.')
|
|
38
|
+
|
|
39
|
+
parser.add_argument('--max_iter', type=int, default=1500, help='Maximum number of iterations for Adam EM')
|
|
40
|
+
parser.add_argument('--check', type=int, default=5, help='Frequency of log-likelihood checks')
|
|
41
|
+
|
|
42
|
+
parser.add_argument('--max_als', type=int, default=1000, help='Maximum number of iterations for ALS')
|
|
43
|
+
parser.add_argument('--tole_als', type=float, default=1e-4, help='Convergence tolerance for ALS')
|
|
44
|
+
parser.add_argument('--reg_als', type=float, default=1e-5, help='Regularization parameter for ALS')
|
|
45
|
+
parser.add_argument('--power', type=int, default=5, help='Number of power iterations for RSVD')
|
|
46
|
+
parser.add_argument('--tole_svd', type=float, default=1e-1, help='Convergence tolerance for SVD')
|
|
47
|
+
|
|
48
|
+
return parser.parse_args(argv)
|
|
49
|
+
|
|
50
|
+
def print_adamixture_banner(version: str="1.0") -> None:
|
|
51
|
+
"""
|
|
52
|
+
Display the Neural Admixture banner with version and author information.
|
|
53
|
+
"""
|
|
54
|
+
banner = r"""
|
|
55
|
+
___ ____ ___ __ __ _____ _______ _ _ _____ ______
|
|
56
|
+
/ _ \| _ \ / _ \| \/ |_ _\ \ / /__ __| | | | __ \| ____|
|
|
57
|
+
/ /_\ | | | / /_\ | \ / | | | \ V / | | | | | | |__) | |__
|
|
58
|
+
| _ | | | | _ | |\/| | | | > < | | | | | | _ /| __|
|
|
59
|
+
| | | | |_| | | | | | | |_| |_ / . \ | | | |__| | | \ \| |____
|
|
60
|
+
\_| |_/____/\_| |_|_| |_|_____/_/ \_\ |_| \____/|_| \_\______|
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
info = f"""
|
|
64
|
+
Version: {version}
|
|
65
|
+
Authors: Joan Saurina Ricós, Daniel Mas Montserrat and
|
|
66
|
+
Alexander G. Ioannidis.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
log.info("\n" + banner + info)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main():
|
|
73
|
+
print_adamixture_banner(__version__)
|
|
74
|
+
arg_list = tuple(sys.argv)
|
|
75
|
+
args = parse_args(arg_list[1:])
|
|
76
|
+
|
|
77
|
+
# CONTROL TIME:
|
|
78
|
+
t0 = time.time()
|
|
79
|
+
|
|
80
|
+
#CONTROL OS:
|
|
81
|
+
system = platform.system()
|
|
82
|
+
if system == "Linux":
|
|
83
|
+
log.info(" Operating system is Linux!")
|
|
84
|
+
os.environ["CC"] = "gcc"
|
|
85
|
+
os.environ["CXX"] = "g++"
|
|
86
|
+
elif system == "Darwin":
|
|
87
|
+
log.info(" Operating system is Darwin (Mac OS)!")
|
|
88
|
+
os.environ["CC"] = "clang"
|
|
89
|
+
os.environ["CXX"] = "clang++"
|
|
90
|
+
elif system == "Windows":
|
|
91
|
+
log.info(" Operating system is Windows!")
|
|
92
|
+
pass
|
|
93
|
+
else:
|
|
94
|
+
log.info(f"System not recognized: {system}")
|
|
95
|
+
sys.exit(1)
|
|
96
|
+
|
|
97
|
+
# CONTROL SEED:
|
|
98
|
+
utils.set_seed(args.seed)
|
|
99
|
+
|
|
100
|
+
# CONTROL THREADS:
|
|
101
|
+
th = str(args.threads)
|
|
102
|
+
os.environ["MKL_NUM_THREADS"] = th
|
|
103
|
+
os.environ["MKL_MAX_THREADS"] = th
|
|
104
|
+
os.environ["OMP_NUM_THREADS"] = th
|
|
105
|
+
os.environ["OMP_MAX_THREADS"] = th
|
|
106
|
+
os.environ["NUMEXPR_NUM_THREADS"] = th
|
|
107
|
+
os.environ["NUMEXPR_MAX_THREADS"] = th
|
|
108
|
+
os.environ["OPENBLAS_NUM_THREADS"] = th
|
|
109
|
+
os.environ["OPENBLAS_MAX_THREADS"] = th
|
|
110
|
+
|
|
111
|
+
log.info(f" Using {th} threads...")
|
|
112
|
+
|
|
113
|
+
from .src import main
|
|
114
|
+
sys.exit(main.main(args, t0))
|
|
File without changes
|