11# MHC-TP
22
3- Cluster immunopeptidomics peptides by their HLA/MHC binding motif and get a
4- ranked table plus a standalone interactive HTML report.
3+ [ ![ PyPI] ( https://img.shields.io/pypi/v/mhc-tp.svg )] ( https://pypi.org/project/mhc-tp/ )
4+ [ ![ Python] ( https://img.shields.io/pypi/pyversions/mhc-tp.svg )] ( https://pypi.org/project/mhc-tp/ )
5+ [ ![ Docs] ( https://img.shields.io/badge/docs-mkdocs--material-526CFE.svg )] ( https://purcelllab.github.io/MHC-TP/ )
6+ [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( LICENSE )
7+
8+ Cluster immunopeptidomics peptides by their ** HLA/MHC binding motif** and get a
9+ ranked table plus a standalone, interactive HTML report.
510
611` mhc-tp ` takes a ** GibbsCluster** output folder, correlates each cluster's
712position-specific scoring matrix against a reference of HLA/MHC ** class I + II**
8- binding motifs (human & mouse), and writes the best allele match per cluster.
13+ binding motifs (human & mouse), and reports the best allele match per cluster.
14+
15+ > [ !TIP]
16+ > 📖 ** [ Documentation] ( https://purcelllab.github.io/MHC-TP/ ) **   ; ·  ;
17+ > 🔬 ** [ Live example report] ( https://purcelllab.github.io/MHC-TP/example-report.html ) **   ; ·  ;
18+ > 📦 ** [ PyPI] ( https://pypi.org/project/mhc-tp/ ) **
919
1020---
1121
12- ## For users
22+ ## Quick start
1323
14- ** Requirements:** Python 3.9–3.11.
24+ ``` bash
25+ pip install mhc-tp
26+ mhc-tp fetch -s human # download reference motifs (once)
27+ mhc-tp search < gibbscluster_output_dir> -s human -o results/
28+ ```
29+
30+ Open ` results/clust_result/mhc-tp-result.html ` in any browser — see what it looks like in the
31+ ** [ live example report] ( https://purcelllab.github.io/MHC-TP/example-report.html ) ** .
32+
33+ > [ !NOTE]
34+ > ** Requirements:** Python 3.9–3.11. A virtual environment is recommended
35+ > (` python -m venv .venv && source .venv/bin/activate ` ).
36+
37+ ---
1538
16- ### 1. Install
39+ ## Install
1740
18- Clone the repo and install it (editable, so ` git pull ` updates the tool):
41+ From PyPI (recommended):
42+
43+ ``` bash
44+ pip install mhc-tp
45+ ```
46+
47+ <details >
48+ <summary >Or install editable from source</summary >
49+
50+ So that ` git pull ` updates the tool:
1951
2052``` bash
2153git clone https://github.com/PurcellLab/MHC-TP.git
2254cd MHC-TP
2355pip install -e .
2456```
2557
26- > Prefer a one-liner without cloning? ` pip install git+https://github.com/PurcellLab/MHC-TP.git `
27- > A virtual environment (` python -m venv .venv && source .venv/bin/activate ` ) is recommended.
58+ One-liner without cloning: ` pip install "git+https://github.com/PurcellLab/MHC-TP.git" `
59+
60+ </details >
2861
29- ### 2. Download the reference data (once)
62+ ## Download the reference data (once)
3063
3164The reference motifs are fetched from the GitHub release, not bundled:
3265
3366``` bash
3467mhc-tp fetch -s human # or: mouse | all
3568```
3669
37- ### 3. Run a search
70+ ## Run a search
3871
3972``` bash
4073mhc-tp search < gibbscluster_output_dir> -s human -o results/
4174```
4275
43- ` <gibbscluster_output_dir> ` is a GibbsCluster run folder (it must contain a
44- ` matrices/ ` subdirectory).
76+ ` <gibbscluster_output_dir> ` is a GibbsCluster run folder (it must contain a ` matrices/ ` subdirectory).
4577
4678** Outputs** land in ` results/clust_result/ ` :
4779
4880| file | what it is |
4981| ------| ------------|
50- | ` correlations.csv ` | every cluster→allele match above the threshold (` hla ` = display name, ` formatted ` = raw key, ` correlation ` = PCC) |
51- | ` mhc-tp-result.html ` | standalone report — open it in any browser |
82+ | ` correlations.csv ` | every cluster→allele match (` hla ` = display name, ` formatted ` = raw key, ` correlation ` = PCC) |
83+ | ` mhc-tp-result.html ` | standalone interactive report — open it in any browser |
5284
53- ### Common options
85+ ### Options
5486
5587| flag | meaning | default |
5688| ------| ---------| ---------|
5789| ` -s, --species ` | ` human ` or ` mouse ` | ` human ` |
90+ | ` -c, --class ` | restrict the reference to MHC class ` I ` , ` II ` , or ` all ` | ` all ` |
5891| ` -r, --reference ` | path to a ` <species>.parquet ` (otherwise the fetched one is used) | auto |
59- | ` -t, --threshold ` | minimum Pearson correlation to report | ` 0.70 ` |
92+ | ` -t, --threshold ` | minimum Pearson correlation (PCC) to report | ` 0.70 ` |
93+ | ` --topNHits ` | allele matches to keep per cluster | ` 3 ` |
94+ | ` --always-top-n ` | keep each cluster's top-N even below threshold (flagged in the report) | off |
6095| ` -o, --output ` | output directory | ` output ` |
6196| ` --threads ` | max CPU threads (also ` $MHC_TP_THREADS ` ) | ` 4 ` |
6297| ` --no-html ` | write only the CSV | off |
6398| ` -l, --log ` | also save the coloured session log | off |
6499
65100Run ` mhc-tp search --help ` for the full list.
66101
102+ ### Examples
103+
104+ ``` bash
105+ # Class I only, keep the top 5 matches per cluster
106+ mhc-tp search runs/sampleA -s human -c I --topNHits 5 -o results/
107+
108+ # Guarantee a top-3 for every cluster (weak matches tagged "below cutoff")
109+ mhc-tp search runs/sampleA -s human --always-top-n -o results/
110+ ```
111+
112+ > [ !IMPORTANT]
113+ > By default a match must score ` ≥ --threshold ` , so a cluster can return fewer than
114+ > ` --topNHits ` rows (or none). ` --always-top-n ` returns the best N regardless — the
115+ > threshold then only ** annotates** confidence and nothing is dropped.
116+
67117---
68118
69119## For contributors / developers
70120
71- The project uses [ pixi] ( https://pixi.sh ) for a reproducible dev environment
72- (Python 3.11) and a ` src/ ` layout packaged with hatchling.
121+ <details >
122+ <summary >Dev environment, tests, and docs (click to expand)</summary >
123+
124+ The project uses [ pixi] ( https://pixi.sh ) for a reproducible dev environment (Python 3.11)
125+ and a ` src/ ` layout packaged with hatchling.
73126
74127``` bash
75128git clone https://github.com/PurcellLab/MHC-TP.git
76129cd MHC-TP
77130pixi install # create the dev env from pixi.lock
78- pixi run dev-install # editable-install the package into the env (run once)
131+ pixi run dev-install # editable-install the package (run once)
79132
80133pixi run test # pytest
81134pixi run lint # ruff
82135pixi run fmt # black
83136```
84137
85- Always run via ` pixi run … ` — a bare ` python ` may pick up a different
86- interpreter without the pinned dependencies.
138+ > [ !WARNING]
139+ > Always run via ` pixi run … ` — a bare ` python ` may pick up a different interpreter
140+ > without the pinned dependencies. CI enforces ` black --check ` , so run ` pixi run fmt ` before pushing.
141+
142+ ### Preview the docs site
143+
144+ ``` bash
145+ pip install -e " .[docs]"
146+ mkdocs serve # live preview at http://127.0.0.1:8000
147+ mkdocs build # static site in ./site
148+ ```
87149
88150### Rebuilding the reference data (dev only)
89151
90152End users never do this. The per-species parquets are built once from the
91153NetMHCpan / NetMHCIIpan packs and uploaded to the release. Embedding the
92- Seq2Logo reference logos (` --with-logos ` ) needs a separate Python 2.7 env and
93- is slow — run it on a cluster:
154+ Seq2Logo reference logos (` --with-logos ` ) needs a separate Python 2.7 env and is slow:
94155
95156``` bash
96- mhc-tp build-ref < species> < classI_pack> < classII_pack> < out.parquet> \
97- --with-logos --workers 16
98- # Seq2Logo itself runs in its own env: pixi run -e seq2logo ...
157+ mhc-tp build-ref < species> < classI_pack> < classII_pack> < out.parquet> --with-logos --workers 16
99158```
100159
101160### Layout
102161
103- ```
162+ ``` text
104163src/mhc_tp/
105164 cli.py entry point (mhc-tp)
106165 engine/ numba correlation search
@@ -109,20 +168,36 @@ src/mhc_tp/
109168 db/ DEV-ONLY reference-pack ingestion
110169 tui/ Rich console banner, logging, results table
111170tests/ pytest suite
171+ docs/ MkDocs site
112172```
113173
174+ </details >
175+
176+ ---
177+
178+ ## How it works
179+
180+ For each GibbsCluster motif, every reference allotype motif is scored by the ** Pearson
181+ correlation** of their flattened position-weight matrices, computed only over the
182+ informative cells of the cluster motif. Per cluster the allotypes are ranked by PCC
183+ (` 1.0 ` = identical motif shape). Full method and formula:
184+ the ** [ API reference] ( https://purcelllab.github.io/MHC-TP/api/ ) ** .
185+
114186---
115187
116188## Citation
117189
118190If you use MHC-TP in your work, please cite:
119191
120192> Munday PR, Krishna SSG, Fehring J, Croft NP, Purcell AW, Li C, Braun A.
121- > Immunolyser 2.0: An advanced computational pipeline for comprehensive analysis
122- > of immunopeptidomic data. * Comput Struct Biotechnol J.* 2025;29:296–304.
193+ > * Immunolyser 2.0: An advanced computational pipeline for comprehensive analysis of
194+ > immunopeptidomic data.* Comput Struct Biotechnol J. 2025;29:296–304.
123195> doi:[ 10.1016/j.csbj.2025.10.007] ( https://doi.org/10.1016/j.csbj.2025.10.007 ) .
124196> PMID: [ 41209766] ( https://pubmed.ncbi.nlm.nih.gov/41209766/ ) ; PMCID: PMC12590289.
125197
198+ <details >
199+ <summary >BibTeX</summary >
200+
126201``` bibtex
127202@article{Munday2025Immunolyser2,
128203 title = {Immunolyser 2.0: An advanced computational pipeline for comprehensive analysis of immunopeptidomic data},
@@ -137,3 +212,4 @@ If you use MHC-TP in your work, please cite:
137212}
138213```
139214
215+ </details >
0 commit comments