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'scommonfactor_gwasmatches RGenomicSEM::userGWASon the equivalent single-factor model, but does not numerically match RGenomicSEM::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 settingGSEMR_COMMONFACTOR_GWAS_QUIET=1in 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
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2506a7f6ea64465b893bc59e9c0547237421032341fffceb016f82a69fa2db86
|
|
| MD5 |
9a474cbc75ccc0fff5499894683e3e01
|
|
| BLAKE2b-256 |
ecf9493d5f8a0f7efb807fc023c86fd28a7a01703e1f0d618a48e69ee0c7434f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e768e996a1536b01d78a949e6ccacc7ff06c9d891b05672381d1d8f057c9e562
|
|
| MD5 |
a3ed2e71f2a262023506745853c7aeb7
|
|
| BLAKE2b-256 |
f9c27b65dc7761599a889224287fc575716e98b9989092cc8b522a063faea491
|
File details
Details for the file genomicsem-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: genomicsem-0.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2140c67212ec1c73ab89d39bad3919432ac85b374d120ec68dba002c8090b744
|
|
| MD5 |
8f6a6bbaa14047ccf90cd6910437eebb
|
|
| BLAKE2b-256 |
581ed9e52d2c64c10deea99d203d0e434b882c76cae8ade35594b763a5962b57
|
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
- Download URL: genomicsem-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.12, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bcdbff18aa363556475652f326756d149b660d2667476162828cf99372bca41
|
|
| MD5 |
00d42fad4ff5f836dae20a33f53a05e5
|
|
| BLAKE2b-256 |
d101f480ed2a3c901902e67a7e9f4f9f809e1f879c9b9f4a9cff2d116223c5b1
|