Skip to content

Commit 87776aa

Browse files
added unit test for enrich
1 parent 058ec37 commit 87776aa

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

diffxpy/testing/det.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def summary(
517517
"pval": self.pval,
518518
"qval": self.qval,
519519
"log2fc": self.log2_fold_change(),
520-
"mean": self.mean
520+
"mean": self.mean,
521521
"zero_mean": self.mean == 0
522522
})
523523

@@ -2488,7 +2488,7 @@ def plot_heatmap(
24882488
plt.close(fig)
24892489

24902490
if return_axs:
2491-
return axs
2491+
return ax
24922492
else:
24932493
return
24942494

diffxpy/unit_test/test_enrich.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import unittest
2+
import logging
3+
import numpy as np
4+
import pandas as pd
5+
import scipy.stats as stats
6+
7+
from batchglm.api.models.glm_nb import Simulator
8+
import diffxpy.api as de
9+
10+
11+
class TestEnrich(unittest.TestCase):
12+
13+
def test_for_fatal(self):
14+
"""
15+
"""
16+
logging.getLogger("tensorflow").setLevel(logging.ERROR)
17+
logging.getLogger("batchglm").setLevel(logging.WARNING)
18+
logging.getLogger("diffxpy").setLevel(logging.WARNING)
19+
20+
sim = Simulator(num_observations=50, num_features=10)
21+
sim.generate_sample_description(num_batches=0, num_conditions=2)
22+
sim.generate()
23+
24+
test = de.test.wald(
25+
data=sim.X,
26+
factor_loc_totest="condition",
27+
formula_loc="~ 1 + condition",
28+
sample_description=sim.sample_description,
29+
gene_names=[str(x) for x in range(sim.X.shape[1])],
30+
training_strategy="DEFAULT",
31+
dtype="float64"
32+
)
33+
print(test.gene_ids)
34+
35+
# Set up reference gene sets.
36+
rs = de.enrich.RefSets()
37+
rs.add(id="set1", source="manual", gene_ids=["1", "3"])
38+
rs.add(id="set2", source="manual", gene_ids=["5", "6"])
39+
40+
enrich_test = de.enrich.test(
41+
ref=rs,
42+
det=test,
43+
de_threshold=0.05
44+
)
45+
return True
46+
47+
48+
if __name__ == '__main__':
49+
unittest.main()

diffxpy/unit_test/test_single.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class TestSingleNull(unittest.TestCase):
1212

13-
def test_null_distribution_wald(self, n_cells: int = 2000, n_genes: int = 100):
13+
def test_null_distribution_wald(self, n_cells: int = 2000, n_genes: int = 200):
1414
"""
1515
Test if de.wald() generates a uniform p-value distribution
1616
if it is given data simulated based on the null model. Returns the p-value
@@ -52,7 +52,7 @@ def test_null_distribution_wald(self, n_cells: int = 2000, n_genes: int = 100):
5252

5353
return True
5454

55-
def test_null_distribution_wald_multi(self, n_cells: int = 2000, n_genes: int = 100):
55+
def test_null_distribution_wald_multi(self, n_cells: int = 2000, n_genes: int = 200):
5656
"""
5757
Test if de.wald() (multivariate mode) generates a uniform p-value distribution
5858
if it is given data simulated based on the null model. Returns the p-value
@@ -92,7 +92,7 @@ def test_null_distribution_wald_multi(self, n_cells: int = 2000, n_genes: int =
9292

9393
return True
9494

95-
def test_null_distribution_lrt(self, n_cells: int = 2000, n_genes: int = 100):
95+
def test_null_distribution_lrt(self, n_cells: int = 2000, n_genes: int = 200):
9696
"""
9797
Test if de.lrt() generates a uniform p-value distribution
9898
if it is given data simulated based on the null model. Returns the p-value
@@ -134,7 +134,7 @@ def test_null_distribution_lrt(self, n_cells: int = 2000, n_genes: int = 100):
134134

135135
return True
136136

137-
def test_null_distribution_ttest(self, n_cells: int = 2000, n_genes: int = 100):
137+
def test_null_distribution_ttest(self, n_cells: int = 2000, n_genes: int = 200):
138138
"""
139139
Test if de.t_test() generates a uniform p-value distribution
140140
if it is given data simulated based on the null model. Returns the p-value
@@ -173,7 +173,7 @@ def test_null_distribution_ttest(self, n_cells: int = 2000, n_genes: int = 100):
173173

174174
return True
175175

176-
def test_null_distribution_wilcoxon(self, n_cells: int = 2000, n_genes: int = 100):
176+
def test_null_distribution_wilcoxon(self, n_cells: int = 2000, n_genes: int = 200):
177177
"""
178178
Test if de.wilcoxon() generates a uniform p-value distribution
179179
if it is given data simulated based on the null model. Returns the p-value

0 commit comments

Comments
 (0)