Skip to content

Commit

Permalink
Merge pull request #283 from pbashyal-nmdp/incorrect-V2-versioned-allele
Browse files Browse the repository at this point in the history
Fix for V2s that are not valid
  • Loading branch information
mmaiers-nmdp committed Nov 7, 2023
2 parents 9952d32 + 738c337 commit c6ce3a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
13 changes: 11 additions & 2 deletions pyard/ard.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,23 @@ def is_v2(self, allele: str) -> bool:
:param allele: Possible allele
:return: Is the allele in V2 nomenclature
"""
return (
matches_v2_format = (
self._config["reduce_v2"]
and "*" in allele
and ":" not in allele
and allele.split("*")[0] not in ["MICA", "MICB", "HFE"]
and allele != self._map_v2_to_v3(allele)
)

if matches_v2_format:
v3_format_allele = self._map_v2_to_v3(allele)
if v3_format_allele != allele:
# If the last field of the allele is alpha, check if it's a MAC
if v3_format_allele.split(":").pop().isalpha():
return self.is_mac(v3_format_allele)
return self._is_valid_allele(v3_format_allele)

return False

def _is_who_allele(self, allele):
"""
Test if allele is a WHO allele in the current imgt database
Expand Down
21 changes: 19 additions & 2 deletions tests/features/version2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@ Feature: Version 2 Nomenclature

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

Scenario Outline:
Scenario Outline: Redux V2 Alleles

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


Examples: Valid A serology typings
Examples: Reduce V2 Alleles
| Version2 | Level | Redux Allele |
| A*0105N | G | A*01:01:01G |
| A*0111 | G | A*01:11N |
| DRB5*02ZB | G | DRB5*01:02:01G/DRB5*01:03/DRB5*02:02:01G/DRB5*02:03/DRB5*02:04 |


Scenario Outline: Invalid V2

Alleles that have valid V2 format but when converted to V3 format,
is not a valid allele.

Given the version 2 typing is <Version2>
When validating the V2 typing
Then the validness of V2 typing is <Validity>

Examples: Validate
| Version2 | Validity |
| A*0105N | Valid |
| DQB1*0804 | Invalid |
| A*01:AB | Valid |
| A*01:NOAB | Invalid |
16 changes: 15 additions & 1 deletion tests/steps/redux_allele.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from behave import given, when, then
from hamcrest import assert_that, is_

from pyard.exceptions import PyArdError
from pyard.exceptions import PyArdError, InvalidAlleleError


@given("the allele as {allele}")
Expand Down Expand Up @@ -72,6 +72,20 @@ def step_impl(context, v2_allele):
context.allele = v2_allele


@when("validating the V2 typing")
def step_impl(context):
try:
context.is_valid = context.ard.validate(context.allele)
except InvalidAlleleError:
context.is_valid = False


@then("the validness of V2 typing is {validity}")
def step_impl(context, validity):
valid = validity == "Valid"
assert_that(context.is_valid, is_(valid))


@given("the typing is {allele}")
def step_impl(context, allele):
context.allele = allele
Expand Down

0 comments on commit c6ce3a7

Please sign in to comment.