Skip to content

Commit 8dbba49

Browse files
fixed t-test and rank test
1 parent 5a5108e commit 8dbba49

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

diffxpy/testing/det.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ImportError:
1515
anndata = None
1616

17-
from batchglm.models.base import _EstimatorBase
17+
from batchglm.models.base import _EstimatorBase, _InputDataBase
1818

1919
from ..stats import stats
2020
from . import correction
@@ -1518,6 +1518,10 @@ def __init__(
15181518
is_sig_zerovar: bool = True
15191519
):
15201520
super().__init__()
1521+
if isinstance(data, anndata.AnnData) or isinstance(data, anndata.Raw):
1522+
data = data.X
1523+
elif isinstance(data, _InputDataBase):
1524+
data = data.x
15211525
self._x = data
15221526
self.sample_description = sample_description
15231527
self.grouping = grouping
@@ -1652,6 +1656,10 @@ def __init__(
16521656
is_sig_zerovar: bool = True
16531657
):
16541658
super().__init__()
1659+
if isinstance(data, anndata.AnnData) or isinstance(data, anndata.Raw):
1660+
data = data.X
1661+
elif isinstance(data, _InputDataBase):
1662+
data = data.x
16551663
self._x = data
16561664
self.sample_description = sample_description
16571665
self.grouping = grouping
@@ -1680,8 +1688,8 @@ def __init__(
16801688
# TODO: can this be done on sparse?
16811689
pval = np.zeros([data.shape[1]]) + np.nan
16821690
pval[idx_run] = stats.mann_whitney_u_test(
1683-
x0=x0.x[:, idx_run].toarray(),
1684-
x1=x1.x[:, idx_run].toarray()
1691+
x0=np.asarray(x0[:, idx_run]),
1692+
x1=np.asarray(x1[:, idx_run])
16851693
)
16861694
pval[np.where(np.logical_and(
16871695
np.logical_and(mean_x0 == mean_x1, self._mean > 0),

diffxpy/testing/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def lrt(
209209
noise_model="nb",
210210
size_factors: Union[np.ndarray, pd.core.series.Series, np.ndarray] = None,
211211
batch_size: int = None,
212-
training_strategy: Union[str, List[Dict[str, object]], Callable] = "DEFAULT",
212+
training_strategy: Union[str, List[Dict[str, object]], Callable] = "AUTO",
213213
quick_scale: bool = False,
214214
dtype="float64",
215215
**kwargs

diffxpy/testing/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def parse_grouping(data, sample_description, grouping):
103103

104104

105105
def split_x(data, grouping):
106+
grouping = np.asarray(grouping)
106107
groups = np.unique(grouping)
107108
x0 = data[np.where(grouping == groups[0])[0]]
108109
x1 = data[np.where(grouping == groups[1])[0]]

diffxpy/unit_test/test_single_de.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import diffxpy.api as de
66

77

8-
class _TestSingleDE:
8+
class _TestSingleDe:
99

1010
def _prepare_data(
1111
self,
@@ -109,7 +109,7 @@ def _test_t_test_de(
109109
)
110110

111111
test = de.test.t_test(
112-
data=sim.x,
112+
data=sim.input_data,
113113
grouping="condition",
114114
sample_description=sim.sample_description
115115
)
@@ -191,7 +191,7 @@ def _test_lrt_de(
191191
return True
192192

193193

194-
class TestSingleDE_STANDARD(_TestSingleDE, unittest.TestCase):
194+
class TestSingleDeStandard(_TestSingleDe, unittest.TestCase):
195195
"""
196196
Noise model-independent tests unit tests that tests false positive and false negative rates.
197197
"""
@@ -235,7 +235,7 @@ def test_rank_de(
235235
)
236236

237237

238-
class TestSingleDE_NB(_TestSingleDE, unittest.TestCase):
238+
class TestSingleDeNb(_TestSingleDe, unittest.TestCase):
239239
"""
240240
Negative binomial noise model unit tests that tests false positive and false negative rates.
241241
"""
@@ -281,7 +281,7 @@ def test_lrt_de_nb(
281281
)
282282

283283

284-
class TestSingleDE_NORM(_TestSingleDE, unittest.TestCase):
284+
class TestSingleDeNorm(_TestSingleDe, unittest.TestCase):
285285
"""
286286
Normal noise model unit tests that tests false positive and false negative rates.
287287
"""

diffxpy/unit_test/test_single_null.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _test_null_distribution_wald_multi(
101101
training_strategy="DEFAULT",
102102
dtype="float64"
103103
)
104-
summary = test.summary()
104+
_ = test.summary()
105105

106106
# Compare p-value distribution under null model against uniform distribution.
107107
pval_h0 = stats.kstest(test.pval, 'uniform').pvalue
@@ -248,6 +248,7 @@ class TestSingleNullStandard(_TestSingleNull, unittest.TestCase):
248248
Noise model-independent unit tests that test whether a test generates uniformly
249249
distributed p-values if data are sampled from the null model.
250250
"""
251+
251252
def test_null_distribution_ttest(
252253
self,
253254
n_cells: int = 2000,
@@ -291,7 +292,7 @@ def test_null_distribution_rank(
291292
)
292293

293294

294-
class TestSingleNullNB(_TestSingleNull, unittest.TestCase):
295+
class TestSingleNullNb(_TestSingleNull, unittest.TestCase):
295296
"""
296297
Negative binomial noise model unit tests that test whether a test generates uniformly
297298
distributed p-values if data are sampled from the null model.
@@ -365,7 +366,7 @@ def test_null_distribution_lrt_nb(
365366
)
366367

367368

368-
class TestSingleNullNORM(_TestSingleNull, unittest.TestCase):
369+
class TestSingleNullNorm(_TestSingleNull, unittest.TestCase):
369370
"""
370371
Normal noise model unit tests that test whether a test generates uniformly
371372
distributed p-values if data are sampled from the null model.

0 commit comments

Comments
 (0)