11import csv
2- import os
32from collections .abc import Generator , Iterable , Sequence
43from datetime import datetime
54from io import TextIOBase
65from operator import attrgetter
6+ from pathlib import Path
77from typing import Final , Optional , TypedDict , cast
88
99import numpy as np
@@ -49,6 +49,8 @@ class HLAAlgorithm:
4949
5050 COLUMN_IDS : Final [dict [str , int ]] = {"A" : 0 , "B" : 2 , "C" : 4 }
5151
52+ DEFAULT_CONFIG_DIR : Final [Path ] = Path (__file__ ).parent / "default_data"
53+
5254 def __init__ (
5355 self ,
5456 loaded_standards : Optional [LoadedStandards ] = None ,
@@ -136,12 +138,7 @@ def load_default_hla_standards() -> LoadedStandards:
136138 :return: List of known HLA standards
137139 :rtype: list[HLAStandard]
138140 """
139- standards_filename : str = HLAAlgorithm ._path_join_shim (
140- os .path .dirname (__file__ ),
141- "default_data" ,
142- "hla_standards.yaml" ,
143- )
144- with open (standards_filename ) as standards_file :
141+ with open (HLAAlgorithm .DEFAULT_CONFIG_DIR / "hla_standards.yaml" ) as standards_file :
145142 return HLAAlgorithm .read_hla_standards (standards_file )
146143
147144 FREQUENCY_LOCUS_COLUMNS : dict [HLA_LOCUS , tuple [str , str ]] = {
@@ -194,13 +191,6 @@ def read_hla_frequencies(
194191 hla_freqs [locus ][protein_pair ] += 1
195192 return hla_freqs
196193
197- @staticmethod
198- def _path_join_shim (* args ) -> str :
199- """
200- A shim for os.path.join which allows us to mock out the method easily in testing.
201- """
202- return os .path .join (* args )
203-
204194 @staticmethod
205195 def load_default_hla_frequencies () -> dict [HLA_LOCUS , dict [HLAProteinPair , int ]]:
206196 """
@@ -210,12 +200,7 @@ def load_default_hla_frequencies() -> dict[HLA_LOCUS, dict[HLAProteinPair, int]]
210200 :rtype: dict[HLA_LOCUS, dict[HLAProteinPair, int]]
211201 """
212202 hla_freqs : dict [HLA_LOCUS , dict [HLAProteinPair , int ]]
213- default_frequencies_filename : str = HLAAlgorithm ._path_join_shim (
214- os .path .dirname (__file__ ),
215- "default_data" ,
216- "hla_frequencies.csv" ,
217- )
218- with open (default_frequencies_filename , "r" ) as f :
203+ with open (HLAAlgorithm .DEFAULT_CONFIG_DIR / "hla_frequencies.csv" ) as f :
219204 hla_freqs = HLAAlgorithm .read_hla_frequencies (f )
220205 return hla_freqs
221206
0 commit comments