Skip to main content

PyPheRS (Phenome Risk Score)

A high-performance Python package and CLI tool for calculating Phenome Risk Scores (PheRS) for clinical and genomic cohorts.

PyPheRS calculates an individual's aggregate risk as a linear combination of effect sizes (betas) derived from Phenome-Wide Association Studies (PheWAS):

$$\text{PheRS}i = \sum{j \in \mathcal{P}i} \beta_j \cdot X{ij}$$

where:

  • $\beta_j$ is the PheWAS effect size (beta / log-odds ratio) for phecode $j$.
  • $X_{ij}$ is individual $i$'s phenotype feature value for phecode $j$ (binary presence, raw count, or log-transformed count).
  • Participants in the cohort who have no recorded matching phecodes receive a score of 0.0.

Installation

Install from PyPI:

pip install pyphers

Development Installation

To contribute or run tests locally from source:

git clone https://github.com/j-t-baker/pyphers.git
cd pyphers
uv sync --group dev

Usage

1. Command-Line Interface (CLI)

Run pyphers --help to view all available options:

pyphers --help

Basic Example

Calculate binary PheRS scores from phenotypes and weights:

pyphers \
  --phenotypes data/phenotypes.txt \
  --weights data/weights.txt \
  --output results/phers_scores.txt

Advanced Options

pyphers \
  --phenotypes data/phenotypes.csv \
  --weights data/weights.txt.gz \
  --cohort data/cohort_ids.txt \
  --mode count \
  --p-val-threshold 0.05 \
  --output results/phers_scores.txt

CLI Options

  • Input & Output:
    • -p, --phenotypes: Path to participant phenotype records.
    • -w, --weights: Path to PheWAS summary statistics file.
    • -o, --output: Path to write calculated PheRS scores.
    • -c, --cohort: Optional path to list of all cohort participant IDs to ensure completeness.
  • Scoring Options:
    • -m, --mode: Weighting scheme: binary (default), count, or log_count.
    • --p-val-threshold: Exclude weights with p-values exceeding this threshold.
  • Column Mapping:
    • --id-col: Participant ID column name (default: person_id).
    • --phecode-col: Phecode column name in phenotypes (default: phecode).
    • --weights-phecode-col: Phecode column name in weights (defaults to --phecode-col).
    • --beta-col: Effect size column name in weights (default: beta).
    • --pval-col: P-value column name in weights (default: p_val).
    • --count-col: Optional column name for pre-aggregated counts in phenotypes.

2. Python API

You can import calculate_phers directly into your Python scripts:

import polars as pl
from pyphers import calculate_phers

# Calculate PheRS directly from file paths or Polars DataFrames/LazyFrames
df_scores = calculate_phers(
    phenotypes="data/phenotypes.txt",
    weights="data/weights.txt",
    cohort="data/cohort.txt",  # or list of IDs: ["P1", "P2", "P3"]
    mode="binary",             # "binary" | "count" | "log_count"
    p_val_threshold=0.05,
    id_col="person_id",
    phecode_col="phecode",
    beta_col="beta",
    pval_col="p_val",
)

# Output is a Polars DataFrame with columns: ['person_id', 'phers']
print(df_scores)

Testing

Run unit and integration tests with pytest:

uv run pytest

Run tests across multiple Python versions (3.10–3.15) with nox:

uv run nox

Metadata

Release files for pyphers 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyphers 0.1.0
File Size Uploaded Provenance Actions
pyphers-0.1.0.tar.gz 6.1 kB Without provenance Details for pyphers-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyphers 0.1.0
File Interpreter ABI Platform Actions
pyphers-0.1.0-py3-none-any.whl Python 3 none any Details for pyphers-0.1.0-py3-none-any.whl

Total release size: 13.9 kB

Release files / pyphers-0.1.0.tar.gz

Download URL pyphers-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c33f3ee36c8864aa06c18b459b47427a089aef4c99a2173e88b93fc2570b4817
BLAKE2b-256 checksum
How to use checksums
c81d662d103a12a14c1a11d802685fb9a8f9e195feaadfddb41a098cb32ba7fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.6

Release files / pyphers-0.1.0-py3-none-any.whl

Download URL pyphers-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4cc7782c8bb7137a3f22ebdaa24b4c10ca01eb905f66abe6a47af108929b258a
BLAKE2b-256 checksum
How to use checksums
34ea845f1a242fc06f9c6f5a9acbb6c2f13a9f441d132063555144816cab4400
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.6

Security for pyphers 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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