Skip to content

Commit 69cff76

Browse files
committed
Cover corner cases in tests
1 parent c306d01 commit 69cff76

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

tests/integration_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ def setUpClass(cls):
2727
scvelo.tl.velocity_embedding(adata)
2828
cls.__adata = adata
2929

30-
@parameterized.expand([['neighbors', 2], ['velocities', None], ['velocities', 2],
31-
['velocities-explicit', None]])
32-
def test_run_hypothesis_test_on_pancreas(self, null_distribution, cosine_empty_neighborhood):
30+
@parameterized.expand([['neighbors', 2, None], ['neighbors', 2, 10], ['velocities', None, None],
31+
['velocities', None, 10], ['velocities', 2, None], ['velocities', 2, 10],
32+
['velocities-explicit', None, None], ['velocities-explicit', None, 10]])
33+
def test_run_hypothesis_test_on_pancreas(self, null_distribution, cosine_empty_neighborhood, exclusion_degree):
3334
adata = self.__adata.copy()
3435

3536
# Run test
3637
uncorrected_p_values, h0_rejected, _ = run_hypothesis_test_on(adata, number_neighborhoods=100,
3738
number_neighbors_to_sample_from=20,
3839
null_distribution=null_distribution,
39-
cosine_empty_neighborhood=cosine_empty_neighborhood)
40+
cosine_empty_neighborhood=cosine_empty_neighborhood,
41+
exclusion_degree=exclusion_degree)
4042
assert uncorrected_p_values.shape[0] == adata.n_obs
4143
assert h0_rejected.shape[0] == adata.n_obs
4244
if null_distribution == 'neighbors':

tests/test_test_statistic_function.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def test_matching_p_values_old_implementation(self, exclusion_deg):
7272
number_neighbors_to_sample_from=15,
7373
null_distribution="velocities",
7474
cosine_empty_neighborhood=None,
75-
exclusion_degree=exclusion_deg)
75+
exclusion_degree=exclusion_deg,
76+
restrict_to_velocity_genes=False)
7677
p_values_explicit, _ = run_explicit_test_from(adata, number_neighbors_to_sample_from=15,
7778
exclusion_gamma_deg=exclusion_deg)
7879

velotest/hypothesis_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ def run_hypothesis_test(
262262

263263
if null_distribution == 'neighbors' or null_distribution == 'velocities':
264264
debug_dict['neighborhoods_all'] = neighborhoods
265-
if cosine_empty_neighborhood is not None:
265+
if isinstance(test_statistics, torch.Tensor):
266266
test_statistics_velocity = test_statistics[:, 0]
267267
test_statistics_random = test_statistics[:, 1:]
268268
else:
269269
test_statistics_velocity = [test_statistic[0] for test_statistic in test_statistics]
270270
test_statistics_random = [test_statistic[1:] for test_statistic in test_statistics]
271-
if cosine_empty_neighborhood is not None:
271+
if isinstance(test_statistics, torch.Tensor):
272272
p_values_ = p_values(test_statistics_velocity, test_statistics_random).numpy()
273273
else:
274274
p_values_ = p_values_list(test_statistics_velocity, test_statistics_random).numpy()

velotest/test_statistic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def mean_cos_directionality_varying_neighbors(expression: torch.Tensor,
9696
number_neighborhoods = len(neighborhoods[0])
9797
if cosine_empty_neighborhood is not None:
9898
mean_cos_neighborhoods = torch.zeros((number_cells, number_neighborhoods))
99-
used_neighborhoods = None
99+
used_neighborhoods = torch.ones((number_cells, number_neighborhoods), dtype=torch.bool)
100100
else:
101101
mean_cos_neighborhoods = []
102102
used_neighborhoods = torch.ones((number_cells, number_neighborhoods), dtype=torch.bool)

0 commit comments

Comments
 (0)