Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37d86c8

Browse files
authored
Merge pull request #12 from cfe-lab/FoldClinicalIn
Fixed a mis-identified precondition that doesn't always hold relating to #11
2 parents af4045e + fa4e4b6 commit 37d86c8

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/hla_algorithm/models.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,14 @@ def _identify_longest_prefix(allele_prefixes: list[GeneCoord]) -> GeneCoord:
427427
"""
428428
Identify the longest gene coordinate "prefix" in the given allele prefixes.
429429
430-
Precondition: that the input must all share at least the same first
431-
coordinate. The algorithm may not return cogent values if not.
432-
433-
Precondition: the specified allele prefixes do not all perfectly match,
434-
so we lose nothing by trimming one coordinate off the end of all of
435-
them.
430+
Precondition: all allele prefixes in the input must all share at least
431+
the same first coordinate. The algorithm may not return cogent values
432+
if not.
436433
"""
437434
longest_prefix: GeneCoord = ()
438435
if len(allele_prefixes) > 0:
439436
max_length: int = max([len(allele) for allele in allele_prefixes])
440-
for i in range(max_length - 1, 0, -1):
437+
for i in range(max_length, 0, -1):
441438
curr_prefixes: set[GeneCoord] = {allele[0:i] for allele in allele_prefixes}
442439
if len(curr_prefixes) == 1:
443440
longest_prefix = curr_prefixes.pop()

tests/models_test.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,31 @@ def test_identify_clean_prefix_in_pairs(
12061206
(),
12071207
id="trivial_case",
12081208
),
1209-
# Note: we have no single allele tests because that contradicts one
1210-
# of our preconditions.
1209+
pytest.param(
1210+
[("C*01", "02", "03", "04G")],
1211+
("C*01", "02", "03", "04G"),
1212+
id="single_input_length_4",
1213+
),
1214+
pytest.param(
1215+
[("C*01", "02", "03")],
1216+
("C*01", "02", "03"),
1217+
id="single_input_length_3",
1218+
),
1219+
pytest.param(
1220+
[("C*01", "02")],
1221+
("C*01", "02"),
1222+
id="single_input_length_2",
1223+
),
1224+
pytest.param(
1225+
[("C*01",)],
1226+
("C*01",),
1227+
id="single_input_length_1",
1228+
),
1229+
pytest.param(
1230+
[("C*01", "02", "03", "04G"), ("C*01", "02", "03", "04G")],
1231+
("C*01", "02", "03", "04G"),
1232+
id="best_match_length_4",
1233+
),
12111234
pytest.param(
12121235
[("C*01", "02", "03", "04G"), ("C*01", "02", "03", "110N")],
12131236
("C*01", "02", "03"),
@@ -1248,6 +1271,11 @@ def test_identify_clean_prefix_in_pairs(
12481271
("C*01",),
12491272
id="best_match_length_1_different_lengths_one_with_no_excess",
12501273
),
1274+
pytest.param(
1275+
[("C*01", "07", "88"), ("C*01", "07", "01"), ("C*01", "07", "01", "110N")],
1276+
("C*01", "07"),
1277+
id="typical_case",
1278+
),
12511279
],
12521280
)
12531281
def test_identify_longest_prefix(

0 commit comments

Comments
 (0)