@@ -40,8 +40,7 @@ import pyard.drbx as drbx
4040
4141
4242def is_serology (allele : str ) -> bool :
43- if len (allele .split (':' )) == 1 :
44- return True
43+ return ard .is_serology (allele )
4544
4645
4746def is_3field (allele : str ) -> bool :
@@ -52,7 +51,11 @@ def is_P(allele: str) -> bool:
5251 if allele .endswith ('P' ):
5352 fields = allele .split (':' )
5453 if len (fields ) == 2 : # Ps are 2 fields
55- return fields [0 ].isdigit () and fields [0 ].isdigit ()
54+ # Check both fields are digits only
55+ # Eg: A*02:01P
56+ # Check last 2 digits of first field: 02 is numeric
57+ # Check digits of seconds field: 01 is numeric
58+ return fields [0 ][- 2 :].isdigit () and fields [1 ][:- 1 ].isdigit ()
5659 return False
5760
5861
@@ -83,6 +86,11 @@ def should_be_reduced(allele, locus_allele):
8386 return False
8487
8588
89+ def remove_locus_name (reduced_allele ):
90+ return "/" .join (map (lambda a : a .split ('*' )[1 ],
91+ reduced_allele .split ('/' )))
92+
93+
8694def reduce (allele , locus , column_name ):
8795 # Does the allele name have the locus in it ?
8896 if allele == '' :
@@ -111,16 +119,23 @@ def reduce(allele, locus, column_name):
111119 if ard_config ["keep_locus_in_allele_name" ]:
112120 allele = reduced_allele
113121 else :
114- allele = "/" .join (map (lambda a : a .split ('*' )[1 ],
115- reduced_allele .split ('/' )))
122+ allele = remove_locus_name (reduced_allele )
116123 else :
117124 if verbose :
118125 print (f"Failed to reduce { locus_allele } " )
119-
120126 if verbose :
121127 print (f"\t { locus_allele } => { allele } " )
122128 else :
123- if ard_config ["keep_locus_in_allele_name" ]:
129+ if ard_config ['convert_v2_to_v3' ]:
130+ if ard .is_v2 (locus_allele ):
131+ v3_allele = ard .v2_to_v3 (locus_allele )
132+ if not ard_config ["keep_locus_in_allele_name" ]:
133+ allele = remove_locus_name (v3_allele )
134+ else :
135+ allele = v3_allele
136+ if verbose :
137+ print (f"\t { locus_allele } => { allele } " )
138+ elif ard_config ["keep_locus_in_allele_name" ]:
124139 allele = locus_allele
125140
126141 return allele
0 commit comments