Skip to content

Commit 6eafdf0

Browse files
authored
Merge pull request #13 from cfe-lab/ReformatBBLabAlleles
Converted the old BBLab alleles to the new format.
2 parents 37d86c8 + 3b41c58 commit 6eafdf0

File tree

7 files changed

+31327
-98
lines changed

7 files changed

+31327
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
**/output/
66
**/*.xml
77
**/*.fasta
8+
**/.DS_Store

README.md

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,93 @@
66

77
## Objective
88

9-
This is a Python implementation of the BC-CfE HLA algorithm. This algorithm has
10-
several interpretations, including [BBLab's hla-easy.rb](https://github.com/cfe-lab/bblab-server/blob/main/alldata/hla_class/hla-easy.rb) file. This project aims
11-
to consolidate all of our HLA algorithm versions into a single version.
9+
This is a Python implementation of the BC-CfE HLA algorithm. This algorithm
10+
has several implementations, including [BBLab's hla-easy.rb][bblab_hla] file.
11+
This project aims to consolidate all of our HLA algorithm versions into a
12+
single version.
1213

13-
## Testing
14+
[bblab_hla]: https://github.com/cfe-lab/bblab-server/blob/main/alldata/hla_class/hla-easy.rb
1415

15-
FIXME
16+
The `hla_algorithm` Python package provided by this repository exposes some
17+
executables as well.
1618

17-
The current validation method is to go to the [BBLab HLA Class tool page](https://hivresearchtools.bccfe.ca/django/tools/hla_class/), upload [test.fasta](https://github.com/cfe-lab/bblab-server/blob/main/tests/test.fasta) in `HLA Type C`, and assert that its output matches [the output kept in version control](https://github.com/cfe-lab/bblab-server/blob/main/tests/hla_class/HLA-C%20batch%20mode%20test%20data%20OUTPUT.csv).
19+
* [`interpret_from_json`][interpret_from_json]: A bare-bones script that
20+
performs interpretation on an HLA sequence specified in JSON.
21+
* This script is also available as `python -m hla_algorithm` (in the
22+
environment where the module is installed).
23+
* [`update_alleles`][update_alleles]: Retrieves alleles from IMGT/HLA (or an
24+
alternative source) and creates a YAML configuration file suitable for use with
25+
this code. This is used periodically to update our lists of alleles with
26+
up-to-date information.
27+
* [`update_frequency_file`][update_frequency_file]: Updates an "old-style"
28+
HLA frequency file into the format used by this algorithm.
29+
* As of the time of writing, the frequencies file has unknown origin and has
30+
never been updated. Under typical operation, you'll likely never use this.
31+
* [`reformat_old_alleles`][reformat_old_alleles]: Updates "old-style" HLA
32+
allele lists into a YAML configuration file suitable for use with this code.
33+
These allele lists may be either "unreduced" (with duplicates remaining) or
34+
"reduced" (with duplicates collapsed into a single representative). This
35+
script can be used to update old allele lists that you wish to continue using
36+
with this code, e.g. if you already have an old implementation of this
37+
algorithm running somewhere and wish to preserve its functionality.
1838

19-
## TODO
39+
[interpret_from_json]: src/hla_algorithm/interpret_from_json.py
40+
[update_alleles]: src/hla_algorithm/update_alleles.py
41+
[update_frequency_file]: src/hla_algorithm/update_frequency_file.py
42+
[reformat_old_alleles]: src/hla_algorithm/reformat_old_alleles.py
2043

21-
<https://waylonwalker.com/hatch-version/>
44+
### Ruby wrapper
45+
46+
In addition to the Python module, this repository also contains a Ruby wrapper
47+
enabling this code to be used in Ruby (through system calls). The Ruby wrapper
48+
is intended as a drop-in replacement for the Ruby-based HLA algorithm that has
49+
been used at the CfE for years; once installed, this Ruby module provides an
50+
`HLAAlgorithm` class with an `analyze` method, as the old code did.
51+
Additionally, this `HLAAlgorithm` class can optionally be provided with new
52+
configuration files, so that the alleles (and frequencies, if that ever happens)
53+
can be updated without having to update the code.
54+
55+
This Ruby module works by simply packing up its inputs into a JSON file and
56+
invoking `interpret_from_json`. Therefore, the Python module must be installed
57+
on the system where you're using the Ruby module.
58+
59+
## Installation
60+
61+
This code may be installed from our git repo. For example, using pip:
62+
63+
```
64+
pip install git+https://github.com/cfe-lab/hla_algorithm.git@[tag]
65+
```
66+
67+
Using uv:
68+
69+
```
70+
uv add git+https://github.com/cfe-lab/hla_algorithm.git@[tag]
71+
```
72+
73+
### Ruby wrapper
74+
75+
Once the Python module is installed, the Ruby module can be installed from our
76+
GitHub package repository. First, you need to authenticate with the GitHub
77+
RubyGems registry. In brief, a personal access token (classic) is required to
78+
install from this registry (even though our repository is public). Then you
79+
must update your gem sources/bundler configuration with this token along with
80+
the username of the token creator. Full details may be found in
81+
[the GitHub instructions][github_rubygem_auth].
82+
83+
From there, you can install using either `gem` or via a Gemfile (i.e. with
84+
`bundler`). Instructions may be found on
85+
[the GitHub page for the package][github_package_page].
86+
87+
The Ruby module must be instructed on how to invoke `interpret_from_json`,
88+
using the environment variable `HLA_INTERPRET_FROM_JSON`. For example, if you
89+
install Python using `uv` in your project directory (as recommended), then you
90+
would set this to `uv run interpret_from_json`. If your project is
91+
Docker-based, then you can set this in your Dockerfile:
92+
93+
```
94+
ENV HLA_INTERPRET_FROM_JSON="uv run interpret_from_json"
95+
```
96+
97+
[github_rubygem_auth]: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry
98+
[github_package_page]: https://github.com/cfe-lab/hla_algorithm/pkgs/rubygems/hla_algorithm

pyproject.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "hla_algorithm"
7-
description = ''
7+
description = 'Python implementation of the BC-CfE HLA interpretation algorithm'
88
readme = "README.md"
99
requires-python = ">=3.10"
1010
license = "MIT"
1111
keywords = []
1212
authors = [
1313
{ name = "Rosemary McCloskey", email = "retired@bccfe.ca" },
1414
{ name = "David Rickett", email = "drickett@bccfe.ca" },
15+
{ name = "Richard Liang", email = "rliang@bccfe.ca" },
1516
]
1617
classifiers = [
17-
"Development Status :: 4 - Beta",
18+
"Development Status :: 5 - Production/Stable",
1819
"Programming Language :: Python",
1920
"Programming Language :: Python :: 3.10",
2021
"Programming Language :: Python :: 3.11",
2122
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
2224
"Programming Language :: Python :: Implementation :: CPython",
2325
"Programming Language :: Python :: Implementation :: PyPy",
2426
]
@@ -61,6 +63,7 @@ Source = "https://github.com/cfe-lab/hla_algorithm"
6163
interpret_from_json = "hla_algorithm.interpret_from_json:main"
6264
update_alleles = "hla_algorithm.update_alleles:main"
6365
update_frequency_file = "hla_algorithm.update_frequency_file:main"
66+
reformat_old_alleles = "hla_algorithm.reformat_old_alleles:main"
6467

6568
[tool.hatch.version]
6669
source = "uv-dynamic-versioning"
@@ -75,6 +78,7 @@ include = [
7578
"src/hla_algorithm/interpret_from_json.py",
7679
"src/hla_algorithm/models.py",
7780
"src/hla_algorithm/py.typed",
81+
"src/hla_algorithm/reformat_old_alleles.py",
7882
"src/hla_algorithm/update_alleles.py",
7983
"src/hla_algorithm/update_frequency_file_lib.py",
8084
"src/hla_algorithm/update_frequency_file.py",
@@ -125,6 +129,7 @@ omit = [
125129
"src/hla_algorithm/__main__.py",
126130
"tests/__init__.py",
127131
"src/hla_algorithm/interpret_from_json.py",
132+
"src/hla_algorithm/reformat_old_alleles.py",
128133
"src/hla_algorithm/update_alleles.py",
129134
"src/hla_algorithm/update_frequency_file.py",
130135
"src/scripts/*.py",
@@ -149,7 +154,6 @@ select = ["E4", "E7", "E9", "F", "C"]
149154
# https://www.flake8rules.com/rules/E712.html
150155
ignore = ["E712"]
151156

152-
153157
[tool.pydocstyle]
154158
match = "src/**/*.py"
155159

src/hla_algorithm/.DS_Store

-8 KB
Binary file not shown.

0 commit comments

Comments
 (0)