Skip to content

Commit

Permalink
Merge pull request #1277 from mild-blue/abragtim/fix-frequency-for-un…
Browse files Browse the repository at this point in the history
…known-hlas

Fix frequency for unknown hlas
  • Loading branch information
kubantjan authored Aug 14, 2024
2 parents 3f2ca22 + 3ed8113 commit b06b604
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
34 changes: 33 additions & 1 deletion tests/web/test_do_crossmatch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,38 @@ def test_do_crossmatch_api_with_different_code_formats(self):
self.assertCountEqual(expected_assumed_hla_types,
res.json['hla_to_antibody'][0]['assumed_hla_types'])

# CASE: donor has unknown HIGH RES code according to our data
json = {
'potential_donor_hla_typing': [[{'hla_code': 'C*07:9999', 'is_frequent': False}]],
'recipient_antibodies': [],
}
with self.app.test_client() as client:
res = client.post(f'{API_VERSION}/{CROSSMATCH_NAMESPACE}/do-crossmatch', json=json,
headers=self.auth_headers)
# since we don't know the SPLIT for this code, we'll leave HIGH RES,
# but designate its frequency as the input
self.assertEqual(200, res.status_code)
expected_assumed_hla_types = [asdict(create_hla_type_with_frequency(
HLATypeWithFrequencyRaw('C*07:9999', is_frequent=False)
))]
self.assertCountEqual(expected_assumed_hla_types,
res.json['hla_to_antibody'][0]['assumed_hla_types'])

# CASE: donor has unknown code in unknown format according to our data
json = {
'potential_donor_hla_typing': [[{'hla_code': '921HLAUNKNWONFORMAT123', 'is_frequent': False}]],
'recipient_antibodies': [],
}
with self.app.test_client() as client:
res = client.post(f'{API_VERSION}/{CROSSMATCH_NAMESPACE}/do-crossmatch', json=json,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
expected_assumed_hla_types = [asdict(create_hla_type_with_frequency(
HLATypeWithFrequencyRaw('921HLAUNKNWONFORMAT123', is_frequent=False)
))]
self.assertCountEqual(expected_assumed_hla_types,
res.json['hla_to_antibody'][0]['assumed_hla_types'])

def test_theoretical_and_double_antibodies(self):
json = {
'potential_donor_hla_typing': [[{'hla_code': 'DPA1*01:03', 'is_frequent': True}],
Expand Down Expand Up @@ -967,7 +999,7 @@ def test_summary(self):
'cutoff': 2000
},
{'mfi': 2000,
'name': 'DPA1*01:02',
'name': 'DPA1*01:07',
'cutoff': 2000}] + type_A_antibodies
}

Expand Down
2 changes: 1 addition & 1 deletion txmatching/utils/hla_system/hla_regexes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import Optional

HIGH_RES_REGEX_STRING = r'^([A-Z]+\d?\*\d{2,4}(:\d{2,3}))(:\d{2,3})*'
HIGH_RES_REGEX_STRING = r'^([A-Z]+\d?\*\d{2,4}(:\d{2,4}))(:\d{2,4})*'
HIGH_RES_REGEX = re.compile(HIGH_RES_REGEX_STRING+r'$') # with high res subunit
HIGH_RES_REGEX_ENDING_WITH_LETTER = re.compile(HIGH_RES_REGEX_STRING+r'([A-Z])$')
HIGH_RES_WITH_SUBUNITS_REGEX = re.compile(r'(DP|DQ)\d?\[(\d{2}:\d{2}),(\d{2}:\d{2})]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def _process_hla_in_high_res(hla_high_res: str, hla_raw_code: str) -> HlaCodePro
)
if exception_split_broad_code is None:
if hla_raw_code in ALL_ULTRA_HIGH_RES_CODES:
return process_parsing_result(hla_raw_code, hla_raw_code, ParsingIssueDetail.UNKNOWN_TRANSFORMATION_FROM_HIGH_RES)
return process_parsing_result(hla_raw_code, None, ParsingIssueDetail.UNKNOWN_TRANSFORMATION_FROM_HIGH_RES)
else:
return process_parsing_result(hla_raw_code, hla_raw_code, ParsingIssueDetail.UNPARSABLE_HLA_CODE)
return process_parsing_result(hla_raw_code, None, ParsingIssueDetail.UNPARSABLE_HLA_CODE)
if isinstance(exception_split_broad_code, ParsingIssueDetail):
return process_parsing_result(hla_raw_code, hla_raw_code, exception_split_broad_code)
if hla_high_res in ALL_HIGH_RES_CODES_WITH_ASSUMED_SPLIT_BROAD_CODE:
Expand Down
5 changes: 5 additions & 0 deletions txmatching/web/api/crossmatch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ def _convert_potential_hla_types_to_low_res(
assumed_hla_types_raw = {HLATypeWithFrequencyRaw(
hla_code=potential_hla_type.hla_type.code.get_low_res_code(),
is_frequent=True
# if the code does not exist in our database and has an unknown format,
# we cannot determine whether it is a high or low res code,
# then leave the is_frequent as it is in the input
if potential_hla_type.hla_type.code.high_res != potential_hla_type.hla_type.code.get_low_res_code()
else potential_hla_type.is_frequent
) for potential_hla_type in potential_hla_types}
assumed_hla_types = [create_hla_type_with_frequency(assumed_hla_type_raw)
for assumed_hla_type_raw in assumed_hla_types_raw
Expand Down

0 comments on commit b06b604

Please sign in to comment.