Python pipeline for PheWAS and Mendelian randomization
PYPE runs phenome-wide association studies (PheWAS), creates PheWAS plots, and performs Mendelian randomization (MR) in Python.
User guide | Roadmap | Reference paper
Features
- PheWAS with genotype or phenotype predictors
- Covariate-adjusted linear regression
- Bonferroni, Sidak, and Benjamini-Hochberg correction
- Manhattan, volcano, and category enrichment plots
- Variant-to-gene mapping and optional BioThings annotations
- Eleven MR methods, including MR-Egger, weighted median, weighted mode, and MR-PRESSO
Installation
python -m pip install pype-mr
Optional annotation dependencies:
python -m pip install "pype-mr[annotations]"
Reproduce the paper
The public Mendelian randomization analyses can be rerun from a GitHub source checkout using the Le Goallec and Neale Lab summary statistics:
python -m pip install -e . openpyxl
python reproducibility/reproduce_paper.py
See reproducibility/README.md for the data boundary and expected outputs.
PheWAS
Pass one dataframe containing phenotypes and covariates, and another containing the predictors. Both dataframes must have the same sample index.
import pandas as pd
import pype
phenotypes = pd.DataFrame({
"trait_a": [1.2, 2.0, 1.5, 3.1],
"trait_b": [0.0, 1.0, 0.0, 1.0],
"age": [50, 61, 47, 70],
})
predictors = pd.DataFrame({
"variant_1": [0, 1, 1, 2],
})
results = pype.phenome_wide_association(
phenotypes,
predictors,
outcomes=["trait_a", "trait_b"],
covariates=["age"],
min_sample_count=3,
)
The result uses consistent snake_case columns: outcome, predictor, sample_count, total_sample_count, negative_log10_pvalue, pvalue, beta, and standard_error.
Plotting
Plots use the PheWAS result dataframe plus a small metadata table containing phenotype descriptions and categories.
import pandas as pd
import pype
from pype.plotting import category_enrichment, manhattan, volcano
metadata = pd.DataFrame({
"outcome": ["trait_a", "trait_b"],
"description": ["Trait A", "Trait B"],
"category": ["Measurements", "Diagnoses"],
})
results = pype.add_phenotype_metadata(results, metadata)
manhattan(results, "manhattan.png")
category_enrichment(results, "category_enrichment.png")
volcano(results, "volcano.png")
Mendelian randomization
Exposure and outcome dataframes must contain:
| Column | Description |
|---|---|
variant_id |
Variant identifier |
chromosome |
Chromosome |
effect_allele |
Effect allele |
other_allele |
Other allele |
beta |
Effect estimate |
standard_error |
Standard error |
pvalue |
P-value |
sample_size |
Sample size, optional |
import pandas as pd
import pype
exposure = pd.read_csv("exposure.tsv", sep="\t")
outcome = pd.read_csv("outcome.tsv", sep="\t")
results, diagnostics = pype.mendelian_randomization(
exposure,
outcome,
exposure_name="exposure_trait",
outcome_name="outcome_trait",
methods=("ivw", "egger", "weighted_median"),
seed=0,
)
Use methods="all" to run every available method. PYPE aligns effect alleles, flips reversed effects, and removes incompatible or ambiguous palindromic variants before analysis.
Available methods:
- Inverse variance weighted
- MR-Egger
- Simple, weighted, and penalized weighted median
- Simple, weighted, penalized, and NOME mode estimators
- MR-PRESSO
Data
Tests use synthetic data. Study data are supplied by users under the access terms of their data source.
License
Apache License 2.0. See LICENSE.md.
Citation
@article{Dalal2024PYPE,
title = {PYPE: A pipeline for phenome-wide association and Mendelian randomization in investigator-driven biobank scale analysis},
author = {Dalal, Taykhoom and Patel, Chirag J.},
journal = {Patterns},
year = {2024},
volume = {5},
number = {6},
pages = {100982},
doi = {10.1016/j.patter.2024.100982},
url = {https://doi.org/10.1016/j.patter.2024.100982}
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 pype_mr-1.0.0.tar.gz.
File metadata
- Download URL: pype_mr-1.0.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de622a89a760c8d1e88e0a3871f8ac616e8d92f7d5f1b004a40631496cd02118
|
|
| MD5 |
adfa2774a1a6ead9fa117f72e9abb131
|
|
| BLAKE2b-256 |
23c44f208549ed08f194bcdd250fa96083b84f2f8b87254a6af54fd03e3cc111
|
Provenance
The following attestation bundles were made for pype_mr-1.0.0.tar.gz:
Publisher:
publish.yml on TaykhoomDalal/pype
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pype_mr-1.0.0.tar.gz -
Subject digest:
de622a89a760c8d1e88e0a3871f8ac616e8d92f7d5f1b004a40631496cd02118 - Sigstore transparency entry: 2524871752
- Sigstore integration time:
-
Permalink:
TaykhoomDalal/pype@e593389a80f3e808a1143d3e85894183c03299e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TaykhoomDalal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e593389a80f3e808a1143d3e85894183c03299e5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pype_mr-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pype_mr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e757aa37147bf5eac39fc10c92d6fb2b8ee6706ff698153107d32138cf7ed8fd
|
|
| MD5 |
c5280dd29c243450fd6115dc94bfb276
|
|
| BLAKE2b-256 |
db5fc7342d515cd72f8fbfa464900db44ac84e79d62da6f26312d4eaff7b50eb
|
Provenance
The following attestation bundles were made for pype_mr-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on TaykhoomDalal/pype
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pype_mr-1.0.0-py3-none-any.whl -
Subject digest:
e757aa37147bf5eac39fc10c92d6fb2b8ee6706ff698153107d32138cf7ed8fd - Sigstore transparency entry: 2524871983
- Sigstore integration time:
-
Permalink:
TaykhoomDalal/pype@e593389a80f3e808a1143d3e85894183c03299e5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TaykhoomDalal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e593389a80f3e808a1143d3e85894183c03299e5 -
Trigger Event:
workflow_dispatch
-
Statement type: