Metadata-Version: 2.4
Name: missense-pfes
Version: 0.2.0
Summary: Protein Feature Enrichment Score (PFES) for missense variant interpretation
Author-email: Seulki Kwon <skwon@broadinstitute.org>, Sumaiya Iqbal <sumaiya@broadinstitute.org>
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: requests
Requires-Dist: tqdm
Requires-Dist: g2papi

# Protein Feature Enrichment Score (PFES)

[![PyPI version](https://img.shields.io/pypi/v/missense-pfes)](https://pypi.org/project/missense-pfes/)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/broadinstitute/missense-pfes/blob/main/notebooks/G2P_PFES.ipynb)

Protein Feature Enrichment Score (PFES) is an interpretable framework for missense variant interpretation. Rather than outputting a single pathogenicity probability, PFES quantifies the degree to which a variant's protein characteristics statistically resemble known pathogenic or benign variation, and decomposes that signal into six feature attribute categories: physicochemical properties, 3D structure, domain/region annotations, functional sites, post-translational modifications, and protein-protein interactions.

This repository contains the data, analysis notebooks, and source code accompanying the manuscript: [*BioRxiv*](https://www.biorxiv.org/content/10.64898/2026.05.26.726248v1)

---

## Repository Structure

```
missense-pfes/
├── data/                        # Pre-preprocessed protein feature annotations for case/control datasets
├── notebooks/                   # Analysis notebooks reproducing key figures and results, and live PFES computation (Colab)
├── results/                     # Output files - precomputed enrichment odds ratios and p-values, scored case and control datasets from batch pfes scorer, example output folder from PFES Colab
├── src/pfes/                    # PFES batch scorer (installable as a CLI tool)
└── glossary_protein_feature.md  # Definitions of all 103 protein features used for PFES computation
```

---
## Quick Start: Query a variant(s)

The easiest way to use PFES is through our **Google Colab notebook**, which requires no local installation: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/broadinstitute/missense-pfes/blob/main/notebooks/G2P_PFES.ipynb)

The notebook returns two outputs for any queried variant(s):


1. **PFES report** — overall PFES, PFES partitioning category with statistical significance, and a breakdown of contributions across six attribute categories with plain-language interpretation of each enriched feature

1. **Protein-wide mutational landscape** — a heatmap of PFES across all possible amino acid substitutions in the queried protein, decomposed by attribute category, showing where the variant of interest sits within the full substitution space


## PFES Batch Scorer
[![PyPI version](https://img.shields.io/pypi/v/missense-pfes)](https://pypi.org/project/missense-pfes/)

`pfes` scores a batch of missense variants from a TSV/CSV input file. For every variant it returns the raw PFES (overall and per attribute), the scaled PFES (sPFES), the partition (PF-Enriched / PF-Neutral / PF-Depleted) and the one-sided empirical p-values. Protein features are fetched at run time via the `g2papi` package; the PFES model (enrichment odds ratios, reference score distributions and partition thresholds) is shipped with the package, so every release gives reproducible scores.

### Installation
```
pip install missense-pfes
```

Or install from source: 
```bash
git clone https://github.com/broadinstitute/missense-pfes.git
cd missense-pfes
pip install .
```

### Input format

The input file should be a TSV or CSV with the following columns:

| Column | Description |
|--------|-------------|
| `Gene` | HGNC gene symbol |
| `UniProt` | UniProt accession |
| `ResID` | Residue position |
| `RefAA` | Reference amino acid (single-letter) |
| `AltAA` | Alternate amino acid (single-letter) |

### Usage

```bash
usage: pfes [-h] -i INPUT -o OUTPUT [--rerun] [--log LOG] [--workers WORKERS] [--no-pvalues] [--model-dir MODEL_DIR] [--version]

options:
  -i INPUT, --input INPUT
                        Input TSV or CSV (columns: Gene, UniProt, ResID, RefAA, AltAA).
                        When --rerun is set, use the previous output file.
  -o OUTPUT, --output OUTPUT
                        Output TSV or CSV path (format inferred from extension).
  --rerun               Only process rows where PFES is NaN (fill missing scores).
  --log LOG             Path for error log (default: pfes_errors.log).
  --workers WORKERS     Number of parallel workers (default: 1).
  --no-pvalues          Leave out the p-value columns.
  --model-dir MODEL_DIR PFES model bundle to use instead of the one shipped with the package.
  --version             Show the package version.
```

```bash
# Basic usage
pfes -i variants.tsv -o scored_variants.tsv

# Parallel processing
pfes -i variants.tsv -o scored_variants.tsv --workers 4
```

### Output

The output keeps the input columns and adds, for each score column `<col>` in `PFES`, `PFES_Physicochemical`, `PFES_Structure`, `PFES_Domain`, `PFES_Function`, `PFES_Modification` and `PFES_PPI`:

| Column | Description |
|--------|-------------|
| `<col>` | Raw score: sum of the log odds ratios of the variant's significant protein features |
| `s<col>` | Scaled PFES, bounded in (−1, 1): tanh(score / T₊) for scores ≥ 0, tanh(score / \|T₋\|) for scores < 0; the thresholds map to ±0.762 |
| `<col>_partition` | PF-Enriched (score ≥ T₊), PF-Depleted (score ≤ T₋) or PF-Neutral |
| `<col>_p_case` | One-sided empirical p-value against pathogenic variants: (#pathogenic ≤ score + 1) / (n + 1) |
| `<col>_p_control` | One-sided empirical p-value against control variants: (#control ≥ score + 1) / (n + 1) |

T₊ is the lowest observed score reached or exceeded by fewer than 5% of control variants, and T₋ the highest observed score reached or undercut by fewer than 5% of pathogenic variants. `PFES_model` records the package version and model release used (e.g. `0.2.0/2026.09`).

### Handling failures and missing scores

Scoring requires fetching protein feature data from `g2papi` at runtime. Individual proteins or variants may fail due to missing data or network issues, in which case their PFES columns are left as `NaN` in the output. Details of each failure — including the gene, UniProt accession, residue, and error message — are written to a log file (`pfes_errors.log` by default).

To retry only the failed variants without re-running the entire dataset, pass the previous output file as input with `--rerun`:

```bash
# Fill in missing scores from a previous run
pfes -i scored_variants.tsv -o scored_variants.tsv --rerun
```

This fills in any rows where `PFES` is `NaN` and leaves successfully scored rows untouched.

## Data
Preprocessed protein feature annotations for the pathogenic (case) and control (benign + common population) variant datasets used in the paper. See `glossary_protein_feature.md` for definitions and sources of all 103 protein features.


| File | Description |
|------|-------------|
| `data/case_annotation.tsv` | Protein feature annotations for 39,695 pathogenic variants |
| `data/control_annotation.tsv` | Protein feature annotations for 130,832 control variants |


## Notebooks

| Notebook | Description |
|----------|-------------|
| `notebooks/compute_enrichment.ipynb` | Runs Fisher's exact test enrichment analysis within each PANTHER protein functional class and visualizes odds ratios. Generates `results/enrichment_OR_by_protein_class.csv`. |
| `notebooks/compute_partitioning_threshold.ipynb` | Computes empirical PFES distributions and derives partitioning thresholds (PF-Enriched/Neutral/Depleted) from the scored case and control datasets. |
| `notebooks/G2P_PFES.ipynb` |  Colab notebook for querying PFES scores and reports for individual variants of a gene of interest. <a href="https://colab.research.google.com/github/broadinstitute/missense-pfes/blob/main/notebooks/G2P_PFES_colab.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |

## Results

| File | Description |
|------|-------------|
| `results/case_pfes.tsv` | The scored (overall and per attribute) pathogenic variants, generated by the PFES batch scorer |
| `results/control_pfes.tsv` | The scored (overall and per attribute) control variants, generated by the PFES batch scorer |
| `results/pfes_pvalue_lookup.tsv` | Empirical p-value lookup table for variant partitioning, generated by `PFES_empirical_stats.ipynb`|
| `results/enrichment_OR_by_protein_class.csv` | Odds ratios from Fisher's exact tests for all 103 protein features across 20 PANTHER protein functional classes, generated by `notebooks/compute_enrichment.ipynb`. Regenerated for v0.1.2 with the feature definitions shared with the scorer (lower-edge-inclusive bins; SS9 `-` excluded; see `glossary_protein_feature.md`) |


## Citation

If you use PFES in your work, please cite:

> Human Proteome-wide Mechanistic Interpretation of Missense Mutations through Protein Feature Enrichment Score *[BioRxiv DOI later]*

## Contact
Seulki Kwon — skwon@broadinstitute.org  
Broad Institute of MIT and Harvard
