Skip to content

Commit 2bc4aa5

Browse files
committed
Fix ping reductions
- Some alleles have dupe reductions e.g. `DPA1*02:12` -> `DPA1*02:02/DPA1*02:07`
1 parent 8ea841e commit 2bc4aa5

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

pyard/ard.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,18 @@ def _redux_allele(
225225
no_suffix_allele = redux_allele
226226
if (
227227
no_suffix_allele == allele
228+
or "/" in no_suffix_allele
228229
or no_suffix_allele in self.ars_mappings.p_not_g.values()
229230
):
230231
return redux_allele
231-
redux_allele = self._redux_allele(
232-
no_suffix_allele, redux_type, True
232+
233+
twice_redux_allele = self._redux_allele(
234+
no_suffix_allele, redux_type, False
233235
)
234-
if self._is_valid_allele(redux_allele):
235-
return redux_allele
236+
if "/" in twice_redux_allele:
237+
return twice_redux_allele
238+
if self._is_valid_allele(twice_redux_allele):
239+
return twice_redux_allele
236240

237241
if redux_type == "G" and allele in self.ars_mappings.g_group:
238242
if allele in self.ars_mappings.dup_g:
@@ -338,6 +342,10 @@ def _redux_allele(
338342
raise InvalidAlleleError(f"{allele} is an invalid allele.")
339343

340344
def _add_lg_suffix(self, redux_allele):
345+
if "/" in redux_allele:
346+
return "/".join(
347+
[self._add_lg_suffix(allele) for allele in redux_allele.split("/")]
348+
)
341349
# ARS suffix maybe used instead of g
342350
if self._config["ARS_as_lg"]:
343351
return redux_allele + "ARS"

tests/features/p_g_group.feature

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ Feature: P and G Groups
1313

1414

1515
Scenario Outline: allele reduction with ping
16-
`ping` is the default.
16+
`ping` is the default.
1717

18-
If there is no G group for the allele, it should use the P group allele.
18+
If there is no G group for the allele, it should use the P group allele.
1919

2020
Given the allele as <Allele>
2121
When reducing on the <Level> level with ping
2222
Then the reduced allele is found to be <Redux Allele>
2323

2424
Examples:
25-
| Allele | Level | Redux Allele |
26-
| C*06:17 | lgx | C*06:02 |
25+
| Allele | Level | Redux Allele |
26+
| C*06:17 | lgx | C*06:02 |
2727

2828
Examples: DRB4*01s
2929
| Allele | Level | Redux Allele |
@@ -83,9 +83,17 @@ Feature: P and G Groups
8383
| DRB4*01:03:02:02 | lgx | DRB4*01:01 |
8484

8585
Examples: C*02:10s
86-
| Allele | Level | Redux Allele |
87-
| C*02:10:02 | lgx | C*02:02 |
88-
| C*02:02 | lg | C*02:02g |
89-
| C*02:02 | lgx | C*02:02 |
90-
| C*02:10 | lg | C*02:02g |
91-
| C*02:10 | lgx | C*02:02 |
86+
| Allele | Level | Redux Allele |
87+
| C*02:10:02 | lgx | C*02:02 |
88+
| C*02:02 | lg | C*02:02g |
89+
| C*02:02 | lgx | C*02:02 |
90+
| C*02:10 | lg | C*02:02g |
91+
| C*02:10 | lgx | C*02:02 |
92+
93+
Examples: lgx with duplicates
94+
| Allele | Level | Redux Allele |
95+
| DPA1*02:12 | lgx | DPA1*02:02/DPA1*02:07 |
96+
| DPA1*02:12 | lg | DPA1*02:02g/DPA1*02:07g |
97+
| DQA1*03:03 | lgx | DQA1*03:01 |
98+
| DQA1*03:03 | lg | DQA1*03:01g |
99+
| DQA1*03:03:09 | lg | DQA1*03:03g |

0 commit comments

Comments
 (0)