2626)
2727from .misc import get_2field_allele , is_2_field_allele
2828from .serology import SerologyMapping
29-
30- default_config = {
31- "reduce_serology" : True ,
32- "reduce_v2" : True ,
33- "reduce_3field" : True ,
34- "reduce_P" : True ,
35- "reduce_XX" : True ,
36- "reduce_MAC" : True ,
37- "reduce_shortnull" : True ,
38- "ping" : True ,
39- "verbose_log" : False ,
40- "ARS_as_lg" : False ,
41- "strict" : True ,
42- "ignore_allele_with_suffixes" : (),
43- }
29+ from .config import ARDConfig
4430
4531
4632class ARD (object ):
@@ -57,9 +43,7 @@ def __init__(
5743 config : dict = None ,
5844 ):
5945 self ._data_dir = data_dir
60- self ._config = default_config .copy ()
61- if config :
62- self ._config .update (config )
46+ self .config = ARDConfig .from_dict (config )
6347
6448 # Initialize specialized handlers
6549 self ._initialize_handlers ()
@@ -160,15 +144,15 @@ def _redux_allele(
160144 self , allele : str , redux_type : VALID_REDUCTION_TYPE , re_ping = True
161145 ) -> str :
162146 """Core allele reduction with ping logic"""
163- if not self ._config [ " strict" ] :
147+ if not self .config . strict :
164148 allele = self ._get_non_strict_allele (allele )
165149
166150 # Handle P/G suffixes
167151 if allele .endswith (("P" , "G" )) and redux_type in ["lg" , "lgx" , "G" ]:
168152 allele = allele [:- 1 ]
169153
170154 # Handle ping mode
171- if self ._config [ " ping" ] and re_ping and redux_type in ("lg" , "lgx" , "U2" ):
155+ if self .config . ping and re_ping and redux_type in ("lg" , "lgx" , "U2" ):
172156 if allele in self .ars_mappings .p_not_g :
173157 not_g_allele = self .ars_mappings .p_not_g [allele ]
174158 if redux_type == "lg" :
@@ -206,8 +190,8 @@ def _redux_non_glstring(
206190 if "*" in allele :
207191 locus , fields = allele .split ("*" )
208192 # Handle ignored allele suffixes
209- if self ._config [ " ignore_allele_with_suffixes" ] :
210- if fields in self ._config [ " ignore_allele_with_suffixes" ] :
193+ if self .config . ignore_allele_with_suffixes :
194+ if fields in self .config . ignore_allele_with_suffixes :
211195 return allele
212196 if locus not in G_GROUP_LOCI :
213197 return allele
@@ -218,9 +202,7 @@ def _redux_non_glstring(
218202 return self .redux (allele , redux_type )
219203
220204 # Handle Serology
221- if self ._config ["reduce_serology" ] and self .serology_handler .is_serology (
222- allele
223- ):
205+ if self .config .reduce_serology and self .serology_handler .is_serology (allele ):
224206 alleles = self .serology_handler .get_alleles_from_serology (allele )
225207 if alleles :
226208 return self .redux ("/" .join (alleles ), redux_type )
@@ -246,7 +228,7 @@ def _redux_non_glstring(
246228
247229 # Handle XX codes
248230 if (
249- self ._config [ " reduce_XX" ]
231+ self .config . reduce_XX
250232 and code == "XX"
251233 and self .xx_handler .is_xx (allele , loc_antigen , code )
252234 ):
@@ -256,17 +238,15 @@ def _redux_non_glstring(
256238 return reduced_alleles
257239
258240 # Handle MAC
259- if self ._config [ " reduce_MAC" ] and code .isalpha ():
241+ if self .config . reduce_MAC and code .isalpha ():
260242 if self .mac_handler .is_mac (allele ):
261243 alleles = self .mac_handler .get_alleles (code , loc_antigen )
262244 return self .redux ("/" .join (alleles ), redux_type )
263245 else :
264246 raise InvalidMACError (f"{ glstring } is an invalid MAC." )
265247
266248 # Handle short nulls
267- if self ._config ["reduce_shortnull" ] and self .shortnull_handler .is_shortnull (
268- allele
269- ):
249+ if self .config .reduce_shortnull and self .shortnull_handler .is_shortnull (allele ):
270250 return self .redux ("/" .join (self .shortnulls [allele ]), redux_type )
271251
272252 redux_allele = self ._redux_allele (allele , redux_type )
@@ -349,7 +329,7 @@ def _get_non_strict_allele(self, allele: str) -> str:
349329 if not self ._is_allele_in_db (allele ):
350330 for expr_char in expression_chars :
351331 if self ._is_allele_in_db (allele + expr_char ):
352- if self ._config [ " verbose_log" ] :
332+ if self .config . verbose_log :
353333 print (f"{ allele } is not valid. Using { allele } { expr_char } " )
354334 allele = allele + expr_char
355335 break
@@ -387,12 +367,12 @@ def _is_valid(self, allele: str) -> bool:
387367 if not alphanum_allele .isalnum ():
388368 return False
389369
390- if self ._config [ " ignore_allele_with_suffixes" ] :
370+ if self .config . ignore_allele_with_suffixes :
391371 locus , fields = allele .split ("*" )
392- if fields in self ._config [ " ignore_allele_with_suffixes" ] :
372+ if fields in self .config . ignore_allele_with_suffixes :
393373 return True
394374
395- if not self ._config [ " strict" ] :
375+ if not self .config . strict :
396376 allele = self ._get_non_strict_allele (allele )
397377
398378 if (
0 commit comments