Skip to main content

High-performance Multi-method Mixed-Model Association for large-scale GWAS

Project description

CI PyPI Python 3.11+ NumPy Hypothesis License: GPL-3.0 Buy Me a Coffee

JAMMA

JAMMA (High-performance Multi-method Mixed-Model Association) — a modern Python and C reimplementation of GEMMA for large-scale GWAS.

  • GEMMA-compatible: Drop-in replacement with identical CLI flags and output formats
  • Numerical equivalence: Validated against GEMMA — 100% significance agreement, 100% effect direction agreement
  • Fast: Up to 17x faster than GEMMA 0.98.5
  • Memory-safe: Pre-flight memory checks prevent OOM crashes before allocation
  • Cross-platform: Runs on Linux, macOS, and Windows with NumPy and vendor BLAS
  • Optimized for Intel: Best performance on Intel CPUs with MKL BLAS. Runs well on Apple Silicon (Accelerate BLAS). Other architectures (AMD, ARM Linux) work correctly but with less BLAS optimization
  • Pure Python + C extensions (OpenMP SIMD): NumPy stack with vendor BLAS dispatch (MKL-ILP64, Accelerate-ILP64) via jlinalg C layer for eigendecomposition and OpenMP-parallel Wald tests
  • Large-scale ready: Optional numpy-mkl ILP64 wheels (numpy 2.4.2) for >46k sample eigendecomposition

Installation

macOS (Intel or ARM)

pip install jamma

That's it. macOS Accelerate BLAS handles large matrices natively.

Linux / Windows / Intel Mac

For small datasets (<46k samples), the standard install works:

pip install jamma

For large-scale GWAS (>46k samples) on x86_64 (Linux or Intel Mac), install numpy-mkl first — standard numpy uses 32-bit BLAS integers which overflow at ~46k samples. MKL is x86_64-only; Windows users are limited to <46k samples (ARM Mac uses Accelerate-ILP64 natively). Pre-built ILP64 wheels are available for Python 3.11–3.14:

pip install numpy \
  --extra-index-url https://michael-denyer.github.io/numpy-mkl \
  --force-reinstall --upgrade
pip install jamma --no-deps
pip install psutil loguru threadpoolctl click progressbar2 bed-reader

From Git (latest development version):

pip install numpy \
  --extra-index-url https://michael-denyer.github.io/numpy-mkl \
  --force-reinstall --upgrade
pip install git+https://github.com/michael-denyer/jamma.git --no-deps
pip install psutil loguru threadpoolctl click progressbar2 bed-reader

Why --no-deps? JAMMA depends on numpy>=2.0.0, so a normal pip install jamma will pull in standard numpy and overwrite the ILP64 build. --no-deps prevents this; you install the runtime dependencies manually instead.

See the User Guide for ILP64 verification steps.

Platform Support

Platform BLAS ILP64 Notes
Linux x86_64 (Intel) MKL (optimal) numpy-mkl Best performance
Linux x86_64 (AMD) OpenBLAS numpy-mkl Works well
ARM Mac (M1+) Accelerate native Excellent performance
ARM Linux OpenBLAS -- Works correctly
Intel Mac Accelerate / MKL numpy-mkl Full support
Windows OpenBLAS -- Limited to <46k samples

JAMMA's heavy computation (eigendecomposition, matrix multiplication, REML optimization) is BLAS-bound. Intel MKL delivers the best throughput, particularly at scale. Apple Accelerate is a close second on Apple Silicon. OpenBLAS works correctly everywhere but is less tuned for these workloads.

Quick Start

# Compute kinship matrix (centered relatedness)
jamma -gk 1 -bfile data/my_study -o output
# Output: output/output.cXX.npy (binary, fast)
# Add --legacy-text for GEMMA-compatible text format

# Run LMM association (Wald test)
jamma -lmm 1 -bfile data/my_study -k output/output.cXX.npy -o results

# Multiple phenotypes (eigendecomp computed once, reused)
jamma -lmm 1 -bfile data/my_study -k output/output.cXX.npy -n "1 2 3" -o results

Output files:

  • output.cXX.npy — Kinship matrix (binary NumPy format; .cXX.txt with --legacy-text)
  • results.assoc.txt — Association results (chr, rs, ps, n_miss, allele1, allele0, af, beta, se, logl_H1, l_remle, p_wald)
  • results.log.txt — Run log

The reader auto-detects format, so existing .cXX.txt files still work as -k input.

Python API

One-call GWAS (recommended)

The gwas() function is the recommended way to run JAMMA from Python. It handles the full pipeline — data loading, kinship computation, eigendecomposition, and LMM association — in a single call. You don't need to compute a kinship matrix separately unless you want to reuse it across runs.

from jamma import gwas

# Simplest usage: computes kinship internally, no separate kinship step needed
result = gwas("data/my_study")
print(f"Tested {result.n_snps_tested} SNPs in {result.timing['total_s']:.1f}s")

# Or supply a pre-computed kinship matrix to skip recomputation
result = gwas("data/my_study", kinship_file="data/kinship.cXX.npy")

# Compute kinship from scratch and save it for reuse
result = gwas("data/my_study", save_kinship=True, output_dir="output")

# With covariates and LRT test
result = gwas("data/my_study", kinship_file="k.txt", covariate_file="covars.txt", lmm_mode=2)

# LOCO analysis (leave-one-chromosome-out)
result = gwas("data/my_study", loco=True)

# LOCO with eigen caching (skip eigendecomp on subsequent runs)
result = gwas("data/my_study", loco=True, write_eigen=True)
# Reuse cached eigen files from a previous run
result = gwas("data/my_study", loco=True,
              eigenvalue_file="output/result.eigenD.npy",
              eigenvector_file="output/result.eigenU.npy")

# Multi-phenotype with eigendecomp reuse (Python API)
result = gwas("data/my_study", write_eigen=True, phenotype_column=1)
result = gwas("data/my_study", eigenvalue_file="output/result.eigenD.npy",
              eigenvector_file="output/result.eigenU.npy", phenotype_column=2)
# Or use the CLI for automatic multi-phenotype: jamma -lmm 1 ... -n "1 2 3"

# SNP filtering
result = gwas("data/my_study", kinship_file="k.txt", snps_file="snps.txt", hwe=0.001)

Low-level API

import numpy as np

from jamma.io import load_plink_binary
from jamma.kinship import compute_centered_kinship
from jamma.lmm import run_lmm_association_numpy
from jamma.lmm.eigen import eigendecompose_kinship

data = load_plink_binary("data/my_study")
phenotypes = np.loadtxt("data/my_study.pheno")
kinship = compute_centered_kinship(data.genotypes)
eigenvalues, eigenvectors = eigendecompose_kinship(kinship)

snp_info = [
    {"chr": str(data.chromosome[i]), "rs": data.sid[i],
     "pos": int(data.bp_position[i]), "a1": data.allele_1[i], "a0": data.allele_2[i]}
    for i in range(data.n_snps)
]

# Returns LmmRunResult — .associations for list[AssocResult], .pve for heritability, .pve_se for SE
run_result = run_lmm_association_numpy(
    genotypes=data.genotypes,
    phenotypes=phenotypes,
    kinship=None,  # Not needed when eigenvalues/eigenvectors provided
    snp_info=snp_info,
    eigenvalues=eigenvalues,
    eigenvectors=eigenvectors,
    lmm_mode=1,
)
results = run_result.associations

Memory Safety

Unlike GEMMA, JAMMA includes pre-flight memory checks that prevent out-of-memory crashes:

from jamma.core.memory import estimate_workflow_memory

# Check memory requirements BEFORE loading data
estimate = estimate_workflow_memory(n_samples=125_000, n_snps=95_000)
print(f"Peak memory: {estimate.total_gb:.1f}GB")
print(f"Available: {estimate.available_gb:.1f}GB")
print(f"Sufficient: {estimate.sufficient}")

Key features:

  • Pre-flight checks before large allocations (eigendecomposition, genotype loading)
  • RSS memory logging at workflow boundaries
  • Incremental result writing (no memory accumulation)
  • Safe chunk size defaults with hard caps

GEMMA will silently OOM and get killed by the OS. JAMMA fails fast with clear error messages.

Performance

Benchmark on mouse_hs1940 (1,940 samples × 12,226 SNPs), Apple M2, GEMMA 0.98.5. Best-of runs, end-to-end wall clock:

Operation GEMMA (OpenBLAS) GEMMA (Accelerate) JAMMA NumPy JAMMA NumPy+C JAMMA NumPy+C (stream) C speedup vs GEMMA (OB) vs GEMMA (Accel)
Kinship (-gk 1) 2.1s 1.7s 262ms 262ms 1.0x 8.0x 6.5x
LMM Wald (-lmm 1) 11.0s 7.6s 4.1s 879ms 1.1s 4.7x 12.5x 8.7x
LMM All (-lmm 4) 20.5s 13.9s 6.0s 1.3s 1.4s 4.7x 16.0x 10.9x
LMM Wald+4cov (-lmm 1 -c) 40.8s 18.8s 9.1s 2.4s 2.6s 3.8x 17.0x 7.8x

GEMMA (Accelerate) is GEMMA 0.98.5 compiled against Apple's Accelerate framework instead of Homebrew OpenBLAS — 1.3-2.2x faster due to AMX-accelerated BLAS, with identical numerical results. NumPy+C uses a C extension with OpenMP for Wald (-lmm 1) — REML optimization is compute-bound and parallelizes well across SNPs. The C speedup grows with covariates because the Pab table recursion is more expensive. NumPy+C is the fastest backend at all modes including all-tests (-lmm 4) at mouse scale. NumPy+C (stream) reads genotypes from disk in chunks — slightly slower than batch but the production code path for large datasets that don't fit in memory. Kinship is always pure NumPy/BLAS.

LOCO (Leave-One-Chromosome-Out)

Backend LOCO Wald vs GEMMA
GEMMA 0.98.5 3m31s 1.0x
JAMMA NumPy+C 7.3s 28.8x

The large speedup has two sources: (1) JAMMA computes per-chromosome LOCO kinship via streaming and tests only that chromosome's SNPs, while GEMMA -loco tests all SNPs against each LOCO kinship (19x redundant work on 19 chromosomes); (2) JAMMA runs all chromosomes in a single process, avoiding 19 cold-start overheads.

Supported Features

Current

  • Kinship matrix computation — centered (-gk 1) and standardized (-gk 2)
  • Univariate LMM Wald test (-lmm 1)
  • Likelihood ratio test (-lmm 2)
  • Score test (-lmm 3)
  • All tests mode (-lmm 4)
  • LOCO kinship — leave-one-chromosome-out analysis (-loco)
  • Binary .npy I/O — default for kinship and eigen files; --legacy-text for GEMMA text format
  • Multi-phenotype support — -n "1 2 3" with single eigendecomposition reuse
  • Eigendecomposition reuse — manual via -d/-u/-eigen, automatic in multi-phenotype mode
  • LOCO eigen caching — --eigen-dir saves/loads per-chromosome eigen files across runs
  • Phenotype column selection (-n)
  • SNP subset selection for association and kinship (-snps/-ksnps)
  • HWE QC filtering (-hwe)
  • Pre-computed kinship input (-k)
  • Covariate support (-c)
  • PLINK binary format (.bed/.bim/.fam) with input dimension validation
  • Large-scale streaming I/O (>100k samples via numpy-mkl ILP64 — numpy 2.4.2)
  • Lambda optimization bounds (-lmin/-lmax)
  • Individual weights for kinship (-widv)
  • Categorical covariates with one-hot encoding (-cat)
  • Pre-flight memory checks (fail-fast before OOM)
  • RSS memory logging at workflow boundaries
  • Incremental result writing
  • In-place mean imputation for missing genotypes (per-chunk, zero-copy)
  • Early sample filtering — kinship accumulated at filtered size when phenotype missingness is present
  • jlinalg C layer: vendor BLAS dispatch for eigendecomposition (DSYEVD default, DSYEVR O(n) workspace fallback under memory pressure), DSYRK, DGEMM
  • Optional C extension: OpenMP-parallel Wald tests (auto-fallback to pure Python)

Planned

  • Multivariate LMM (mvLMM)

Architecture

JAMMA uses NumPy for data loading and kinship. Eigendecomposition uses jlinalg.eigh which dispatches to vendor DSYEVD (default) or DSYEVR (O(n) workspace, under memory pressure) via the jlinalg C layer. LMM association uses a NumPy backend with an optional C extension for OpenMP-parallel Wald/Score/LRT tests. Mode is auto-selected based on available memory: batch runner when genotypes fit in RAM, streaming runner (two-pass disk I/O) for large datasets.

flowchart TD
    CLI["CLI / gwas()"] --> PIPE["PipelineRunner"]
    PIPE --> LOAD["Load PLINK + Phenotypes<br>(NumPy)"]
    LOAD --> KIN["Kinship<br>(NumPy matmul)"]
    KIN --> EIG["Eigendecomposition<br>(jlinalg.eigh - vendor DSYEVD/DSYEVR)"]
    EIG --> MEM{"memory?"}
    MEM -->|"fits"| NP["NumPy Batch Runner"]
    MEM -->|"large"| NPS["NumPy Streaming Runner<br>two-pass disk streaming"]
    NP --> CEXT{"C extension?"}
    NPS --> CEXT
    CEXT -->|yes| C["C Extension<br>OpenMP + SIMD"]
    CEXT -->|no| PY["Pure Python<br>fallback"]
    C --> RES["AssocResult"]
    PY --> RES

Core algorithms (likelihood.py, prepare_common.py) are shared between batch and streaming runners.

jlinalg: Controlled C Compute Layer

JAMMA includes jlinalg, a controlled C compute layer that dispatches to vendor BLAS/LAPACK (MKL-ILP64, Accelerate-ILP64) when available, with NumPy fallback when no vendor library is available. This eliminates numpy BLAS compatibility issues (LP64 integer overflow at >46k samples, scipy ILP64 incompatibility).

graph TD
    A["jamma CLI / Python API"] --> B["LMM Pipeline"]
    B --> C["jlinalg Python API"]
    C --> D{"C Extension"}
    D -->|Loaded| E["Vendor Dispatch<br/>MKL-ILP64 / Accelerate-ILP64"]
    D -->|Not loaded| G["NumPy Fallback"]
    B --> H["_lmm_accel.c<br/>Wald/Score/LRT"]

jlinalg provides vendor LAPACK dispatch (DSYEVD/DSYEVR) for eigendecomposition and symmetric BLAS specialization (dsyrk). See the jlinalg Architecture doc for layer diagrams and the contributing guide.

See Code Map for the full architecture diagram with source links.

Documentation

Requirements

  • Python 3.11+
  • NumPy 2.0+

License

GPL-3.0 (same as GEMMA)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jamma-5.1.0.tar.gz (83.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jamma-5.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (669.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

jamma-5.1.0-cp313-cp313-macosx_14_0_arm64.whl (465.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

jamma-5.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (669.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

jamma-5.1.0-cp312-cp312-macosx_14_0_arm64.whl (465.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

jamma-5.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

jamma-5.1.0-cp311-cp311-macosx_14_0_arm64.whl (466.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file jamma-5.1.0.tar.gz.

File metadata

  • Download URL: jamma-5.1.0.tar.gz
  • Upload date:
  • Size: 83.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jamma-5.1.0.tar.gz
Algorithm Hash digest
SHA256 bcf8f0710ee9a2ab24124107ac11ced1b1db97ff9866e70e8f5a932630582d58
MD5 641a0a90e125d0dd182cd929bcb9168d
BLAKE2b-256 afab6966b0aba2d85463bc281baa8f3a8737d3f1e6ee0c0a3446521b77916927

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0.tar.gz:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26a932a4529e3f37da42ce9151cb11d1848c4f72ba18ab2cf4d3512cbb6e5561
MD5 1ddea9f3e45ccd6fb5894cd53ec2bf50
BLAKE2b-256 5f65288007dc5094919773a56e1c86390e40c0ce0578adb772a71ecd5539f1ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5f7ca4f6b57fd24eac65139a1b9dc1b31cec641851a9e92453147735c6c526fa
MD5 78d2dc4997ba1472bdc41d5ed7d7e6ca
BLAKE2b-256 c0aee74cfb5a2d316d03c5283244b1f3e256e075b4b9ada53f08099d82f1a56d

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1c3c657a12812c348f9db1f7da1c1849d0a17c2ec5ad2e97e7b4add979eea91f
MD5 03ad8222f3927afb10c57d427b768658
BLAKE2b-256 4e8d84669148b100649a4058d6c14c17bc47f270892a14c442ec2be4b6e04310

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5888a2ee8cf33199207be4030f6bbd7a9e5ccf6725e27694aa2c217895641782
MD5 c86da0bd90e23274c37df57aca2e59ec
BLAKE2b-256 6b05d945ccc49ffc608571849880b06052efd0b91abbaefcf4e4f813f3f86ce1

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c8630aace4033939e8495eda81f31113d3f06d3f66f84dfdb6363bacdf611c8
MD5 3301ce2dd2f9e4adfa65456f6d3f21af
BLAKE2b-256 ec42c32e45ff1c9375ed9151044e3648c8f455cdf59409afd4a9bcbf6e0151bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jamma-5.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for jamma-5.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d06fbb66483fdce4abde53ab3e06c778acee2f540894218e69e1f4810f37acf9
MD5 dfe2047edf027e6300ce03a6e6548f7e
BLAKE2b-256 4fd7602b4d8c25653e6262de4622c924e2559bb641dcbdcd7fb39081f4f40fce

See more details on using hashes here.

Provenance

The following attestation bundles were made for jamma-5.1.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: build-wheels.yml on michael-denyer/jamma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page