Skip to content

Commit

Permalink
Refactor interpolate_allele_probabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Sep 13, 2023
1 parent 92b58c8 commit a4a1a04
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions python/tests/beagle_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,13 @@ def interpolate_allele_probabilities(
assert m == len(genotyped_pos)
x = len(imputed_pos)
assert (x, h) == ref_h.shape
genotyped_cm = convert_to_genetic_map_position(genotyped_pos)
imputed_cm = convert_to_genetic_map_position(imputed_pos)
weights, marker_interval_start = get_weights(genotyped_pos, imputed_pos)
assert x == len(weights) == len(marker_interval_start)
p = np.zeros((x, len(alleles)), dtype=np.float64)
# Compute allele probabilities as per Equation 1 in BB2016.
for a in alleles:
for i in np.arange(x):
# Identify the genotyped markers k and k + 1 between the imputed marker i
# The indices k should mirror those in `get_weights`.
if imputed_cm[i] < genotyped_cm[0]:
# Special case: imputed marker is before the first genotyped marker.
k = 0
elif imputed_cm[i] > genotyped_cm[-1]:
# Special case: imputed marker is after the last genotyped marker.
k = m - 1
else:
k = np.max(np.where(imputed_cm[i] > genotyped_cm)[0])
k = marker_interval_start[i]
# Sum over the reference haplotypes where the allele is a at marker i.
has_a = ref_h[i, :] == a
p[i, a] += np.sum(weights[i] * sm[k, has_a])
Expand Down

0 comments on commit a4a1a04

Please sign in to comment.