Skip to content

Commit 778049b

Browse files
authored
Merge pull request #297 from pbashyal-nmdp/fix-serology-sort
Fix serology sort
2 parents 26f9db7 + d9868f2 commit 778049b

File tree

8 files changed

+42
-18
lines changed

8 files changed

+42
-18
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ LABEL MAINTAINER="Pradeep Bashyal"
44

55
WORKDIR /app
66

7-
ARG PY_ARD_VERSION=1.0.9
7+
ARG PY_ARD_VERSION=1.0.10
88

99
COPY requirements.txt /app
1010
RUN pip install --no-cache-dir --upgrade pip && \

api-spec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.0.3
22
info:
33
title: ARD Reduction
44
description: Reduce to ARD Level
5-
version: "1.0.9"
5+
version: "1.0.10"
66
servers:
77
- url: 'http://localhost:8080'
88
tags:

pyard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .misc import get_imgt_db_versions as db_versions
2828

2929
__author__ = """NMDP Bioinformatics"""
30-
__version__ = "1.0.9"
30+
__version__ = "1.0.10"
3131

3232

3333
def init(

pyard/smart_sort.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

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

3233

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

6465
# Handle serology
6566
if ":" not in a1:
66-
return 1 if a1 > a2 else -1
67+
serology1_match = serology_splitter.match(a1)
68+
serology1_num = int(serology1_match.group(2))
69+
serology2_match = serology_splitter.match(a2)
70+
serology2_num = int(serology2_match.group(2))
71+
return 1 if serology1_num > serology2_num else -1
6772

6873
# Extract and Compare 1st fields first
6974
a1_f1 = int(a1[a1.find("*") + 1 : a1.find(":")])

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.9
2+
current_version = 1.0.10
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
setup(
3838
name="py-ard",
39-
version="1.0.9",
39+
version="1.0.10",
4040
description="ARD reduction for HLA with Python",
4141
long_description=readme,
4242
long_description_content_type="text/markdown",

tests/features/serology_redux.feature

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ Feature: Serology Reduction
77

88
Given the allele as <Allele>
99
When reducing on the <Level> level with ping
10-
Then the reduced allele is found to be <Redux Allele>
10+
Then the reduced allele is found to be <Redux Serology>
1111

12-
Examples:
13-
| Allele | Level | Redux Allele |
14-
| A*01:01:01:01 | S | A1 |
15-
| A*01:01 | S | A1 |
16-
| A*01:AABJE | S | A1/A36 |
17-
| A*03:XX | S | A3 |
18-
| B*44:02:01:11/B*44:02:01:12 | S | B12/B44 |
19-
| B*13:03 | S | B13 |
20-
| B*13:04 | S | B15/B21 |
21-
| B*15:01/B*15:02/B*15:03/B*15:04 | S | B15/B62/B70/B72/B75 |
22-
| B*15:10 | S | B15/B70/B71 |
12+
Examples: Alleles to Serology
13+
| Allele | Level | Redux Serology |
14+
| A*01:01:01:01 | S | A1 |
15+
| A*01:01 | S | A1 |
16+
| A*01:AABJE | S | A1/A36 |
17+
| A*03:XX | S | A3 |
18+
| B*44:02:01:11/B*44:02:01:12 | S | B12/B44 |
19+
| B*13:03 | S | B13 |
20+
| B*13:04 | S | B15/B21 |
21+
22+
Examples: Serology Sorted Properly
23+
| Allele | Level | Redux Serology |
24+
| B*15:01/B*15:02/B*15:03/B*15:04 | S | B15/B62/B70/B72/B75 |
25+
| B*15:10 | S | B15/B70/B71 |
26+
| A*24:03/A*24:10/A*24:23/A*24:33/A*24:374 | S | A9/A24/A2403 |

tests/test_smart_sort.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ def test_fourth_field_comparator_ge(self):
104104
allele2 = "HLA-A*01:01:01:09"
105105
self.assertEqual(smart_sort_comparator(allele1, allele2), 1)
106106

107+
def test_serology_ge(self):
108+
serology1 = "Cw10"
109+
serology2 = "Cw3"
110+
self.assertEqual(smart_sort_comparator(serology1, serology2), 1)
111+
112+
def test_serology_le(self):
113+
serology1 = "A10"
114+
serology2 = "A25"
115+
self.assertEqual(smart_sort_comparator(serology1, serology2), -1)
116+
117+
def test_serology_eq(self):
118+
serology1 = "B70"
119+
serology2 = "B70"
120+
self.assertEqual(smart_sort_comparator(serology1, serology2), 0)
121+
107122

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

0 commit comments

Comments
 (0)