@@ -367,6 +367,8 @@ def compute_state_probability_matrix_equation1(fm, bm, ref_h, query_h, rho, mu):
367367 Implement the HMM forward-backward algorithm following Equation 1 of BB2016.
368368 This is simpler than faithfully reimplementing the original BEAGLE 4.1 algorithm.
369369
370+ See the docstring of `compute_state_probability_matrix` for more details.
371+
370372 :param numpy.ndarray fm: Forward probability matrix.
371373 :param numpy.ndarray bm: Backward probability matrix.
372374 :param numpy.ndarray ref_h: Reference haplotypes.
@@ -376,7 +378,24 @@ def compute_state_probability_matrix_equation1(fm, bm, ref_h, query_h, rho, mu):
376378 :return: HMM state probability matrix.
377379 :rtype: numpy.ndarray
378380 """
379- pass
381+ m = ref_h .shape [0 ]
382+ h = ref_h .shape [1 ]
383+ assert m == len (query_h )
384+ assert m == len (rho )
385+ assert m == len (mu )
386+ assert 0 <= np .min (rho ) and np .max (rho ) <= 1
387+ # BEAGLE caps mismatch probabilities at 0.5.
388+ assert 0 <= np .min (mu ) and np .max (mu ) <= 0.5
389+ assert fm .shape == (m , h )
390+ assert bm .shape == (m , h )
391+ # Check all biallelic sites
392+ assert np .all (np .isin (np .unique (ref_h ), [0 , 1 ]))
393+ assert np .all (np .isin (np .unique (query_h ), [- 1 , 0 , 1 ]))
394+ sm = np .zeros ((m , h ), dtype = np .float64 )
395+ for i in np .arange (m - 1 , 0 , - 1 ):
396+ for j in np .arange (h ):
397+ sm [i , j ] = fm [i , j ] * bm [i , j ]
398+ return sm
380399
381400
382401def interpolate_allele_probabilities_equation1 (sm , ref_h , genotyped_pos , imputed_pos ):
0 commit comments