Skip to main content

Rust-accelerated Genomic Structural Equation Modeling

Project description

genomicsem

Rust-accelerated GenomicSEM for Python. Multivariate LD Score Regression and Structural Equation Modeling on GWAS summary statistics.

Repository · Issue tracker · API compatibility notes · Architecture & performance

Install

pip install genomicsem

From source (requires Rust toolchain):

pip install maturin
cd bindings/python && maturin develop --release

Usage

import genomicsem as gsem

# LDSC
result = gsem.ldsc(
    traits=["trait1.sumstats.gz", "trait2.sumstats.gz"],
    sample_prev=[None, None],
    pop_prev=[None, None],
    ld="eur_w_ld_chr/",
)
result.s       # np.ndarray — genetic covariance matrix
result.v       # np.ndarray — sampling covariance matrix
result.i_mat   # np.ndarray — intercept matrix
result.n       # list — sample sizes
result.m_total # float — number of SNPs

# Every downstream function accepts the `result` object directly. You
# can also pass a plain dict with `s`, `v`, `i_mat`, `n_vec`, `m` fields,
# or a dict using the uppercase `S`, `V`, `I`, `N`, `m` keys that match
# the R GenomicSEM convention.

# Common factor model
cf = gsem.commonfactor(result)
# cf is a dict: {parameters: {lhs, op, rhs, est, se, z, p}, chisq, df, ...}

# User-specified SEM
um = gsem.usermodel(
    result,
    model="F1 =~ NA*V1 + V2\nF1 ~~ 1*F1\nV1 ~~ V1\nV2 ~~ V2",
    estimation="DWLS",
)

# Munge
gsem.munge(
    files=["gwas1.txt", "gwas2.txt"],
    hm3="w_hm3.snplist",
    trait_names=["T1", "T2"],
)

# Merge sumstats
gsem.sumstats(
    files=["T1.sumstats.gz", "T2.sumstats.gz"],
    ref_dir="eur_w_ld_chr/",
    trait_names=["V1", "V2"],
)

# GWAS — results come back as a columnar dict. Feed it straight into pandas:
#   import pandas as pd; df = pd.DataFrame({k: v for k, v in res.items() if k != "params"})
res = gsem.commonfactor_gwas(result, "merged_sumstats.tsv")
res = gsem.user_gwas(result, "merged_sumstats.tsv", model="F1 =~ NA*V1 + V2\nF1 ~ SNP")

# Parallel analysis
gsem.parallel_analysis(result.s, result.v, r=500)

# Auto-generate model syntax
gsem.write_model(loadings=[[0.7, 0.0], [0.6, 0.0], [0.0, 0.8]], names=["V1", "V2", "V3"])

# Genetic correlation
gsem.rgmodel(result, model="")

Functions

Every exported function has a worked example in its docstring — run help(gsem.ldsc), help(gsem.commonfactor), etc. to see them.

Core pipeline: munge, ldsc, sumstats, commonfactor, usermodel, user_gwas, commonfactor_gwas

Advanced: hdl, s_ldsc, enrich, parallel_analysis, write_model, rgmodel, multi_snp, multi_gene, sim_ldsc, summary_gls

Note on commonfactor_gwas: genomicsem's commonfactor_gwas matches R GenomicSEM::userGWAS on the equivalent single-factor model, but does not numerically match R GenomicSEM::commonfactorGWAS, which uses a different internal parameterization. See ARCHITECTURE.md §3.3 for the full rationale. A one-time warning is emitted on first use; suppress it by setting GSEMR_COMMONFACTOR_GWAS_QUIET=1 in the environment.

Citation

Grotzinger, A. D., Rhemtulla, M., de Vlaming, R., Ritchie, S. J., Mallard, T. T., Hill, W. D., Ip, H. F., Marioni, R. E., McIntosh, A. M., Deary, I. J., Koellinger, P. D., Harden, K. P., Nivard, M. G., & Tucker-Drob, E. M. (2019). Genomic structural equation modelling provides insights into the multivariate genetic architecture of complex traits. Nature human behaviour, 3(5), 513–525. https://doi.org/10.1038/s41562-019-0566-x

License

GPL-3.0

Project details


Download files

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

Source Distribution

genomicsem-0.1.1.tar.gz (160.8 kB view details)

Uploaded Source

Built Distributions

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

genomicsem-0.1.1-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

genomicsem-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

genomicsem-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file genomicsem-0.1.1.tar.gz.

File metadata

  • Download URL: genomicsem-0.1.1.tar.gz
  • Upload date:
  • Size: 160.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genomicsem-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2506a7f6ea64465b893bc59e9c0547237421032341fffceb016f82a69fa2db86
MD5 9a474cbc75ccc0fff5499894683e3e01
BLAKE2b-256 ecf9493d5f8a0f7efb807fc023c86fd28a7a01703e1f0d618a48e69ee0c7434f

See more details on using hashes here.

File details

Details for the file genomicsem-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: genomicsem-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genomicsem-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e768e996a1536b01d78a949e6ccacc7ff06c9d891b05672381d1d8f057c9e562
MD5 a3ed2e71f2a262023506745853c7aeb7
BLAKE2b-256 f9c27b65dc7761599a889224287fc575716e98b9989092cc8b522a063faea491

See more details on using hashes here.

File details

Details for the file genomicsem-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for genomicsem-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2140c67212ec1c73ab89d39bad3919432ac85b374d120ec68dba002c8090b744
MD5 8f6a6bbaa14047ccf90cd6910437eebb
BLAKE2b-256 581ed9e52d2c64c10deea99d203d0e434b882c76cae8ade35594b763a5962b57

See more details on using hashes here.

File details

Details for the file genomicsem-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genomicsem-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 3bcdbff18aa363556475652f326756d149b660d2667476162828cf99372bca41
MD5 00d42fad4ff5f836dae20a33f53a05e5
BLAKE2b-256 d101f480ed2a3c901902e67a7e9f4f9f809e1f879c9b9f4a9cff2d116223c5b1

See more details on using hashes here.

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