Metadata-Version: 2.4
Name: pymr-genetics
Version: 0.1.0
Summary: Modern Python package for Mendelian Randomization analysis
Project-URL: Homepage, https://github.com/maxghenis/pymr
Project-URL: Documentation, https://maxghenis.github.io/pymr
Project-URL: Repository, https://github.com/maxghenis/pymr
Author-email: Max Ghenis <max@policyengine.org>
License-Expression: MIT
License-File: LICENSE
Keywords: causal-inference,epidemiology,genetics,gwas,mendelian-randomization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.9
Requires-Dist: matplotlib>=3.5
Requires-Dist: numpy>=1.20
Requires-Dist: pandas>=1.3
Requires-Dist: requests>=2.28
Requires-Dist: scipy>=1.7
Requires-Dist: seaborn>=0.12
Requires-Dist: statsmodels>=0.13
Provides-Extra: dev
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pre-commit>=3.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest-xdist>=3.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1; extra == 'dev'
Provides-Extra: docs
Requires-Dist: jupyter-book>=1.0; extra == 'docs'
Requires-Dist: myst-nb>=1.0; extra == 'docs'
Requires-Dist: sphinx-autodoc2>=0.5; extra == 'docs'
Description-Content-Type: text/markdown

# PyMR: Mendelian Randomization in Python

[![Tests](https://github.com/maxghenis/pymr/actions/workflows/test.yml/badge.svg)](https://github.com/maxghenis/pymr/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/maxghenis/pymr/branch/main/graph/badge.svg)](https://codecov.io/gh/maxghenis/pymr)
[![PyPI](https://img.shields.io/pypi/v/pymr.svg)](https://pypi.org/project/pymr/)
[![Documentation](https://img.shields.io/badge/docs-jupyter--book-blue)](https://maxghenis.github.io/pymr)

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

```bash
pip install pymr
```

## Quick Start

### Frequentist MR

```python
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

```python
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](docs/bayesian_mr.md) for comprehensive Bayesian MR documentation.

## Development

```bash
# 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:

```bibtex
@software{pymr2025,
  author = {Ghenis, Max},
  title = {PyMR: Mendelian Randomization in Python},
  year = {2025},
  url = {https://github.com/maxghenis/pymr}
}
```

## License

MIT License - see [LICENSE](LICENSE) for details.
