PYPE

Install and run PYPE

Install PYPE

Install PYPE from PyPI:

python -m pip install pype-mr

For an editable checkout with tests:

git clone https://github.com/TaykhoomDalal/pype.git
cd pype
python -m pip install -e ".[test]"

Functional variant and gene summaries use optional BioThings clients:

python -m pip install "pype-mr[annotations]"

Choose a workflow

PheWAS

Use aligned phenotype and predictor dataframes when you want to test many outcomes.

Plot existing results

Start with a PheWAS result dataframe, add categories, and call the plotting functions.

Mendelian randomization

Use exposure and outcome summary-statistic dataframes with matching variants.

First PheWAS

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,
)

PYPE returns one row per predictor-outcome regression. See PheWAS results for the output columns.

Add metadata and plot

from pype.plotting import manhattan

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", annotate=True, seed=0)

First MR analysis

exposure = pd.read_csv("exposure.tsv", sep="\t")
outcome = pd.read_csv("outcome.tsv", sep="\t")

mr_results, diagnostics = pype.mendelian_randomization(
    exposure,
    outcome,
    exposure_name="exposure_trait",
    outcome_name="outcome_trait",
    methods=("ivw", "egger", "weighted_median"),
    seed=0,
)

Start with IVW as the main estimate, then compare estimators with different assumptions. The MR methods guide explains when each method is useful.

Before interpreting results

  • Confirm that phenotype and predictor rows use the same sample index.
  • Check complete-case sample counts in the PheWAS results.
  • Choose a multiple-testing correction before reviewing associations.
  • Confirm exposure and outcome GWAS use the same genome assembly.
  • Review harmonization warnings and the number of retained instruments.
  • Compare several MR estimators rather than treating one p-value as a causal conclusion.