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.2.0.tar.gz (184.1 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.2.0-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

genomicsem-0.2.0-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.2.0.tar.gz.

File metadata

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

File hashes

Hashes for genomicsem-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1fb7d0e91a0387f45f40f4be644a6ce3b56158c9f7e0222a1b75bd03cc664d4a
MD5 02f7368f9e60190ca71ce80a57bf20af
BLAKE2b-256 6d22ce1acaea6a77346c9a8580d92bb0def732eb6d362304003eec95a656d7d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: genomicsem-0.2.0-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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5fb2d9e1e35eb7d57b42240c153cb90eba64203bd244e83668e5c9a35b1bef6b
MD5 3fef4ce4f510970107cfe922780e7036
BLAKE2b-256 c1cbbfb137956bff76fd2d001053862b31876c71fcdc03c75a06038c632e953a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genomicsem-0.2.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 59601603be7d81741c4beb8344e0c0ac2987b56d86c40e60ba78d1c0e9d70a00
MD5 c094aca3f990968f296c1acb25fe7fee
BLAKE2b-256 39949c7209dea194e3dfa42a0edd0610da088b17bc9055dfcf7802d08f457d26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genomicsem-0.2.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 4fe0960f25401a184eae776eccdf2dc482312f00247128e2d465b2fec044bb9c
MD5 24d8f70ee15d6508397a01e224ac70a8
BLAKE2b-256 550300c652453f844b977f18e9a3be0d32c24b06cd11fa6c4385defd6498bfec

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