#NEWLINE# def normalize_allele_name( raw_allele ) : #NEWLINE# #INDENT# 'MHC alleles are named with a frustratingly loose system. It\'s not uncommon\n    to see dozens of different forms for the same allele.\n\n    Note: this function works with both class I and class II allele names (including\n    alpha/beta pairs).\n\n    For example, these all refer to the same MHC sequence:\n        - HLA-A*02:01\n        - HLA-A02:01\n        - HLA-A:02:01\n        - HLA-A0201\n        - HLA-A00201\n\n    Additionally, for human alleles, the species prefix is often omitted:\n        - A*02:01\n        - A*00201\n        - A*0201\n        - A02:01\n        - A:02:01\n        - A:002:01\n        - A0201\n        - A00201\n\n    We might also encounter "6 digit" and "8 digit" MHC types (which specify\n    variants that don\'t affect amino acid sequence), for our purposes these\n    should be truncated to their "4-digit" forms:\n        - A*02:01:01\n        - A*02:01:01:01\n    There are also suffixes which we\'re going to ignore:\n        - HLA-A*02:01:01G\n\n    And lastly, for human alleles, there are serotypes which we\'ll treat\n    as approximately equal to a 4-digit type.\n        - HLA-A2\n        - A2\n\n    These should all be normalized to:\n        HLA-A*02:01\n    ' #NEWLINE# if ( raw_allele in _normalized_allele_cache ) : #NEWLINE# #INDENT# return _normalized_allele_cache [ raw_allele ] #NEWLINE# #UNINDENT# parsed_alleles = parse_classi_or_classii_allele_name ( raw_allele ) #NEWLINE# species = parsed_alleles [ 0 ] . species #NEWLINE# normalized_list = [ species ] #NEWLINE# for parsed_allele in parsed_alleles : #NEWLINE# #INDENT# if ( len ( parsed_allele . allele_family ) > 0 ) : #NEWLINE# #INDENT# normalized_list . append ( ( '%s*%s:%s' % ( parsed_allele . gene , parsed_allele . allele_family , parsed_allele . allele_code ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# normalized_list . append ( ( '%s%s' % ( parsed_allele . gene , parsed_allele . allele_code ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# normalized = '-' . join ( normalized_list ) #NEWLINE# _normalized_allele_cache [ raw_allele ] = normalized #NEWLINE# return normalized