@@ -409,22 +409,21 @@ def compute_state_probability_matrix_equation1(fm, bm, ref_h, query_h, rho, mu):
409
409
return sm
410
410
411
411
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 ):
415
413
"""
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.
417
416
418
417
This function takes the output of `compute_state_probability_matrix_equation1`.
419
418
420
419
Assume all biallelic sites.
421
420
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).
424
424
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.
428
427
:param numpy.ndarray genotyped_pos: Site positions at genotyped markers.
429
428
:param numpy.ndarray imputed_pos: Site positions at imputed markers.
430
429
:return: Interpolated allele probabilities.
@@ -435,7 +434,6 @@ def interpolate_allele_probabilities_equation1(
435
434
x = len (imputed_pos )
436
435
assert sm .shape == (m , h )
437
436
assert ref_h .shape == (m + x , h )
438
- assert len (query_h ) == m + x
439
437
genotyped_cm = convert_to_genetic_map_position (genotyped_pos )
440
438
imputed_cm = convert_to_genetic_map_position (imputed_pos )
441
439
weights = get_weights (genotyped_pos , imputed_pos )
@@ -445,15 +443,16 @@ def interpolate_allele_probabilities_equation1(
445
443
def _compute_allele_probabilities (a ):
446
444
"""Equation 1 in BB2016."""
447
445
for i in np .arange (x ):
446
+ # Identify the genotyped markers m and m + 1
447
+ # that flank the imputed marker i
448
448
if imputed_cm [i ] < genotyped_cm [0 ]:
449
449
_m = 0
450
450
elif imputed_cm [i ] > genotyped_cm [- 1 ]:
451
451
_m = - 2
452
452
else :
453
453
_m = np .min (np .where (genotyped_cm > imputed_cm [i ]))
454
454
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 :
457
456
p [i , a ] += weights [i ] * sm [_m , j ]
458
457
p [i , a ] += (1 - weights [i ]) * sm [_m + 1 , j ]
459
458
0 commit comments