Skip to content

Commit 0708204

Browse files
committed
MAC lookup error
- Alleles need to be sorted when looking up in database - Allow the given order first
1 parent 35e8f3e commit 0708204

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pyard/ard.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ def expand_mac(self, mac_code: str):
834834

835835
raise InvalidMACError(f"{mac_code} is an invalid MAC.")
836836

837+
@functools.lru_cache()
837838
def lookup_mac(self, allelelist_gl: str):
838839
"""
839840
Finds a MAC code corresponding to
@@ -856,10 +857,18 @@ def lookup_mac(self, allelelist_gl: str):
856857
locus = allelelist_gl.split("*")[0]
857858
return f"{locus}*{antigen_groups[0]}:{mac_code}"
858859

859-
# Try the list of first_field:second_field combinations
860-
mac_expansion = "/".join(sorted(allele_fields))
860+
# Try the given list order first with first_field:second_field combinations
861+
mac_expansion = "/".join(allele_fields)
861862
mac_code = db.alleles_to_mac_code(self.db_connection, mac_expansion)
863+
if mac_code:
864+
locus = allelelist_gl.split("*")[0]
865+
return f"{locus}*{antigen_groups[0]}:{mac_code}"
862866

867+
# Try the sorted list of first_field:second_field combinations
868+
mac_expansion = "/".join(
869+
sorted(allele_fields, key=functools.cmp_to_key(self.smart_sort_comparator))
870+
)
871+
mac_code = db.alleles_to_mac_code(self.db_connection, mac_expansion)
863872
if mac_code:
864873
locus = allelelist_gl.split("*")[0]
865874
return f"{locus}*{antigen_groups[0]}:{mac_code}"

0 commit comments

Comments
 (0)