Skip to main content

HLAfreq

HLAfreq allows you to download and combine HLA allele frequencies from multiple datasets, e.g. combine data from several studies within a country or combine countries. Useful for studying regional diversity in immune genes and, when paired with epitope prediction, estimating a population's ability to mount an immune response to specific epitopes.

Automated download of allele frequency data download from allele frequencies.net.

Full documentation at HLAfreq/docs. Source code is available at BarinthusBio/HLAfreq.

Details

Estimates are combined by modelling allele frequency as a Dirichlet distribution which defines the probability of drawing each allele. When combining studies their estimates are weighted as 2x sample size by default. Sample size is doubled as each person in the study contributes two alleles. Alternative weightings can be used, for example population size when averaging across countries.

When selecting a panel of HLA alleles to represent a population, allele frequency is not the only thing to consider. Depending on the purpose of the panel, you should include a range of loci and supertypes (grouped alleles sharing binding specificies).

Install

HLAfreq is a python package available on windows, mac, and linux. We recommend installing with conda.

conda create -n hlafreq -c bioconda -c conda-forge hlafreq
conda activate hlafreq

If you're new to conda see the miniconda installation guide and documentation to get started with conda. Enter the above command into your conda prompt to create and activate a conda environment with HLAfreq installed. Typing python into this activated environment will start a python session where you can enter your python code such as the HLAfreq minimal example below.

If you prefer to write your python code as scripts using an IDE such as PyCharm or VScode, you'll need to look up how to configure a conda virtual environment with those tools.

Troubleshooting

HLAfreq uses pymc to estimate credible intervals, which is the source of most installation difficulty, see pymc installation guide.

At time of writing pymc doesn't play nice with python 3.11, so you can try installing a specific python version and then add HLAfreq with pip or conda. For example

conda create -n hlafreq -c conda-forge -c bioconda python=3.10 numpy=1.25.2 pymc=5.6.1 hlafreq

HLAfreq requires python>=3.8, matplotlib>=3.5, and pymc>=3. Conda should handle this automatically, but if you get errors check the package versions with conda list.

If you do run into trouble please open an issue.

If you don't intend to use credible intervals you can install with pip: pip install HLAfreq. However, if you do import HLAfreq_pymc you may get warnings about degraded performance.

See the pip documentation to get started with pip. If you do have issues with pip, try installing with conda as described above.

Minimal example

Download HLA data using HLAfreq.HLAfreq.makeURL() and HLAfreq.HLAfreq.getAFdata(). All arguments that can be specified in the webpage form are available, see help(HLAfreq.makeURL) for details (press q to exit).

import HLAfreq
base_url = HLAfreq.makeURL("Uganda", locus="A")
aftab = HLAfreq.getAFdata(base_url)

After downloading the data, it must be filtered so that all studies sum to allele frequency 1 (within tolerence). Then we must ensure that all studies report alleles at the same resolution. Finaly we can combine frequency estimates, for more details see the HLAfreq.HLAfreq.combineAF() api documentation.

aftab = HLAfreq.only_complete(aftab)
aftab = HLAfreq.decrease_resolution(aftab, 2)
caf = HLAfreq.combineAF(aftab)

Detailed examples

For more detailed walkthroughs see HLAfreq/examples.

Docs

Full documentation at HLAfreq/docs. API documentation for functions are under the submodules on the left.

  • HLAfreq.HLAfreq documents most functions, specifically download and combine allele data.
  • HLAfreq.HLAfreq_pymc is functions using pymc to acurately estimate credible intervals on allele frequency estimates.

For help on specific functions view the docstring, help(function_name).

Run pdoc -d google -o docs/ HLAfreq to generate the documentation in ./docs.

Citation

Wells, D. A., & McAuley, M. (2023). HLAfreq: Download and combine HLA allele frequency data. bioRxiv, 2023-09. https://doi.org/10.1101/2023.09.15.557761

Metadata

Release files for hlafreq 0.0.4

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

Source distribution (sdist)

Source distribution for hlafreq 0.0.4
File Size Uploaded Provenance
hlafreq-0.0.4.tar.gz 19.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hlafreq 0.0.4
File Interpreter ABI Platform
HLAfreq-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / hlafreq-0.0.4.tar.gz

Download URL hlafreq-0.0.4.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
58aa7aaa1d554a3264531f6aaa3bd0a5a29c13b58441dc6564537adf4d096051
BLAKE2b-256 checksum
How to use checksums
0ac1c2d9d353d24f747dd621e7f681600196dca5317c6689114cd5b3cdb9900f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / HLAfreq-0.0.4-py3-none-any.whl

Download URL HLAfreq-0.0.4-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15babcae254dd3be63b4974c179bae39050b321b33d784d8c2dac3fad89fc3d9
BLAKE2b-256 checksum
How to use checksums
c689d95c37792c8b117df616791fbba096a1aa781ecb14b71f96b0760ae33d7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for hlafreq 0.0.4

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.

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