Skip to content

Commit 4059d52

Browse files
committed
WIP
1 parent 5a5d711 commit 4059d52

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

python/tests/test_beagle.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -315,24 +315,6 @@ def compute_state_probability_matrix(fm, bm, ref_h, query_h, rho, mu):
315315
return (sm, fwd_hap_probs, bwd_hap_probs)
316316

317317

318-
def compute_state_probability_matrix_eqn1(fm, bm, ref_h, query_h, rho, mu):
319-
"""
320-
Implement the HMM forward-backward algorithm following Equation 1 of BB2016.
321-
322-
This is simpler than faithfully reimplementing the original BEAGLE 4.1 algorithm.
323-
324-
:param numpy.ndarray fm: Forward probability matrix.
325-
:param numpy.ndarray bm: Backward probability matrix.
326-
:param numpy.ndarray ref_h: Reference haplotypes.
327-
:param numpy.ndarray query_h: One query haplotype.
328-
:param numpy.ndarray rho: Switch probabilities.
329-
:param numpy.ndarray mu: Mismatch probabilities.
330-
:return: HMM state probability matrix.
331-
:rtype: numpy.ndarray
332-
"""
333-
pass
334-
335-
336318
def interpolate_haplotype_probability_matrix(
337319
fwd_hap_probs, bwd_hap_probs, genotyped_pos, imputed_pos
338320
):
@@ -380,6 +362,49 @@ def interpolate_haplotype_probability_matrix(
380362
return i_hap_probs
381363

382364

365+
def compute_state_probability_matrix_equation1(fm, bm, ref_h, query_h, rho, mu):
366+
"""
367+
Implement the HMM forward-backward algorithm following Equation 1 of BB2016.
368+
This is simpler than faithfully reimplementing the original BEAGLE 4.1 algorithm.
369+
370+
:param numpy.ndarray fm: Forward probability matrix.
371+
:param numpy.ndarray bm: Backward probability matrix.
372+
:param numpy.ndarray ref_h: Reference haplotypes.
373+
:param numpy.ndarray query_h: One query haplotype.
374+
:param numpy.ndarray rho: Switch probabilities.
375+
:param numpy.ndarray mu: Mismatch probabilities.
376+
:return: HMM state probability matrix.
377+
:rtype: numpy.ndarray
378+
"""
379+
pass
380+
381+
382+
def interpolate_allele_probabilities_equation1(sm, ref_h, genotyped_pos, imputed_pos):
383+
"""
384+
Compute the interpolated allele probabilities following Equation 1 of BB2016.
385+
386+
Assume all biallelic sites.
387+
388+
:param numpy.ndarray sm: HMM state probability matrix.
389+
:param numpy.ndarray ref_h: Reference haplotypes.
390+
:param numpy.ndarray genotyped_pos: Site positions at genotyped markers.
391+
:param numpy.ndarray imputed_pos: Site positions at imputed markers.
392+
:return: Interpolated allele probabilities.
393+
:rtype: numpy.ndarray
394+
"""
395+
h = ref_h.shape[1]
396+
# m = len(genotyped_pos)
397+
x = len(imputed_pos)
398+
p = np.array((x, 2), dtype=np.float64)
399+
weights = get_weights(genotyped_pos, imputed_pos)
400+
# Compute probabilities of allele a at imputed markers
401+
a = 0
402+
for i in np.arange(x):
403+
for j in np.arange(h):
404+
p[i, a] = weights[i] * sm[i, j] + (1 - weights[i]) * sm[i + 1, j]
405+
return p
406+
407+
383408
def get_map_alleles(i_hap_probs):
384409
"""
385410
Compute the maximum a posteriori alleles at the imputed markers of a query haplotype.

0 commit comments

Comments
 (0)