def parse_allele_name(name, species_prefix=None):
    original = name
    name = name.strip()

    if len(name) == 0:
        raise ValueError("Can't normalize empty MHC allele name")

    species_from_name, name = split_species_prefix(name)
    if species_prefix:
        if species_from_name:
            raise ValueError("If a species is passed in, we better not have another "
                             "species in the name itself.")
        species = species_prefix
    else:
        species = species_from_name

    if species == "H-2" or species == "H2":
        gene, allele_code = _parse_mouse_allele_name("H-2-" + name)
        # mice don't have allele families
        return AlleleName("H-2", gene, "", allele_code)

    if len(name) == 0:
        raise AlleleParseError("Incomplete MHC allele name: %s" % (original,))
    elif not species:
        # assume that a missing species name means we're dealing with a
        # human HLA allele
        if "-" in name:
            raise AlleleParseError("Can't parse allele name: %s" % original)
        species = "HLA"

    if name[0].upper() == "D":
        # MHC class II genes like "DQA1" need to be parsed with both
        # letters and numbers
        gene, name = _parse_alphanum(name, 4)
    elif name[0].isalpha():
        # if there are more separators to come, then assume the gene names
        # can have the form "DQA1"
        gene, name = _parse_letters(name)
    elif name[0].isdigit():
        gene, name = _parse_numbers(name)
    else:
        raise AlleleParseError(
            "Can't parse gene name from allele: %s" % original)

    if len(gene) == 0:
        raise AlleleParseError("No MHC gene name given in %s" % original)
    if len(name) == 0:
        raise AlleleParseError("Malformed MHC type %s" % original)

    gene = gene.upper()

    # skip initial separator
    sep, name = _parse_separator(name)
    # if all that's left is e.g. "0201" then only parse the
    # first two digits as the family code
    if len(name) == 4:
        family, name = _parse_numbers(name, max_len=2)
    else:
        family, name = _parse_numbers(name, max_len=3)

    sep, name = _parse_separator(name)

    allele_code, name = _parse_numbers(name)

    if len(family) == 1:
        family = "0" + family
    elif len(family) == 3 and family[0] == "0":
        family = family[1:]

    if len(allele_code) == 0:
        allele_code = "01"
    elif len(allele_code) == 1:
        # change HLA-A*2:01 into HLA-A*02:01
        allele_code = "0" + allele_code
    elif len(allele_code) == 3 and allele_code[0] == "0":
        # normalize HLA-A*002:01 into HLA-A*02:01
        allele_code = allele_code[1:]
    return AlleleName(species, gene, family, allele_code)
Takes an allele name and splits it into four parts:
dataset/ETHPy150Open hammerlab/mhctools/mhctools/alleles.py/parse_allele_name