def test_mouse_class2_alleles(): # H2-IAb eq_(parse_allele_name("H2-IAb"), AlleleName("H-2", "IA", "", "b")) eq_(normalize_allele_name("H2-IAb"), "H-2-IAb") eq_(compact_allele_name("H2-IAb"), "IAb") # with hyphen in "H-2" eq_(parse_allele_name("H-2-IAb"), AlleleName("H-2", "IA", "", "b")) eq_(normalize_allele_name("H-2-IAb"), "H-2-IAb") eq_(compact_allele_name("H-2-IAb"), "IAb")
def test_mouse_class1_alleles_H2_Db(): # H2-Db eq_(parse_allele_name("H2-Db"), AlleleName("H-2", "D", "", "b")) eq_(normalize_allele_name("H2-Db"), "H-2-Db") eq_(compact_allele_name("H2-Db"), "Db") # with hyphen in "H-2" eq_(parse_allele_name("H-2-Db"), AlleleName("H-2", "D", "", "b")) eq_(normalize_allele_name("H-2-Db"), "H-2-Db") eq_(compact_allele_name("H-2-Db"), "Db")
def test_mouse_class1_alleles_H2_Kk(): # H2-Kk eq_(parse_allele_name("H2-Kk"), AlleleName("H-2", "K", "", "k")) eq_(normalize_allele_name("H2-Kk"), "H-2-Kk") eq_(compact_allele_name("H-2-Kk"), "Kk") # with a hyphen in "H-2" eq_(parse_allele_name("H-2-Kk"), AlleleName("H-2", "K", "", "k")) eq_(normalize_allele_name("H-2-Kk"), "H-2-Kk") eq_(compact_allele_name("H-2-Kk"), "Kk")
def test_macaque_alleles(): allele_name = "Mamu-B*082:02" eq_(normalize_allele_name(allele_name), "Mamu-B*82:02") eq_(compact_allele_name(allele_name), "B8202") # expect 3rd zero in the family "007" to be trimmed in the normalized form # of this allele allele_name = "Mamu-B*007:02" eq_(normalize_allele_name(allele_name), "Mamu-B*07:02") eq_(compact_allele_name(allele_name), "B0702")
def test_hla_with_3_digit_allele_code(): # B*15:120 eq_(normalize_allele_name("HLA-B*15:120"), "HLA-B*15:120") eq_(compact_allele_name("HLA-B*15:120"), "B15120") eq_(normalize_allele_name("B15120"), "HLA-B*15:120") eq_(compact_allele_name("B15120"), "B15120") # A*02*123 eq_(normalize_allele_name("HLA-A*02:123"), "HLA-A*02:123") eq_(compact_allele_name("HLA-A*02:123"), "A02123") eq_(normalize_allele_name("A02123"), "HLA-A*02:123") eq_(compact_allele_name("A02123"), "A02123")
def get_normalized_allele_name(raw_allele_name: str) -> Optional[str]: """ Try to parse `raw_allele_name` to a normalized compact allele name If `raw_allele_name` cannot be parsed, a warning is logged and `None` is returned. Parameters ---------- raw_allele_name : str The unnormalized allele name Returns ------- compact_allele_name : typing.Optional[str] The normalized, compact allele name, or `None`, if the allele name could not be parsed. """ ret = None try: ret = mhcnames.compact_allele_name(raw_allele_name) except mhcnames.AlleleParseError as ape: logger.warning(ape) return ret
def test_human_class2_alpha_beta(): expected = "HLA-DPA1*01:05-DPB1*100:01" expected_compact = "DPA10105-DPB110001" for name in ["DPA10105-DPB110001", "HLA-DPA1*01:05-DPB1*100:01", "hla-dpa1*0105-dpb1*10001", "dpa1*0105-dpb1*10001", "HLA-DPA1*01:05/DPB1*100:01"]: eq_(normalize_allele_name(name), expected) eq_(compact_allele_name(name), expected_compact)
def test_human_class2_alpha_beta(): expected = "HLA-DPA1*01:05-DPB1*100:01" expected_compact = "DPA10105-DPB110001" for name in ["DPA10105-DPB110001", "HLA-DPA1*01:05-DPB1*100:01", "hla-dpa1*0105-dpb1*10001", "dpa1*0105-dpb1*10001", "HLA-DPA1*01:05/DPB1*100:01", "DPA10105/DPB110001"]: eq_(normalize_allele_name(name), expected) eq_(compact_allele_name(name), expected_compact)
def test_human_class2(): expected = "HLA-DRB1*01:02" expected_compact = "DRB10102" for name in ["DRB1_0102", "DRB101:02", "HLA-DRB1_0102", "DRB10102", "DRB1*0102", "HLA-DRB1*0102", "HLA-DRB1*01:02"]: eq_(normalize_allele_name(name), expected) eq_(compact_allele_name(name), expected_compact)
def test_human_class2(): expected = "HLA-DRA1*01:01-DRB1*01:02" expected_compact = "DRB10102" for name in ["DRB1_0102", "DRB101:02", "HLA-DRB1_0102", "DRB10102", "DRB1*0102", "HLA-DRB1*0102", "HLA-DRB1*01:02", "DRB0102"]: eq_(normalize_allele_name(name), expected) eq_(compact_allele_name(name), expected_compact)
def test_hla_short_names(): expected = "A0201" for name in hla_02_01_names: result = compact_allele_name(name) eq_(result, expected)