Skip to content

Commit 4ab6857

Browse files
author
Richard Liang
committed
All tests passing.
1 parent 68ac01c commit 4ab6857

File tree

3 files changed

+173
-8
lines changed

3 files changed

+173
-8
lines changed

src/easyhla/update_frequency_file_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def from_string(cls, new_name_str: str) -> Self:
8787
field_2_match: Optional[re.Match] = re.match(r"(\d+)[a-zA-Z]*", coords[1])
8888
if field_2_match is None:
8989
raise ValueError(
90-
f"Could not parse {new_name_str} into a proper allele name"
90+
f'Could not parse "{new_name_str}" into a proper allele name'
9191
)
9292
field_2: str = field_2_match.group(1)
9393
return cls(locus, field_1, field_2)

tests/easyhla_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,8 @@ def test_read_hla_standards(
13371337
"14:23,deprecated,57:01,57:03,25:29,40:43",
13381338
"54:32,98:76,57:01,57:03,19:82,19:82",
13391339
"54:32,98:74,57:02,57:03,11:11,22:22",
1340-
"54:32,98:76,57:01,57:03,19:82,unknown",
1341-
"54:32,98:74,unknown,deprecated,11:11,22:22",
1340+
"54:32,98:76,57:01,57:03,19:82,unmapped",
1341+
"54:32,98:74,unmapped,deprecated,11:11,22:22",
13421342
]
13431343

13441344
READ_HLA_FREQUENCIES_TYPICAL_CASE_OUTPUT: dict[HLA_LOCUS, dict[HLAProteinPair, int]] = {
@@ -1443,7 +1443,7 @@ def test_read_hla_standards(
14431443
id="single_row",
14441444
),
14451445
pytest.param(
1446-
["14:23,unknown,57:01,57:03,25:29,40:43"],
1446+
["14:23,unmapped,57:01,57:03,25:29,40:43"],
14471447
{},
14481448
{
14491449
HLAProteinPair(
@@ -1485,7 +1485,7 @@ def test_read_hla_standards(
14851485
id="single_row_b_non_allele",
14861486
),
14871487
pytest.param(
1488-
["14:23,22:33,57:01,57:03,deprecated,unknown"],
1488+
["14:23,22:33,57:01,57:03,deprecated,unmapped"],
14891489
{
14901490
HLAProteinPair(
14911491
first_field_1="14",
@@ -1506,7 +1506,7 @@ def test_read_hla_standards(
15061506
id="single_row_c_non_allele",
15071507
),
15081508
pytest.param(
1509-
["unknown,deprecated,57:01,unknown,deprecated,40:43"],
1509+
["unmapped,deprecated,57:01,unmapped,deprecated,40:43"],
15101510
{},
15111511
{},
15121512
{},

tests/update_frequency_file_lib_test.py

Lines changed: 167 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,18 @@ def test_new_name_from_string_good_cases(
147147
),
148148
],
149149
)
150-
def test_new_name_from_string_exception_cases(new_name_str: str):
150+
def test_new_name_from_string_bad_locus_exception_cases(new_name_str: str):
151151
with pytest.raises(OtherLocusException):
152152
NewName.from_string(new_name_str)
153153

154154

155+
def test_new_name_from_string_cannot_parse_exception():
156+
error_msg: str = 'Could not parse "A*01:fdsa" into a proper allele name'
157+
with pytest.raises(ValueError) as e:
158+
NewName.from_string("A*01:fdsa")
159+
assert error_msg in str(e.value)
160+
161+
155162
@pytest.mark.parametrize(
156163
"locus, field_1, field_2, expected_result",
157164
[
@@ -229,6 +236,17 @@ def test_new_name_to_frequency_format(
229236
[],
230237
id="one_skipped_mapping",
231238
),
239+
pytest.param(
240+
[
241+
("B*505001", "B*50:50:01"),
242+
("B*505002", "B*50:50:02"),
243+
],
244+
{OldName("B", "50", "50"): NewName("B", "50", "50")},
245+
[],
246+
[],
247+
[],
248+
id="two_compatible_mappings_overrides_deprecated",
249+
),
232250
pytest.param(
233251
[
234252
("A*020119", "A*02:01:19"),
@@ -238,6 +256,7 @@ def test_new_name_to_frequency_format(
238256
("B*505001", "None"),
239257
("B*505002", "B*49:32:11"),
240258
("B*570101", "B*57:01:01"),
259+
("B*570111", "B*57:01:11"),
241260
("Cw*223344", "C*22:122"),
242261
("Cw*223445", "None"),
243262
("DPB1*020102", "DPB1*02:01:02"),
@@ -364,7 +383,40 @@ def test_parse_nomenclature(
364383
}
365384
),
366385
Counter(),
367-
id="one_row_all_unmapped",
386+
id="one_row_all_unmapped_no_mappings",
387+
),
388+
pytest.param(
389+
["1234,5678,5701,5603,2233,4455"],
390+
{
391+
OldName("A", "55", "34"): NewName("A", "12", "340"),
392+
OldName("A", "77", "78"): NewName("A", "56", "110"),
393+
OldName("B", "10", "01"): NewName("B", "55", "02"),
394+
OldName("B", "22", "03"): NewName("B", "53", "04"),
395+
OldName("C", "85", "33"): NewName("C", "22", "115"),
396+
OldName("C", "12", "55"): NewName("C", "43", "02"),
397+
},
398+
[
399+
{
400+
"a_first": "unmapped",
401+
"a_second": "unmapped",
402+
"b_first": "unmapped",
403+
"b_second": "unmapped",
404+
"c_first": "unmapped",
405+
"c_second": "unmapped",
406+
},
407+
],
408+
Counter(
409+
{
410+
("A", "1234"): 1,
411+
("A", "5678"): 1,
412+
("B", "5701"): 1,
413+
("B", "5603"): 1,
414+
("C", "2233"): 1,
415+
("C", "4455"): 1,
416+
}
417+
),
418+
Counter(),
419+
id="one_row_all_unmapped_no_mappings_used",
368420
),
369421
pytest.param(
370422
["1234,5678,5701,5603,2233,4455"],
@@ -399,6 +451,119 @@ def test_parse_nomenclature(
399451
),
400452
id="one_row_all_deprecated",
401453
),
454+
pytest.param(
455+
[
456+
"1234,5678,5701,5603,2233,4455",
457+
"1234,5678,6602,6303,2233,5471",
458+
],
459+
{
460+
OldName("A", "12", "34"): NewName("A", "12", "34"),
461+
OldName("A", "56", "78"): NewName(None, "", ""),
462+
OldName("B", "57", "01"): NewName("B", "57", "01"),
463+
OldName("B", "56", "03"): NewName("B", "56", "03"),
464+
OldName("C", "44", "55"): NewName("C", "44", "55"),
465+
OldName("B", "66", "02"): NewName("B", "64", "11"),
466+
OldName("B", "63", "03"): NewName("B", "63", "03"),
467+
OldName("C", "54", "71"): NewName("C", "53", "110"),
468+
},
469+
[
470+
{
471+
"a_first": "12:34",
472+
"a_second": "deprecated",
473+
"b_first": "57:01",
474+
"b_second": "56:03",
475+
"c_first": "unmapped",
476+
"c_second": "44:55",
477+
},
478+
{
479+
"a_first": "12:34",
480+
"a_second": "deprecated",
481+
"b_first": "64:11",
482+
"b_second": "63:03",
483+
"c_first": "unmapped",
484+
"c_second": "53:110",
485+
},
486+
],
487+
Counter({("C", "2233"): 2}),
488+
Counter({("A", "5678"): 2}),
489+
id="two_rows_multiple_deprecated_and_unmapped",
490+
),
491+
pytest.param(
492+
[
493+
"1234,5678,5701,5603,2233,4455",
494+
"5501,7400,5523,5823,1500,1503",
495+
"1111,2222,3333,4444,5555,6666",
496+
"1234,7400,4444,5823,1501,1507",
497+
],
498+
{
499+
OldName("A", "12", "34"): NewName("A", "12", "34"),
500+
OldName("A", "56", "78"): NewName("A", "56", "110"),
501+
OldName("B", "57", "01"): NewName("B", "57", "01"),
502+
OldName("B", "56", "03"): NewName("B", "55", "114"),
503+
OldName("C", "22", "33"): NewName("C", "22", "33"),
504+
OldName("C", "44", "55"): NewName("C", "44", "55"),
505+
OldName("A", "55", "01"): NewName("A", "55", "01"),
506+
OldName("B", "55", "23"): NewName("B", "55", "23"),
507+
OldName("B", "58", "23"): NewName("B", "58", "23"),
508+
OldName("C", "15", "03"): NewName(None, "", ""),
509+
OldName("A", "11", "11"): NewName("A", "10", "223"),
510+
OldName("A", "22", "34"): NewName("A", "22", "35"), # unused
511+
OldName("A", "22", "22"): NewName("A", "19", "190"),
512+
OldName("B", "33", "33"): NewName("B", "33", "33"),
513+
OldName("B", "44", "44"): NewName(None, "", ""),
514+
OldName("C", "55", "55"): NewName("C", "55", "55"),
515+
OldName("C", "66", "66"): NewName("C", "62", "114"),
516+
OldName("C", "15", "01"): NewName("C", "15", "01"),
517+
OldName("C", "15", "07"): NewName("C", "15", "07"),
518+
},
519+
[
520+
{
521+
"a_first": "12:34",
522+
"a_second": "56:110",
523+
"b_first": "57:01",
524+
"b_second": "55:114",
525+
"c_first": "22:33",
526+
"c_second": "44:55",
527+
},
528+
{
529+
"a_first": "55:01",
530+
"a_second": "unmapped",
531+
"b_first": "55:23",
532+
"b_second": "58:23",
533+
"c_first": "unmapped",
534+
"c_second": "deprecated",
535+
},
536+
{
537+
"a_first": "10:223",
538+
"a_second": "19:190",
539+
"b_first": "33:33",
540+
"b_second": "deprecated",
541+
"c_first": "55:55",
542+
"c_second": "62:114",
543+
},
544+
{
545+
"a_first": "12:34",
546+
"a_second": "unmapped",
547+
"b_first": "deprecated",
548+
"b_second": "58:23",
549+
"c_first": "15:01",
550+
"c_second": "15:07",
551+
},
552+
],
553+
Counter(
554+
{
555+
("A", "7400"): 2,
556+
("C", "1500"): 1,
557+
}
558+
),
559+
Counter(
560+
{
561+
("C", "1503"): 1,
562+
("B", "4444"): 2,
563+
}
564+
),
565+
id="typical_case",
566+
),
402567
],
403568
)
404569
def test_update_old_frequencies(

0 commit comments

Comments
 (0)