Skip to content

Commit ba50173

Browse files
fixes to unit tests
1 parent 8dbba49 commit ba50173

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

diffxpy/testing/det.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ def _test(self):
789789
# with a normal distribution, for multiple parameters, a chi-square distribution is used.
790790
self.theta_mle = self.model_estim.a_var[self.coef_loc_totest]
791791
if len(self.coef_loc_totest) == 1:
792-
self.theta_mle = self.theta_mle[0] # Make xarray one dimensional for stats.wald_test.
792+
self.theta_mle = self.theta_mle[0]
793793
self.theta_sd = self.model_estim.fisher_inv[:, self.coef_loc_totest[0], self.coef_loc_totest[0]]
794794
self.theta_sd = np.nextafter(0, np.inf, out=self.theta_sd, where=self.theta_sd < np.nextafter(0, np.inf))
795795
self.theta_sd = np.sqrt(self.theta_sd)

diffxpy/unit_test/test_single_de.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,34 @@ def _prepare_data(
2121
"""
2222
if noise_model == "nb":
2323
from batchglm.api.models.glm_nb import Simulator
24+
rand_fn_loc = lambda shape: np.random.uniform(5, 10, shape)
25+
rand_fn_scale = lambda shape: np.random.uniform(1, 2, shape)
2426
elif noise_model == "norm":
2527
from batchglm.api.models.glm_norm import Simulator
28+
rand_fn_loc = lambda shape: np.random.uniform(500, 1000, shape)
29+
rand_fn_scale = lambda shape: np.random.uniform(1, 2, shape)
2630
else:
2731
raise ValueError("noise model %s not recognized" % noise_model)
2832

2933
num_non_de = n_genes // 2
3034
sim = Simulator(num_observations=n_cells, num_features=n_genes)
3135
sim.generate_sample_description(num_batches=0, num_conditions=2)
3236
sim.generate_params(
33-
rand_fn_ave=lambda shape: np.random.poisson(500, shape) + 1,
34-
rand_fn=lambda shape: np.abs(np.random.uniform(1, 0.5, shape))
37+
rand_fn_loc=rand_fn_loc,
38+
rand_fn_scale=rand_fn_scale
3539
)
3640
sim.a_var[1, :num_non_de] = 0
3741
sim.b_var[1, :num_non_de] = 0
3842
self.isDE = np.arange(n_genes) >= num_non_de
3943
sim.generate_data()
40-
4144
return sim
4245

4346
def _eval(self, sim, test):
4447
idx_de = np.where(self.isDE)[0]
4548
idx_nonde = np.where(np.logical_not(self.isDE))[0]
4649

47-
frac_de_of_non_de = np.sum(test.qval[idx_nonde] < 0.05) / len(idx_nonde)
48-
frac_de_of_de = np.sum(test.qval[idx_de] < 0.05) / len(idx_de)
50+
frac_de_of_non_de = np.mean(test.qval[idx_nonde] < 0.05)
51+
frac_de_of_de = np.mean(test.qval[idx_de] < 0.05)
4952

5053
logging.getLogger("diffxpy").info(
5154
'fraction of non-DE genes with q-value < 0.05: %.1f%%' %

diffxpy/unit_test/test_single_null.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ def _test_null_distribution_wald(
2727
"""
2828
if noise_model == "nb":
2929
from batchglm.api.models.glm_nb import Simulator
30+
rand_fn_scale = lambda shape: np.random.uniform(1, 2, shape)
3031
elif noise_model == "norm":
3132
from batchglm.api.models.glm_norm import Simulator
33+
rand_fn_scale = lambda shape: np.random.uniform(1, 2, shape)
3234
else:
3335
raise ValueError("noise model %s not recognized" % noise_model)
3436

3537
sim = Simulator(num_observations=n_cells, num_features=n_genes)
3638
sim.generate_sample_description(num_batches=0, num_conditions=0)
37-
sim.generate()
39+
sim.generate_params(rand_fn_scale=rand_fn_scale)
40+
sim.generate_data()
3841

3942
random_sample_description = pd.DataFrame({
4043
"condition": np.random.randint(2, size=sim.nobs),

0 commit comments

Comments
 (0)