@@ -355,6 +355,7 @@ def redux(self, allele: str, ars_type: str) -> str:
355355 :return: ARS reduced allele
356356 :rtype: str
357357 """
358+
358359 if re .search ("HLA-" , allele ):
359360 hla , allele_name = allele .split ("-" )
360361 return "-" .join (["HLA" , self .redux (allele_name , ars_type )])
@@ -389,6 +390,9 @@ def redux_gl(self, glstring: str, redux_type: str) -> str:
389390 :rtype: str
390391 """
391392
393+ if not self .isvalid_gl (glstring ):
394+ return ""
395+
392396 if re .search ("\^" , glstring ):
393397 return "^" .join (sorted (set ([self .redux_gl (a , redux_type ) for a in glstring .split ("^" )]), key = functools .cmp_to_key (loci_sort )))
394398
@@ -429,6 +433,42 @@ def redux_gl(self, glstring: str, redux_type: str) -> str:
429433 return self .redux_gl ("/" .join (sorted (alleles , key = functools .cmp_to_key (loci_sort ))), redux_type )
430434 return self .redux (glstring , redux_type )
431435
436+ def isvalid (self , allele : str ) -> str :
437+ """
438+ Determines valididy of an allele
439+
440+ :param allele: An HLA allele.
441+ :type: str
442+ :return: allele or empty
443+ :rtype: boolean
444+ """
445+ v = lambda a : a in self .valid
446+ return v (allele )
447+
448+ def isvalid_gl (self , glstring : str ) -> str :
449+ """
450+ Determine validity of glstring
451+
452+ :param glstring
453+ :type: str
454+ :return: result
455+ :rtype: boolean
456+ """
457+
458+ if re .search ("\^" , glstring ):
459+ return (all (list (map (self .isvalid_gl ,glstring .split ("^" )))))
460+ if re .search ("\|" , glstring ):
461+ return (all (list (map (self .isvalid_gl ,glstring .split ("|" )))))
462+ if re .search ("\+" , glstring ):
463+ return (all (list (map (self .isvalid_gl ,glstring .split ("+" )))))
464+ if re .search ("\~" , glstring ):
465+ return (all (list (map (self .isvalid_gl ,glstring .split ("~" )))))
466+ if re .search ("/" , glstring ):
467+ return (all (list (map (self .isvalid_gl ,glstring .split ("/" )))))
468+
469+ # what falls through here is an allele
470+ return (self .isvalid (glstring ))
471+
432472 def mac_toG (self , allele : str ) -> str :
433473 """
434474 Does ARS reduction with allele and ARS type
0 commit comments