Skip to content

Commit 8cd9d74

Browse files
author
rhliang
committed
Fixed all existing tests and removed some seemingly unnecessary "config" files.
To do: add new tests to cover all the new code, and convert the existing config CSV files (which are intentionally an old version, and used in bblab) to our YAML format.
1 parent 8ed2114 commit 8cd9d74

File tree

12 files changed

+100590
-101064
lines changed

12 files changed

+100590
-101064
lines changed

src/easyhla/bblab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def process_from_file_to_files(
8888

8989
log_and_print(
9090
f"Run commencing {time_start.strftime(DATE_FORMAT)}. "
91-
f"Allele definitions last updated {hla_alg.last_modified}.",
91+
f"Allele definitions last updated {hla_alg.last_updated}.",
9292
to_stdout=to_stdout,
9393
)
9494

src/easyhla/default_data/hla_a_seq.csv

Lines changed: 0 additions & 192 deletions
This file was deleted.

src/easyhla/default_data/hla_b_seq.csv

Lines changed: 0 additions & 199 deletions
This file was deleted.

src/easyhla/default_data/hla_c_seq.csv

Lines changed: 0 additions & 202 deletions
This file was deleted.

src/easyhla/default_data/hla_standards.yaml

Lines changed: 100166 additions & 100163 deletions
Large diffs are not rendered by default.

src/easyhla/easyhla.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
class LoadedStandards(TypedDict):
3333
tag: str
34-
last_modified: datetime
34+
last_updated: datetime
3535
standards: dict[HLA_LOCUS, dict[str, HLAStandard]]
3636

3737

@@ -63,7 +63,7 @@ def __init__(
6363
self.hla_standards: dict[HLA_LOCUS, dict[str, HLAStandard]] = loaded_standards[
6464
"standards"
6565
]
66-
self.last_modified: datetime = loaded_standards["last_modified"]
66+
self.last_updated: datetime = loaded_standards["last_updated"]
6767
self.tag: str = loaded_standards["tag"]
6868

6969
self.hla_frequencies: dict[HLA_LOCUS, dict[HLAProteinPair, int]]
@@ -121,7 +121,7 @@ def read_hla_standards(standards_io: TextIOBase) -> LoadedStandards:
121121

122122
return {
123123
"tag": stored_stds.tag,
124-
"last_modified": stored_stds.last_modified,
124+
"last_updated": stored_stds.last_updated,
125125
"standards": hla_stds,
126126
}
127127

@@ -161,8 +161,8 @@ def read_hla_frequencies(
161161
"B": {},
162162
"C": {},
163163
}
164-
for locus in ("A", "B", "C"):
165-
for line in frequencies_io.readlines():
164+
for line in frequencies_io.readlines():
165+
for locus in ("A", "B", "C"):
166166
column_id = EasyHLA.COLUMN_IDS[locus]
167167
line_array = line.strip().split(",")[column_id : column_id + 2]
168168

@@ -429,7 +429,7 @@ def interpret(
429429
b5701_standards: Optional[list[HLAStandard]] = None
430430
if locus == "B":
431431
b5701_standards = [
432-
self.hla_standards[allele] for allele in self.B5701_ALLELES
432+
self.hla_standards[locus][allele] for allele in self.B5701_ALLELES
433433
]
434434

435435
return HLAInterpretation(
@@ -440,10 +440,11 @@ def interpret(
440440
mismatches=self.get_mismatches(
441441
combined_std.standard_bin,
442442
seq,
443+
locus,
443444
),
444445
)
445446
for combined_std, mismatch_count in all_combos.items()
446447
},
447-
allele_frequencies=self.hla_frequencies,
448+
allele_frequencies=self.hla_frequencies[locus],
448449
b5701_standards=b5701_standards,
449450
)

src/easyhla/models.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import re
22
from collections.abc import Iterable
33
from operator import itemgetter
4-
from typing import Optional
4+
from typing import Optional, Self
55

66
import numpy as np
77
from pydantic import BaseModel, ConfigDict
88

9-
from .utils import HLA_LOCUS, allele_coordinates, bin2nuc, count_forgiving_mismatches
9+
from .utils import (
10+
HLA_LOCUS,
11+
HLARawStandard,
12+
allele_coordinates,
13+
bin2nuc,
14+
count_forgiving_mismatches,
15+
nuc2bin,
16+
)
1017

1118

1219
class HLASequence(BaseModel):
@@ -52,6 +59,14 @@ def sequence(self) -> tuple[int, ...]:
5259
def sequence_np(self) -> np.ndarray:
5360
return np.array(self.sequence)
5461

62+
@classmethod
63+
def from_raw_standard(cls, raw_standard: HLARawStandard) -> Self:
64+
return cls(
65+
allele=raw_standard.allele,
66+
two=nuc2bin(raw_standard.exon2),
67+
three=nuc2bin(raw_standard.exon3),
68+
)
69+
5570

5671
class HLAStandardMatch(HLAStandard):
5772
mismatch: int

src/easyhla/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections import defaultdict
55
from collections.abc import Iterable, Sequence
66
from datetime import datetime
7-
from operator import attrgetter
87
from typing import Final, Literal, Optional, Self
98

109
import numpy as np
@@ -487,8 +486,7 @@ def group_identical_alleles(
487486
logger.info(
488487
f"[{', '.join(grouped_allele.alleles)}] -> {grouped_allele.name}"
489488
)
490-
491-
return sorted(grouped_alleles, key=attrgetter("name"))
489+
return grouped_alleles
492490

493491

494492
def compute_stored_standard_checksum(
@@ -532,3 +530,4 @@ def compute_compare_checksum(self) -> Self:
532530
else:
533531
if self.checksum != checksum:
534532
raise ValueError("Checksum mismatch")
533+
return self

tests/bblab_lib_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
HLASequence,
1818
HLAStandard,
1919
)
20-
from easyhla.utils import EXON_NAME, HLA_LOCUS, nuc2bin
20+
from easyhla.utils import EXON_NAME, HLA_LOCUS, HLARawStandard, nuc2bin
2121

2222
from .clinical_hla_lib_test import DUMMY_FREQUENCIES, dummy_hla_sequence, dummy_matches
23-
from .easyhla_test import HLA_STANDARDS, DummyStandard
23+
from .easyhla_test import HLA_STANDARDS
2424

2525

2626
@pytest.mark.parametrize(
@@ -732,7 +732,7 @@ def test_pair_exons(
732732
paired_seqs: list[HLASequence]
733733
unmatched: dict[EXON_NAME, dict[str, Seq]]
734734

735-
current_standard: DummyStandard = HLA_STANDARDS[locus]
735+
current_standard: HLARawStandard = HLA_STANDARDS[locus]
736736
fake_standard: HLAStandard = HLAStandard(
737737
allele=current_standard.allele,
738738
two=nuc2bin(current_standard.exon2),

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Tuple
22

3-
from easyhla import EasyHLA
3+
from easyhla.easyhla import EasyHLA
44

55

66
def make_comparison(easyhla: EasyHLA, ref_seq: str, test_seq: str) -> str:

0 commit comments

Comments
 (0)