Skip to content

Commit 2511167

Browse files
committed
Complete interpolate_allele_probabilities_equation1
1 parent ed4d2a4 commit 2511167

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

python/tests/test_beagle.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,22 +409,21 @@ def compute_state_probability_matrix_equation1(fm, bm, ref_h, query_h, rho, mu):
409409
return sm
410410

411411

412-
def interpolate_allele_probabilities_equation1(
413-
sm, ref_h, query_h, genotyped_pos, imputed_pos
414-
):
412+
def interpolate_allele_probabilities_equation1(sm, ref_h, genotyped_pos, imputed_pos):
415413
"""
416-
Compute the interpolated allele probabilities following Equation 1 of BB2016.
414+
Compute the interpolated allele probabilities at imputed markers
415+
following Equation 1 of BB2016.
417416
418417
This function takes the output of `compute_state_probability_matrix_equation1`.
419418
420419
Assume all biallelic sites.
421420
422-
Note that this function takes the full reference haplotypes and query haplotype,
423-
i.e., not subsetted to genotyped markers.
421+
Note that this function takes:
422+
1) HMM state probability matrix across genotyped markers (size of m).
423+
2) reference haplotypes subsetted to imputed markers (size of x).
424424
425-
:param numpy.ndarray sm: HMM state probability matrix.
426-
:param numpy.ndarray ref_h: Reference haplotypes.
427-
:param numpy.ndarray query_h: One query haplotype.
425+
:param numpy.ndarray sm: HMM state probability matrix at genotyped markers.
426+
:param numpy.ndarray ref_h: Reference haplotypes subsetted to imputed markers.
428427
:param numpy.ndarray genotyped_pos: Site positions at genotyped markers.
429428
:param numpy.ndarray imputed_pos: Site positions at imputed markers.
430429
:return: Interpolated allele probabilities.
@@ -435,7 +434,6 @@ def interpolate_allele_probabilities_equation1(
435434
x = len(imputed_pos)
436435
assert sm.shape == (m, h)
437436
assert ref_h.shape == (m + x, h)
438-
assert len(query_h) == m + x
439437
genotyped_cm = convert_to_genetic_map_position(genotyped_pos)
440438
imputed_cm = convert_to_genetic_map_position(imputed_pos)
441439
weights = get_weights(genotyped_pos, imputed_pos)
@@ -445,15 +443,16 @@ def interpolate_allele_probabilities_equation1(
445443
def _compute_allele_probabilities(a):
446444
"""Equation 1 in BB2016."""
447445
for i in np.arange(x):
446+
# Identify the genotyped markers m and m + 1
447+
# that flank the imputed marker i
448448
if imputed_cm[i] < genotyped_cm[0]:
449449
_m = 0
450450
elif imputed_cm[i] > genotyped_cm[-1]:
451451
_m = -2
452452
else:
453453
_m = np.min(np.where(genotyped_cm > imputed_cm[i]))
454454
for j in np.arange(h):
455-
k = 0 # Index wrt reference markers
456-
if ref_h[k, j] == a:
455+
if ref_h[i, j] == a:
457456
p[i, a] += weights[i] * sm[_m, j]
458457
p[i, a] += (1 - weights[i]) * sm[_m + 1, j]
459458

0 commit comments

Comments
 (0)