@@ -134,7 +134,7 @@ def load_default_hla_standards() -> LoadedStandards:
134134 :return: List of known HLA standards
135135 :rtype: list[HLAStandard]
136136 """
137- standards_filename : str = os . path . join (
137+ standards_filename : str = HLAAlgorithm . _path_join_shim (
138138 os .path .dirname (__file__ ),
139139 "default_data" ,
140140 "hla_standards.yaml" ,
@@ -192,6 +192,13 @@ def read_hla_frequencies(
192192 hla_freqs [locus ][protein_pair ] += 1
193193 return hla_freqs
194194
195+ @staticmethod
196+ def _path_join_shim (* args ) -> str :
197+ """
198+ A shim for os.path.join which allows us to mock out the method easily in testing.
199+ """
200+ return os .path .join (* args )
201+
195202 @staticmethod
196203 def load_default_hla_frequencies () -> dict [HLA_LOCUS , dict [HLAProteinPair , int ]]:
197204 """
@@ -201,7 +208,7 @@ def load_default_hla_frequencies() -> dict[HLA_LOCUS, dict[HLAProteinPair, int]]
201208 :rtype: dict[HLA_LOCUS, dict[HLAProteinPair, int]]
202209 """
203210 hla_freqs : dict [HLA_LOCUS , dict [HLAProteinPair , int ]]
204- default_frequencies_filename : str = os . path . join (
211+ default_frequencies_filename : str = HLAAlgorithm . _path_join_shim (
205212 os .path .dirname (__file__ ),
206213 "default_data" ,
207214 "hla_frequencies.csv" ,
@@ -282,9 +289,8 @@ def combine_standards_stepper(
282289 mismatches = combos [combined_std_bin ]
283290
284291 else :
285- seq_mask = np .full_like (std_bin , fill_value = 15 )
286292 # Note that seq is implicitly cast to a NumPy array:
287- mismatches = np .count_nonzero (( std_bin ^ seq ) & seq_mask != 0 )
293+ mismatches = np .count_nonzero (std_bin ^ seq != 0 )
288294 combos [combined_std_bin ] = mismatches # cache this value
289295
290296 if mismatches > current_rejection_threshold :
@@ -335,7 +341,9 @@ def combine_standards(
335341 combined_std_bin ,
336342 mismatches ,
337343 allele_pair ,
338- ) in HLAAlgorithm .combine_standards_stepper (matching_stds , seq , mismatch_threshold ):
344+ ) in HLAAlgorithm .combine_standards_stepper (
345+ matching_stds , seq , mismatch_threshold
346+ ):
339347 if combined_std_bin not in combos :
340348 combos [combined_std_bin ] = (mismatches , [])
341349 combos [combined_std_bin ][1 ].append (allele_pair )
@@ -404,8 +412,8 @@ def get_mismatches(
404412 mislist .append (
405413 HLAMismatch (
406414 index = dex ,
407- observed_base = BIN2NUC [sequence_bin [index ]],
408- expected_base = BIN2NUC [correct_base_bin ],
415+ sequence_base = BIN2NUC [sequence_bin [index ]],
416+ standard_base = BIN2NUC [correct_base_bin ],
409417 )
410418 )
411419
@@ -459,14 +467,13 @@ def interpret(
459467 hla_sequence = hla_sequence ,
460468 matches = {
461469 combined_std : HLAMatchDetails (
462- mismatch_count = mismatch_count ,
463470 mismatches = self .get_mismatches (
464471 combined_std .standard_bin ,
465472 seq ,
466473 locus ,
467474 ),
468475 )
469- for combined_std , mismatch_count in all_combos . items ()
476+ for combined_std in all_combos
470477 },
471478 allele_frequencies = self .hla_frequencies [locus ],
472479 b5701_standards = b5701_standards ,
0 commit comments