Skip to content

Commit

Permalink
Refactor and add assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Sep 1, 2023
1 parent 32c82a8 commit 8df277f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions python/tests/beagle.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,23 @@ def _compute_state_probability_matrix(fm, bm, ref_h, query_h, rho, mu):
backward haplotype probability matrix.
:rtype: tuple
"""
m = ref_h.shape[0]
h = ref_h.shape[1]
m = fm.shape[0]
h = fm.shape[1]
assert (m, h) == bm.shape
assert not np.any(fm < 0), "Forward probability matrix has negative values."
assert not np.any(np.isnan(fm)), "Forward probability matrix has NaN values."
assert not np.any(bm < 0), "Backward probability matrix has negative values."
assert not np.any(np.isnan(bm)), "Backward probability matrix has NaN values."
assert np.all(
np.isin(ref_h, [0, 1])
), "Reference haplotypes have non-biallelic values."
assert np.all(np.isin(query_h, [0, 1])), "Query haplotype has non-biallelic values."
assert m == len(query_h)
assert m == len(rho)
assert m == len(mu)
assert 0 <= np.min(rho) and np.max(rho) <= 1
# BEAGLE caps mismatch probabilities at 0.5.
assert 0 <= np.min(mu) and np.max(mu) <= 0.5
assert fm.shape == (m, h)
assert bm.shape == (m, h)
# Check all biallelic sites
assert np.all(np.isin(np.unique(ref_h), [0, 1]))
assert np.all(np.isin(np.unique(query_h), [-1, 0, 1]))
sm = np.zeros((m, h), dtype=np.float64) # HMM state probability matrix
sm = np.zeros((m, h), dtype=np.float64)
fwd_hap_probs = np.zeros((m, 4), dtype=np.float64)
bwd_hap_probs = np.zeros((m, 4), dtype=np.float64)
for i in np.arange(m - 1, -1, -1):
Expand Down

0 comments on commit 8df277f

Please sign in to comment.