Skip to content

Commit a2d3d8c

Browse files
authored
Merge pull request #280 from pbashyal-nmdp/fix_mica_micb
Fix Single field MICA, MICB Alleles failing
2 parents 21f3d4e + 49c135a commit a2d3d8c

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

pyard/ard.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
VALID_REDUCTION_TYPES,
4444
expression_chars,
4545
DEFAULT_CACHE_SIZE,
46+
G_GROUP_LOCI,
4647
)
4748

4849
default_config = {
@@ -387,6 +388,10 @@ def redux(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:
387388
loc_allele = glstring.split(":")
388389
loc_antigen, code = loc_allele[0], loc_allele[1]
389390
else:
391+
if "*" in glstring:
392+
locus, _ = glstring.split("*")
393+
if locus not in G_GROUP_LOCI:
394+
return glstring
390395
raise InvalidTypingError(
391396
f"{glstring} is not a valid V2 or Serology typing."
392397
)
@@ -534,6 +539,7 @@ def is_v2(self, allele: str) -> bool:
534539
self._config["reduce_v2"]
535540
and "*" in allele
536541
and ":" not in allele
542+
and allele.split("*")[0] not in ["MICA", "MICB", "HFE"]
537543
and allele != self._map_v2_to_v3(allele)
538544
)
539545

pyard/constants.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,32 @@
2525

2626
HLA_regex = re.compile("^HLA-")
2727

28-
VALID_REDUCTION_TYPES = ["G", "P", "lg", "lgx", "W", "exon", "U2", "S"]
29-
expression_chars = ["N", "Q", "L", "S"]
28+
VALID_REDUCTION_TYPES = ("G", "P", "lg", "lgx", "W", "exon", "U2", "S")
29+
expression_chars = ("N", "Q", "L", "S")
3030
# List of P and G characters
31-
PandG_chars = ["P", "G"]
31+
P_and_G_chars = ("P", "G")
32+
33+
# Loci with G group data
34+
# Retrieved from lgx_group
35+
# sqlite> select distinct(substr(allele, 1, instr(allele, '*') - 1)) from lgx_group;
36+
G_GROUP_LOCI = (
37+
"A",
38+
"B",
39+
"C",
40+
"DMA",
41+
"DMB",
42+
"DOA",
43+
"DOB",
44+
"DPA1",
45+
"DPB1",
46+
"DQA1",
47+
"DQB1",
48+
"DRA",
49+
"DRB1",
50+
"DRB3",
51+
"DRB4",
52+
"DRB5",
53+
"E",
54+
"F",
55+
"G",
56+
)

pyard/misc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import tempfile
2525
from typing import List
2626

27-
from pyard.constants import VALID_REDUCTION_TYPES, expression_chars, PandG_chars
27+
from pyard.constants import VALID_REDUCTION_TYPES, expression_chars, P_and_G_chars
2828

2929

3030
def get_n_field_allele(allele: str, n: int, preserve_expression=False) -> str:
@@ -47,15 +47,15 @@ def get_n_field_allele(allele: str, n: int, preserve_expression=False) -> str:
4747

4848
def get_3field_allele(a: str) -> str:
4949
last_char = a[-1]
50-
if last_char in PandG_chars:
50+
if last_char in P_and_G_chars:
5151
a = a[:-1]
5252

5353
return get_n_field_allele(a, 3)
5454

5555

5656
def get_2field_allele(a: str) -> str:
5757
last_char = a[-1]
58-
if last_char in PandG_chars:
58+
if last_char in P_and_G_chars:
5959
a = a[:-1]
6060
return get_n_field_allele(a, 2)
6161

@@ -76,7 +76,7 @@ def is_2_field_allele(allele: str) -> bool:
7676
def get_G_name(a: str) -> str:
7777
a = a.split("/")[0]
7878
last_char = a[-1]
79-
if last_char in PandG_chars + expression_chars:
79+
if last_char in P_and_G_chars + expression_chars:
8080
a = a[:-1]
8181
if len(a.split(":")) == 2:
8282
return ":".join([a, "01"]) + "G"
@@ -88,7 +88,7 @@ def get_G_name(a: str) -> str:
8888
def get_P_name(a: str) -> str:
8989
a = a.split("/")[0]
9090
last_char = a[-1]
91-
if last_char in PandG_chars + expression_chars:
91+
if last_char in P_and_G_chars + expression_chars:
9292
a = a[:-1]
9393
return ":".join(a.split(":")[0:2]) + "P"
9494

tests/features/allele.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,19 @@ Feature: Alleles
7171
| Allele | Level | Redux Allele |
7272
| A*24:329 | lgx | A*24:329Q |
7373
| DQB1*03:276 | lgx | DQB1*03:01 |
74+
75+
76+
Scenario Outline: Single field MICA, MICB Alleles
77+
78+
For MICA, MICB alleles with single field, their reduced version is self.
79+
80+
Given the allele as <Allele>
81+
When reducing on the <Level> level
82+
Then the reduced allele is found to be <Redux Allele>
83+
84+
Examples:
85+
| Allele | Level | Redux Allele |
86+
| HFE*002 | lgx | HFE*002 |
87+
| MICA*040 | lgx | MICA*040 |
88+
| MICB*006 | lgx | MICB*006 |
89+
| MICB*029 | lgx | MICB*029 |

0 commit comments

Comments
 (0)