mhcgnomes: Parsing MHC nomenclature in the wild
MHCgnomes is a parsing library for multi-species MHC nomenclature which aims to correctly parse every name in IEDB, IMGT/HLA, IPD/MHC, and the allele lists for both NetMHCpan and NetMHCIIpan predictors. This allows for standardization between immune databases and tools, which often use different naming conventions.
It is the allele-naming layer of the openvax stack: mhctools, mhcflurry and mhcseqs all normalize allele names through it rather than parsing strings themselves.
Install
pip install mhcgnomes
Requires Python 3.11 or later. There are no MHC data downloads: the curated species and gene ontology ships with the package.
Quick start
>>> import mhcgnomes
>>> [mhcgnomes.parse(s).to_string() for s in ["A*02:01", "HLA-A0201", "hla-a:02:01"]]
['HLA-A*02:01', 'HLA-A*02:01', 'HLA-A*02:01']
>>> mhcgnomes.parse("DQ2.5").to_string()
'HLA-DQA1*05:01/DQB1*02:01'
>>> type(mhcgnomes.parse("HLA-A2")).__name__
'Serotype'
>>> mhcgnomes.parse("H2-Kk").to_string()
'H2-K*k'
parse returns a structured object, not a string: an Allele, Gene,
Pair, Serotype, Haplotype, MhcClass or Species, depending on how much
the input actually specified. to_string() gives the normalized spelling and
compact_string() the short one:
>>> mhcgnomes.parse("HLA-A0201")
Allele(gene=Gene(species=Species(name='Homo sapiens', mhc_prefix='HLA'), name='A', mutations=()), allele_fields=('02', '01'), annotations=(), mutations=())
>>> mhcgnomes.parse("HLA-A0201").compact_string()
'A0201'
Pass raise_on_error=False to get None instead of a ParseError, and
required_result_types= to say which of those types you will accept. Both
matter when the input is not a curated allele list; see
parsing untrusted input.
Command line
mhcgnomes "HLA-A*02:01" "DQ2.5"
This prints one row per input with the parsed result type, the normalized and
compact forms, species, gene, MHC class, and the parsed properties from
to_record(). --format tsv and --format json give machine-readable
output, --strict exits non-zero on the first parse error, and
mhcgnomes data manages the pinned external IMGT/IPD files. The
command-line guide shows the full
output of each.
Documentation
Full documentation: pirl-unc.github.io/mhcgnomes.
- MHC nomenclature in the wild: why one allele has a dozen spellings, and what the other named entities are
- Parsing guide: result types, untrusted input, species inference,
species=vsdefault_species= - Command line
- Species and gene ontology: the species tree, prefix tiers and provenance, gene classes
- Curation guide: where new species, genes and aliases go
- Immutable data objects and the release process
Development
./develop.sh # create .venv and install the package with dev and docs extras
./format.sh # ruff format
./lint.sh # ruff check and ruff format --check
./test.sh # pytest with coverage, worker count capped by free RAM and CPUs
Every pull request bumps mhcgnomes/version.py; see the
release process
(source) for how a merged version reaches PyPI.
Raw IPD-IMGT/HLA and IPD-MHC snapshots are not committed or bundled in releases. See External IMGT/IPD data for checksum-pinned downloads, local/CI caches, optional mirrors, offline use, and alias regeneration.
To work on the documentation site:
./develop.sh
mkdocs serve
mkdocs build --strict
License
Metadata
Release files for mhcgnomes 3.68.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mhcgnomes-3.68.1.tar.gz | 263.0 kB | Without provenance | Details for mhcgnomes-3.68.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mhcgnomes-3.68.1-py3-none-any.whl | Python 3 | none | any | Details for mhcgnomes-3.68.1-py3-none-any.whl |
Total release size: 552.1 kB
Release files / mhcgnomes-3.68.1.tar.gz
| Download URL | mhcgnomes-3.68.1.tar.gz |
|---|---|
| Size | 263.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d19d6b9526645a4d2d797722f214118d879a0a82620a840e1f1edea5d2196395
|
|
BLAKE2b-256 checksum How to use checksums |
d8ce166d0fd0363a57a9a72877d34e3026d5f6ce5200c37be84308f0727a3d02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Release files / mhcgnomes-3.68.1-py3-none-any.whl
| Download URL | mhcgnomes-3.68.1-py3-none-any.whl |
|---|---|
| Size | 289.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e3a2f556f76f1981b9091c8c46673f3d1e7ce865ddfcd4bf755c94b76f802c6
|
|
BLAKE2b-256 checksum How to use checksums |
4712e60a93f9ddc8c1271ecd8182ebdcc9f91313f88ebfa3349ae1fba7574895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Security for mhcgnomes 3.68.1
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.