Skip to main content

PYPE

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 pype-mr 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

pype_mr-1.0.1.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pype_mr-1.0.1-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file pype_mr-1.0.1.tar.gz.

File metadata

  • Download URL: pype_mr-1.0.1.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

Hashes for pype_mr-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3392f6a27afc2d7841b4a816efcf0f31b2000f8c9b797eb64d01b7ce0b7fe4d4
MD5 c798d7243e201378eeb99d73128a97d8
BLAKE2b-256 8bf7d0a6304cff6bf8a5a6a691481b7fbc5e6b0c0786cf26066b9c3864186063

See more details on using hashes here.

Provenance

The following attestation bundles were made for pype_mr-1.0.1.tar.gz:

Publisher: publish.yml on TaykhoomDalal/pype

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pype_mr-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pype_mr-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pype_mr-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df0ad409a43dc8dbd92fe30d31512eabda7a815ddade4a26b73c97976d3e86f4
MD5 0786eb818d7f03dcb1af4a64f1658d35
BLAKE2b-256 5872b84d10c935f3230ddaddbe8ec5a0fd4a781112af3aacbd0065bf980757c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pype_mr-1.0.1-py3-none-any.whl:

Publisher: publish.yml on TaykhoomDalal/pype

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page