@@ -39,7 +39,7 @@ import pandas as pd
3939import pyard
4040from pyard .db import similar_alleles
4141import pyard .drbx as drbx
42- from pyard .exceptions import PyArdError , InvalidTypingError
42+ from pyard .exceptions import PyArdError , InvalidTypingError , InvalidAlleleError
4343from pyard .misc import get_data_dir , get_imgt_version , download_to_file
4444
4545
@@ -277,10 +277,45 @@ def create_reduced_slug(locus_typ1_typ2_pair):
277277 return typ1
278278
279279
280+ def apply_drbx (gl_string ):
281+ slugs = gl_string .split ("^" )
282+ alleles = [allele for slug in slugs for allele in slug .split ("+" )]
283+ drbx_loci = ("DRB3" , "DRB4" , "DRB5" )
284+
285+ # Filter for DRBX alleles
286+ drbx_alleles = [
287+ allele
288+ for allele in alleles
289+ if any (allele .startswith (locus ) for locus in drbx_loci )
290+ ]
291+
292+ # Create new GL string without DRBX alleles
293+ filtered_slugs = []
294+ for slug in slugs :
295+ non_drbx_alleles = []
296+ for allele in slug .split ("+" ):
297+ if not any (allele .startswith (locus ) for locus in drbx_loci ):
298+ non_drbx_alleles .append (allele )
299+ if non_drbx_alleles :
300+ filtered_slugs .append ("+" .join (non_drbx_alleles ))
301+
302+ new_gl_string = "^" .join (filtered_slugs )
303+
304+ drbx_slug = drbx .map_drbx (drbx_alleles , True )
305+ gl_string_drbx = new_gl_string + "^" + "+" .join (drbx_slug )
306+
307+ return gl_string_drbx
308+
309+
280310def reduce_glstring (glstring : str ) -> str :
281311 try :
282- return ard .redux (glstring , ard_config ["redux_type" ])
283- except InvalidTypingError as e :
312+ ard_redux = ard .redux (glstring , ard_config ["redux_type" ])
313+ if ard_config .get ("map_drb345_to_drbx" ):
314+ glstring_drbx = apply_drbx (ard_redux )
315+ return glstring_drbx
316+ else :
317+ return ard_redux
318+ except (InvalidTypingError , InvalidAlleleError ) as e :
284319 print (f"Error reducing { glstring } \n " , e .message , file = sys .stderr )
285320 return "Failed"
286321
@@ -391,6 +426,9 @@ if __name__ == "__main__":
391426 "reduce_MAC" : ard_config .get ("reduce_MAC" , True ),
392427 "map_drb345_to_drbx" : ard_config .get ("map_drb345_to_drbx" , True ),
393428 "verbose_log" : ard_config .get ("verbose_log" , True ),
429+ "ignore_allele_with_suffixes" : tuple (
430+ ard_config .get ("ignore_allele_with_suffixes" , tuple ())
431+ ),
394432 }
395433 ard = pyard .init (
396434 imgt_version = imgt_version ,
0 commit comments