Skip to content

Commit

Permalink
Rework tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Mar 26, 2024
1 parent 5befe81 commit aa9aa58
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions tests/test_API_noncopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,30 @@ def get_example_data():
]).T
query_two_switches = np.array([[ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1]])
path_two_switches = np.array([ 0, 0, 0, 1, 1, 1, 2, 2, 2, 2])
# TODO: Add a case with two equally likely paths.
# TODO: Insert missing state at switch position.
# TODO: Insert missing state next to switch position.
# MISSING at switch position
# This causes more than one best paths
H_miss_switch = np.array([
[NC, NC, NC, 0, 0, 0, 0, NC, NC, NC],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]).T
query_miss_switch = np.array([[ 1, 1, 1, -1, 0, 0, 0, 1, 1, 1]])
path_miss_switch = np.array([ 1, 1, 1, 1, 0, 0, 0, 1, 1, 1])
# MISSING left of switch position.
H_miss_next_switch = np.array([
[NC, NC, NC, 0, 0, 0, 0, NC, NC, NC],
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]).T
query_next_switch = np.array([[ 1, 1, -1, 0, 0, 0, 0, 1, 1, 1]])
path_next_switch = np.array([ 1, 1, 1, 0, 0, 0, 0, 1, 1, 1])

return [
(H_only_noncopy, query_only_noncopy, path_only_noncopy),
(H_noncopy_on_right, query_noncopy_on_right, path_noncopy_on_right),
(H_noncopy_on_left, query_noncopy_on_left, path_noncopy_on_left),
(H_noncopy_middle, query_noncopy_middle, path_noncopy_middle),
(H_two_switches, query_two_switches, path_two_switches),
(H_miss_switch, query_miss_switch, path_miss_switch),
(H_miss_next_switch, query_next_switch, path_next_switch),
]


Expand All @@ -104,11 +118,9 @@ def test_forwards_viterbi_hap_naive(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_naive(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V[-1, :], P)
_, _, actual_ll = vh.forwards_viterbi_hap_naive(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -124,11 +136,9 @@ def test_forwards_viterbi_hap_naive_vec(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_naive_vec(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V[-1, :], P)
_, _, actual_ll = vh.forwards_viterbi_hap_naive_vec(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -144,11 +154,9 @@ def test_forwards_viterbi_hap_naive_low_mem(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_naive_low_mem(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V, P)
_, _, actual_ll = vh.forwards_viterbi_hap_naive_low_mem(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -164,11 +172,9 @@ def test_forwards_viterbi_hap_naive_low_mem_rescaling(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_naive_low_mem_rescaling(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V, P)
_, _, actual_ll = vh.forwards_viterbi_hap_naive_low_mem_rescaling(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -184,11 +190,9 @@ def test_forwards_viterbi_hap_low_mem_rescaling(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_low_mem_rescaling(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V, P)
_, _, actual_ll = vh.forwards_viterbi_hap_low_mem_rescaling(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -204,11 +208,9 @@ def test_forwards_viterbi_hap_lower_mem_rescaling(H, s, expected_path):
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

V, P, actual_ll = vh.forwards_viterbi_hap_lower_mem_rescaling(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap(m, V, P)
_, _, actual_ll = vh.forwards_viterbi_hap_lower_mem_rescaling(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)


Expand All @@ -224,9 +226,7 @@ def test_forwards_viterbi_hap_lower_mem_rescaling_no_pointer(H, s, expected_path
n_alleles = _get_num_alleles_per_site(H)
e = _get_emission_probabilities(m, p_mutation, n_alleles)

_, V_argmaxes, recombs, actual_ll = vh.forwards_viterbi_hap_lower_mem_rescaling_no_pointer(n, m, H, s, e, r)
actual_path = vh.backwards_viterbi_hap_no_pointer(m, V_argmaxes, recombs)
_, _, _, actual_ll = vh.forwards_viterbi_hap_lower_mem_rescaling_no_pointer(n, m, H, s, e, r)
expected_ll = vh.path_ll_hap(n, m, H, expected_path, s, e, r)

assert np.array_equal(expected_path, actual_path)
assert np.allclose(expected_ll, actual_ll)

0 comments on commit aa9aa58

Please sign in to comment.