Skip to content

Commit

Permalink
Update remap_alleles
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Feb 26, 2024
1 parent 4d8ca10 commit b0be587
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/tests/beagle_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,23 @@ def get_alleles_at_site(self, i):

def remap_alleles(a):
"""
Helper function.
Helper function to map an allele encoded as a character to an integer.
TODO: Move elsewhere.
:param str allele: Allele.
:return: Recorded allele.
:rtype: int
"""
_ALLELES_ACGT = "ACGT"
b = np.zeros(len(a), dtype=np.int8) - 1
b = np.zeros(len(a), dtype=np.int8) - 1 # Encoded as missing by default
for i in range(len(a)):
if a[i] in [None, ""]:
continue
elif a[i] in _ALLELES_ACGT:
b[i] = _ALLELES_ACGT.index(a[i])
else:
raise AssertionError(f"Unrecognised character: {a[i]}")
raise AssertionError(f"Allele {a[i]} is not recognised.")
return b


Expand Down

0 comments on commit b0be587

Please sign in to comment.