PyMR: Mendelian Randomization in Python
A modern, test-driven Python package for Mendelian Randomization (MR) analysis.
Features
- Multiple MR methods: IVW, weighted median, MR-Egger, mode-based
- Bayesian MR: Full posterior inference, Bayes factors, model comparison
- Sensitivity analyses: Heterogeneity tests, MR-PRESSO, leave-one-out
- Data harmonization: Automatic allele alignment and strand flipping
- GWAS integration: Load from Pan-UKB, IEU OpenGWAS, or custom files
- Visualization: Forest plots, scatter plots, funnel plots, posterior distributions
- No external dependencies: Pure Python (no PLINK, PyMC, or Stan required)
Installation
pip install pymr
Quick Start
Frequentist MR
from pymr import MR, load_gwas
# Load GWAS summary statistics
exposure = load_gwas("bmi_gwas.tsv.gz")
outcome = load_gwas("diabetes_gwas.tsv.gz")
# Run MR analysis
mr = MR(exposure, outcome)
results = mr.run()
print(results)
# method beta se OR pval nsnp
# 0 IVW 0.924740 0.030497 2.521214 5.83e-202 192
# 1 Weighted Median 1.039266 0.021565 2.827140 0.00e+00 192
# 2 MR-Egger 0.911587 0.075401 2.488269 1.19e-33 192
Bayesian MR
from pymr import BayesianMR
# Run Bayesian MR with full posterior inference
bmr = BayesianMR(harmonized_data, prior_mean=0, prior_sd=1)
bmr.sample(n_samples=10000, n_chains=4, warmup=1000)
# Get posterior summary
summary = bmr.summary()
print(f"Effect: {summary['mean']:.3f} [{summary['ci_lower']:.3f}, {summary['ci_upper']:.3f}]")
print(f"Bayes Factor: {bmr.bayes_factor(null_value=0):.2f}")
# Visualize posterior
bmr.plot_posterior()
See docs/bayesian_mr.md for comprehensive Bayesian MR documentation.
Development
# Clone repository
git clone https://github.com/maxghenis/pymr.git
cd pymr
# Install in development mode
pip install -e ".[dev,docs]"
# Run tests
pytest
# Build documentation
jupyter-book build docs
Citation
If you use PyMR in your research, please cite:
@software{pymr2025,
author = {Ghenis, Max},
title = {PyMR: Mendelian Randomization in Python},
year = {2025},
url = {https://github.com/maxghenis/pymr}
}
License
MIT License - see LICENSE for details.
Metadata
Release files for pymr-genetics 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymr_genetics-0.1.0.tar.gz | 13.1 MB | Without provenance | Details for pymr_genetics-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymr_genetics-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pymr_genetics-0.1.0-py3-none-any.whl |
Total release size: 13.2 MB
Release files / pymr_genetics-0.1.0.tar.gz
| Download URL | pymr_genetics-0.1.0.tar.gz |
|---|---|
| Size | 13.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f15884e7276bab28c4f078b7fdaa670cdf250d9f3b5d8af6cc1aa8d0c0f6603
|
|
BLAKE2b-256 checksum How to use checksums |
635cd6667ad07e1c8725e03dec69fb6e95106dc14a4a1287015911fef2b302c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / pymr_genetics-0.1.0-py3-none-any.whl
| Download URL | pymr_genetics-0.1.0-py3-none-any.whl |
|---|---|
| Size | 41.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e942517d438ff6e03d0f38ae66f22c81e33dfb95ca9dfad70403e84dad02906
|
|
BLAKE2b-256 checksum How to use checksums |
da00269b1ec7605cc63be1692d2d9e5c56e4dce82d52c5c48d45dc4ed3714541
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for pymr-genetics 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.