5656 "verbose_log" : True ,
5757}
5858
59+
5960# Typing information
6061
6162
@@ -255,7 +256,7 @@ def _redux_allele(
255256 raise InvalidAlleleError (f"{ allele } is an invalid allele." )
256257
257258 @staticmethod
258- def sorted_unique_gl (gls : List [str ], delim : str ) -> str :
259+ def _sorted_unique_gl (gls : List [str ], delim : str ) -> str :
259260 """
260261 Make a list of sorted unique GL Strings separated by delim.
261262 As the list may itself contains elements that are separated by the
@@ -302,28 +303,28 @@ def redux(self, glstring: str, redux_type: VALID_REDUCTION_TYPES) -> str:
302303
303304 self .validate (glstring )
304305
305- if re . search ( r"\^" , glstring ) :
306- return self .sorted_unique_gl (
306+ if "^" in glstring :
307+ return self ._sorted_unique_gl (
307308 [self .redux (a , redux_type ) for a in glstring .split ("^" )], "^"
308309 )
309310
310- if re . search ( r"\|" , glstring ) :
311- return self .sorted_unique_gl (
311+ if "|" in glstring :
312+ return self ._sorted_unique_gl (
312313 [self .redux (a , redux_type ) for a in glstring .split ("|" )], "|"
313314 )
314315
315- if re . search ( r"\+" , glstring ) :
316- return self .sorted_unique_gl (
316+ if "+" in glstring :
317+ return self ._sorted_unique_gl (
317318 [self .redux (a , redux_type ) for a in glstring .split ("+" )], "+"
318319 )
319320
320- if re . search ( "~" , glstring ) :
321- return self .sorted_unique_gl (
321+ if "~" in glstring :
322+ return self ._sorted_unique_gl (
322323 [self .redux (a , redux_type ) for a in glstring .split ("~" )], "~"
323324 )
324325
325- if re . search ( "/" , glstring ) :
326- return self .sorted_unique_gl (
326+ if "/" in glstring :
327+ return self ._sorted_unique_gl (
327328 [self .redux (a , redux_type ) for a in glstring .split ("/" )], "/"
328329 )
329330
@@ -389,7 +390,7 @@ def validate(self, glstring):
389390 :return: boolean indicating success
390391 """
391392 try :
392- return self .isvalid_gl (glstring )
393+ return self ._is_valid_gl (glstring )
393394 except InvalidAlleleError as e :
394395 raise InvalidTypingError (
395396 f"{ glstring } is not valid GL String. \n { e .message } " , e
@@ -574,9 +575,9 @@ def _map_v2_to_v3(self, v2_allele):
574575 v3_allele = self ._predict_v3 (v2_allele )
575576 return v3_allele
576577
577- def isvalid (self , allele : str ) -> bool :
578+ def _is_valid (self , allele : str ) -> bool :
578579 """
579- Determines validity of an allele
580+ Determines validity of an allele in various forms
580581
581582 :param allele: An HLA allele.
582583 :type: str
@@ -617,7 +618,7 @@ def isvalid(self, allele: str) -> bool:
617618 return self ._is_valid_allele (allele )
618619 return True
619620
620- def isvalid_gl (self , glstring : str ) -> bool :
621+ def _is_valid_gl (self , glstring : str ) -> bool :
621622 """
622623 Determines validity of glstring
623624
@@ -627,62 +628,23 @@ def isvalid_gl(self, glstring: str) -> bool:
627628 :rtype: bool
628629 """
629630
630- if re . search ( r"\^" , glstring ) :
631- return all (map (self .isvalid_gl , glstring .split ("^" )))
632- if re . search ( r"\|" , glstring ) :
633- return all (map (self .isvalid_gl , glstring .split ("|" )))
634- if re . search ( r"\+" , glstring ) :
635- return all (map (self .isvalid_gl , glstring .split ("+" )))
636- if re . search ( "~" , glstring ) :
637- return all (map (self .isvalid_gl , glstring .split ("~" )))
638- if re . search ( "/" , glstring ) :
639- return all (map (self .isvalid_gl , glstring .split ("/" )))
631+ if "^" in glstring :
632+ return all (map (self ._is_valid_gl , glstring .split ("^" )))
633+ if "|" in glstring :
634+ return all (map (self ._is_valid_gl , glstring .split ("|" )))
635+ if "+" in glstring :
636+ return all (map (self ._is_valid_gl , glstring .split ("+" )))
637+ if "~" in glstring :
638+ return all (map (self ._is_valid_gl , glstring .split ("~" )))
639+ if "/" in glstring :
640+ return all (map (self ._is_valid_gl , glstring .split ("/" )))
640641
641642 # what falls through here is an allele
642- is_valid_allele = self .isvalid (glstring )
643+ is_valid_allele = self ._is_valid (glstring )
643644 if not is_valid_allele :
644645 raise InvalidAlleleError (f"{ glstring } is not a valid Allele" )
645646 return is_valid_allele
646647
647- def mac_toG (self , allele : str ) -> str :
648- """
649- Does ARS reduction with allele and ARS type
650-
651- :param allele: An HLA allele.
652- :type: str
653- :return: ARS reduced allele
654- :rtype: str
655- """
656- locus_antigen , code = allele .split (":" )
657- if HLA_regex .search (allele ):
658- locus_antigen = locus_antigen .split ("-" )[1 ] # Remove HLA- prefix
659- if db .is_valid_mac_code (self .db_connection , code ):
660- alleles = self ._get_alleles (code , locus_antigen )
661- group = [self .toG (a ) for a in alleles ]
662- if "X" in group :
663- raise InvalidMACError (f"{ allele } is an invalid MAC." )
664- else :
665- return "/" .join (group )
666- else :
667- raise InvalidMACError (f"{ allele } is an invalid MAC." )
668-
669- def toG (self , allele : str ) -> str :
670- """
671- Does ARS reduction to the G group level
672-
673- :param allele: An HLA allele.
674- :type: str
675- :return: ARS G reduced allele
676- :rtype: str
677- """
678- if allele in self .ars_mappings .g_group :
679- if allele in self .ars_mappings .dup_g :
680- return self .ars_mappings .dup_g [allele ]
681- else :
682- return self .ars_mappings .g_group [allele ]
683- else :
684- return "X"
685-
686648 def expand_mac (self , mac_code : str ):
687649 """
688650 Expands mac codes
0 commit comments