Skip to content

Commit 738c337

Browse files
committed
Fix for V2s that are not valid
1 parent 9952d32 commit 738c337

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

pyard/ard.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,23 @@ def is_v2(self, allele: str) -> bool:
535535
:param allele: Possible allele
536536
:return: Is the allele in V2 nomenclature
537537
"""
538-
return (
538+
matches_v2_format = (
539539
self._config["reduce_v2"]
540540
and "*" in allele
541541
and ":" not in allele
542542
and allele.split("*")[0] not in ["MICA", "MICB", "HFE"]
543-
and allele != self._map_v2_to_v3(allele)
544543
)
545544

545+
if matches_v2_format:
546+
v3_format_allele = self._map_v2_to_v3(allele)
547+
if v3_format_allele != allele:
548+
# If the last field of the allele is alpha, check if it's a MAC
549+
if v3_format_allele.split(":").pop().isalpha():
550+
return self.is_mac(v3_format_allele)
551+
return self._is_valid_allele(v3_format_allele)
552+
553+
return False
554+
546555
def _is_who_allele(self, allele):
547556
"""
548557
Test if allele is a WHO allele in the current imgt database

tests/features/version2.feature

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@ Feature: Version 2 Nomenclature
22

33
py-ard is able to reduce version 2 HLA nomenclature.
44

5-
Scenario Outline:
5+
Scenario Outline: Redux V2 Alleles
66

77
Given the version 2 typing is <Version2>
88
When reducing on the <Level> level (ambiguous)
99
Then the reduced allele is found to be <Redux Allele>
1010

1111

12-
Examples: Valid A serology typings
12+
Examples: Reduce V2 Alleles
1313
| Version2 | Level | Redux Allele |
1414
| A*0105N | G | A*01:01:01G |
1515
| A*0111 | G | A*01:11N |
1616
| DRB5*02ZB | G | DRB5*01:02:01G/DRB5*01:03/DRB5*02:02:01G/DRB5*02:03/DRB5*02:04 |
17+
18+
19+
Scenario Outline: Invalid V2
20+
21+
Alleles that have valid V2 format but when converted to V3 format,
22+
is not a valid allele.
23+
24+
Given the version 2 typing is <Version2>
25+
When validating the V2 typing
26+
Then the validness of V2 typing is <Validity>
27+
28+
Examples: Validate
29+
| Version2 | Validity |
30+
| A*0105N | Valid |
31+
| DQB1*0804 | Invalid |
32+
| A*01:AB | Valid |
33+
| A*01:NOAB | Invalid |

tests/steps/redux_allele.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from behave import given, when, then
2323
from hamcrest import assert_that, is_
2424

25-
from pyard.exceptions import PyArdError
25+
from pyard.exceptions import PyArdError, InvalidAlleleError
2626

2727

2828
@given("the allele as {allele}")
@@ -72,6 +72,20 @@ def step_impl(context, v2_allele):
7272
context.allele = v2_allele
7373

7474

75+
@when("validating the V2 typing")
76+
def step_impl(context):
77+
try:
78+
context.is_valid = context.ard.validate(context.allele)
79+
except InvalidAlleleError:
80+
context.is_valid = False
81+
82+
83+
@then("the validness of V2 typing is {validity}")
84+
def step_impl(context, validity):
85+
valid = validity == "Valid"
86+
assert_that(context.is_valid, is_(valid))
87+
88+
7589
@given("the typing is {allele}")
7690
def step_impl(context, allele):
7791
context.allele = allele

0 commit comments

Comments
 (0)