From 8e5095af5a781e162d8244df90888bdac7411915 Mon Sep 17 00:00:00 2001 From: Shing Zhan Date: Sun, 24 Mar 2024 18:36:24 +0000 Subject: [PATCH] Remove checking expected number of paths --- tests/test_API_noncopy.py | 98 ++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/tests/test_API_noncopy.py b/tests/test_API_noncopy.py index 403eeb1..31b2202 100644 --- a/tests/test_API_noncopy.py +++ b/tests/test_API_noncopy.py @@ -88,14 +88,14 @@ def get_test_queries_biallelic(): # TODO: Add a case with two equally likely paths. return [ - (query_a3_clone, expected_path_a3_clone, 1), - (query_s0_clone, expected_path_s0_clone, 1), - (query_s1_x_s2, expected_path_s1_x_s2, 1), - (query_s0_x_a1, expected_path_s0_x_a1, 1), - (query_s0_x_a2_x_s0, expected_path_s0_x_a2_x_s0, 1), - (query_a0_x_s0, expected_path_a0_x_s0, 1), - (query_a0_x_s0_miss_a, expected_path_a0_x_s0_miss_a, 1), - (query_a0_x_s0_miss_b, expected_path_a0_x_s0_miss_b, 1), + (query_a3_clone, expected_path_a3_clone), + (query_s0_clone, expected_path_s0_clone), + (query_s1_x_s2, expected_path_s1_x_s2), + (query_s0_x_a1, expected_path_s0_x_a1), + (query_s0_x_a2_x_s0, expected_path_s0_x_a2_x_s0), + (query_a0_x_s0, expected_path_a0_x_s0), + (query_a0_x_s0_miss_a, expected_path_a0_x_s0_miss_a), + (query_a0_x_s0_miss_b, expected_path_a0_x_s0_miss_b), ] @@ -107,156 +107,140 @@ def get_test_queries_multiallelic(): query_m_a3_x_a2_x_s0 = np.array([[ 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]]) expected_path_m_a3_x_a2_x_s0 = np.array([ 3, 3, 3, 2, 2, 2, 2, 4, 4, 4]) # Sample 0 x ancestor 1. - query_s0_x_a1 = np.array([[ 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]]) - expected_path_s0_x_a1 = np.array([ 4, 4, 4, 4, 4, 1, 1, 1, 1, 1]) + query_m_s0_x_a1 = np.array([[ 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]]) + expected_path_m_s0_x_a1 = np.array([ 4, 4, 4, 4, 4, 1, 1, 1, 1, 1]) return [ - (query_m_a3_x_a1, expected_path_m_a3_x_a1, 1), - (query_m_a3_x_a2_x_s0, expected_path_m_a3_x_a2_x_s0, 1), - (query_s0_x_a1, expected_path_s0_x_a1, 1), + (query_m_a3_x_a1, expected_path_m_a3_x_a1), + (query_m_a3_x_a2_x_s0, expected_path_m_a3_x_a2_x_s0), + (query_m_s0_x_a1, expected_path_m_s0_x_a1), ] # Tests for naive matrix-based implementation. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_naive_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_naive_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V, P, _ = vh.forwards_viterbi_hap_naive(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V[-1, :], P) - num_best_paths = np.sum(V[-1, :] == np.max(V[-1, :])) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_naive_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) V, P, _ = vh.forwards_viterbi_hap_naive(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V[-1, :], P) - num_best_paths = np.sum(V[-1, :] == np.max(V[-1, :])) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths # Tests for naive matrix-based implementation using numpy. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_naive_vec_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_naive_vec_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V, P, _ = vh.forwards_viterbi_hap_naive_vec(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V[-1, :], P) - num_best_paths = np.sum(V[-1, :] == np.max(V[-1, :])) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_naive_vec_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) V, P, _ = vh.forwards_viterbi_hap_naive_vec(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V[-1, :], P) - num_best_paths = np.sum(V[-1, :] == np.max(V[-1, :])) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths # Tests for naive matrix-based implementation with reduced memory. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_naive_low_mem_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_naive_low_mem_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V, P, _ = vh.forwards_viterbi_hap_naive_low_mem(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V, P) - num_best_paths = np.sum(V == np.max(V)) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_naive_low_mem_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) V, P, _ = vh.forwards_viterbi_hap_naive_low_mem(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V, P) - num_best_paths = np.sum(V == np.max(V)) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths # Tests for naive matrix-based implementation with reduced memory and rescaling. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_naive_low_mem_rescaling_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_naive_low_mem_rescaling_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V, P, _ = vh.forwards_viterbi_hap_naive_low_mem_rescaling(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V, P) - num_best_paths = np.sum(V == np.max(V)) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_naive_low_mem_rescaling_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) V, P, _ = vh.forwards_viterbi_hap_naive_low_mem_rescaling(n, m, H, query, e, r) best_path = vh.backwards_viterbi_hap(m, V, P) - num_best_paths = np.sum(V == np.max(V)) assert np.array_equal(expected_path, best_path) - assert expected_num_paths == num_best_paths # Tests for implementation with reduced memory and rescaling. # Hereon, compare the log-likelihood of the most likely path with that of the naive implementation # instead of the paths themselves. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_low_mem_rescaling_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_low_mem_rescaling_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V_naive, P_naive, ll_naive = vh.forwards_viterbi_hap_naive(n, m, H, query, e, r) @@ -266,11 +250,11 @@ def test_forwards_viterbi_hap_low_mem_rescaling_biallelic(query, expected_path, @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_low_mem_rescaling_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) @@ -282,10 +266,10 @@ def test_forwards_viterbi_hap_low_mem_rescaling_multiallelic( # Tests for implementation with even more reduced memory and rescaling. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_lower_mem_rescaling_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_lower_mem_rescaling_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V_naive, P_naive, ll_naive = vh.forwards_viterbi_hap_naive(n, m, H, query, e, r) @@ -295,11 +279,11 @@ def test_forwards_viterbi_hap_lower_mem_rescaling_biallelic(query, expected_path @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_lower_mem_rescaling_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True) @@ -311,10 +295,10 @@ def test_forwards_viterbi_hap_lower_mem_rescaling_multiallelic( # Tests for implementation with even more reduced memory and rescaling, without keeping pointers. @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_biallelic() ) -def test_forwards_viterbi_hap_lower_mem_rescaling_no_pointer_biallelic(query, expected_path, expected_num_paths): +def test_forwards_viterbi_hap_lower_mem_rescaling_no_pointer_biallelic(query, expected_path): n, m, H, e, r = get_test_data(use_multiallelic_sites=False) V_naive, P_naive, ll_naive = vh.forwards_viterbi_hap_naive(n, m, H, query, e, r) @@ -324,11 +308,11 @@ def test_forwards_viterbi_hap_lower_mem_rescaling_no_pointer_biallelic(query, ex @pytest.mark.parametrize( - "query, expected_path, expected_num_paths", + "query, expected_path", get_test_queries_multiallelic() ) def test_forwards_viterbi_hap_lower_mem_rescaling_no_pointer_multiallelic( - query, expected_path, expected_num_paths + query, expected_path ): n, m, H, e, r = get_test_data(use_multiallelic_sites=True)