Skip to content

Commit

Permalink
Merge pull request #297 from pbashyal-nmdp/fix-serology-sort
Browse files Browse the repository at this point in the history
Fix serology sort
  • Loading branch information
mmaiers-nmdp authored Jan 19, 2024
2 parents 26f9db7 + d9868f2 commit 778049b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL MAINTAINER="Pradeep Bashyal"

WORKDIR /app

ARG PY_ARD_VERSION=1.0.9
ARG PY_ARD_VERSION=1.0.10

COPY requirements.txt /app
RUN pip install --no-cache-dir --upgrade pip && \
Expand Down
2 changes: 1 addition & 1 deletion api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: ARD Reduction
description: Reduce to ARD Level
version: "1.0.9"
version: "1.0.10"
servers:
- url: 'http://localhost:8080'
tags:
Expand Down
2 changes: 1 addition & 1 deletion pyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .misc import get_imgt_db_versions as db_versions

__author__ = """NMDP Bioinformatics"""
__version__ = "1.0.9"
__version__ = "1.0.10"


def init(
Expand Down
7 changes: 6 additions & 1 deletion pyard/smart_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

expr_regex = re.compile("[PNQLSGg]")
glstring_chars = re.compile("[/|+^~]")
serology_splitter = re.compile(r"(\D+)(\d+)")


@functools.lru_cache(maxsize=constants.DEFAULT_CACHE_SIZE)
Expand Down Expand Up @@ -63,7 +64,11 @@ def smart_sort_comparator(a1, a2):

# Handle serology
if ":" not in a1:
return 1 if a1 > a2 else -1
serology1_match = serology_splitter.match(a1)
serology1_num = int(serology1_match.group(2))
serology2_match = serology_splitter.match(a2)
serology2_num = int(serology2_match.group(2))
return 1 if serology1_num > serology2_num else -1

# Extract and Compare 1st fields first
a1_f1 = int(a1[a1.find("*") + 1 : a1.find(":")])
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.9
current_version = 1.0.10
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

setup(
name="py-ard",
version="1.0.9",
version="1.0.10",
description="ARD reduction for HLA with Python",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down
28 changes: 16 additions & 12 deletions tests/features/serology_redux.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ Feature: Serology Reduction

Given the allele as <Allele>
When reducing on the <Level> level with ping
Then the reduced allele is found to be <Redux Allele>
Then the reduced allele is found to be <Redux Serology>

Examples:
| Allele | Level | Redux Allele |
| A*01:01:01:01 | S | A1 |
| A*01:01 | S | A1 |
| A*01:AABJE | S | A1/A36 |
| A*03:XX | S | A3 |
| B*44:02:01:11/B*44:02:01:12 | S | B12/B44 |
| B*13:03 | S | B13 |
| B*13:04 | S | B15/B21 |
| B*15:01/B*15:02/B*15:03/B*15:04 | S | B15/B62/B70/B72/B75 |
| B*15:10 | S | B15/B70/B71 |
Examples: Alleles to Serology
| Allele | Level | Redux Serology |
| A*01:01:01:01 | S | A1 |
| A*01:01 | S | A1 |
| A*01:AABJE | S | A1/A36 |
| A*03:XX | S | A3 |
| B*44:02:01:11/B*44:02:01:12 | S | B12/B44 |
| B*13:03 | S | B13 |
| B*13:04 | S | B15/B21 |

Examples: Serology Sorted Properly
| Allele | Level | Redux Serology |
| B*15:01/B*15:02/B*15:03/B*15:04 | S | B15/B62/B70/B72/B75 |
| B*15:10 | S | B15/B70/B71 |
| A*24:03/A*24:10/A*24:23/A*24:33/A*24:374 | S | A9/A24/A2403 |
15 changes: 15 additions & 0 deletions tests/test_smart_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def test_fourth_field_comparator_ge(self):
allele2 = "HLA-A*01:01:01:09"
self.assertEqual(smart_sort_comparator(allele1, allele2), 1)

def test_serology_ge(self):
serology1 = "Cw10"
serology2 = "Cw3"
self.assertEqual(smart_sort_comparator(serology1, serology2), 1)

def test_serology_le(self):
serology1 = "A10"
serology2 = "A25"
self.assertEqual(smart_sort_comparator(serology1, serology2), -1)

def test_serology_eq(self):
serology1 = "B70"
serology2 = "B70"
self.assertEqual(smart_sort_comparator(serology1, serology2), 0)


if __name__ == "__main__":
unittest.main()

0 comments on commit 778049b

Please sign in to comment.