Skip to content

Commit 1487e44

Browse files
committed
non-strict mode makes valid alleles by adding expression characters to invalid alleles
1 parent 2f94c3c commit 1487e44

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

pyard/ard.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"map_drb345_to_drbx": True,
5757
"verbose_log": True,
5858
"ARS_as_lg": False,
59+
"strict": True,
5960
}
6061

6162

@@ -181,6 +182,15 @@ def _redux_allele(
181182
else:
182183
return redux_allele
183184

185+
# In non-strict mode, if the allele is not valid,
186+
# try it with expression characters suffixed
187+
if not self._config["strict"] and not self._is_valid_allele(allele):
188+
for expr_char in expression_chars:
189+
if self._is_valid_allele(allele + expr_char):
190+
if self._config["verbose_log"]:
191+
print(f"{allele} is not valid. Using {allele}{expr_char}")
192+
allele = allele + expr_char
193+
184194
# g_group maps alleles to their g_group
185195
# note: this includes mappings for shortened version of alleles
186196
# C*12:02:02:01 => C*12:02:01G
@@ -335,7 +345,8 @@ def redux(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:
335345

336346
validate_reduction_type(redux_type)
337347

338-
self.validate(glstring)
348+
if self._config["strict"]:
349+
self.validate(glstring)
339350

340351
if "^" in glstring:
341352
return self._sorted_unique_gl(

tests/environment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ def before_all(context):
3636
"ARS_as_lg": True,
3737
}
3838
context.ard_ars = pyard.init("3440", data_dir="/tmp/py-ard", config=lg_ars_config)
39+
40+
# use non-strict mode
41+
non_strict_config = {"strict": False}
42+
context.ard_non_strict = pyard.init(
43+
"3440", data_dir="/tmp/py-ard", config=non_strict_config
44+
)

tests/features/allele.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ Feature: Alleles
5757
| DRB1*14:06:01 | lg | DRB1*14:06ARS |
5858
| C*02:02 | lg | C*02:02ARS |
5959
| C*02:10 | lg | C*02:02ARS |
60+
61+
Scenario Outline: Allele reduction in non-strict mode
62+
63+
The canon of HLA Nomenclature includes Deleted Alleles like A*24:329 that were renamed to add an expression character. https://hla.alleles.org/alleles/deleted.html
64+
Such alleles can be included by using non-strict mode where py-ard will try alleles with expression characters when the original allele is not valid
65+
66+
Given the allele as <Allele>
67+
When reducing on the <Level> level in non-strict mode
68+
Then the reduced allele is found to be <Redux Allele>
69+
70+
Examples:
71+
| Allele | Level | Redux Allele |
72+
| A*24:329 | lgx | A*24:329Q |
73+
| DQB1*03:276 | lgx | DQB1*03:01 |

tests/steps/redux_allele.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ def step_impl(context, level):
9292
@then("the expanded allele is found to be {expanded_alleles}")
9393
def step_impl(context, expanded_alleles):
9494
assert_that(context.expanded_alleles, is_(expanded_alleles))
95+
96+
97+
@when("reducing on the {level} level in non-strict mode")
98+
def step_impl(context, level):
99+
context.level = level
100+
context.redux_allele = context.ard_non_strict.redux(context.allele, level)

0 commit comments

Comments
 (0)