Switch to unified view

a b/tests/deseq2/test_DESeq.py
1
import unittest
2
3
import patsy
4
5
from inmoose.deseq2 import DESeq, makeExampleDESeqDataSet
6
from inmoose.utils import Factor
7
8
9
class Test(unittest.TestCase):
10
    def test_DESeq(self):
11
        """test that DESeq() gives correct errors"""
12
        dds = makeExampleDESeqDataSet(n=100, m=8)
13
        with self.assertRaisesRegex(
14
            ValueError,
15
            expected_regex="likelihood ratio test requires a 'reduced' design",
16
        ):
17
            DESeq(dds, test="LRT")
18
        with self.assertRaisesRegex(
19
            ValueError, expected_regex="'reduced' ignored when test='Wald'"
20
        ):
21
            DESeq(dds, test="Wald", full="~condition", reduced="~1")
22
        with self.assertRaisesRegex(
23
            ValueError,
24
            expected_regex="'full' specified as formula should match obj.design",
25
        ):
26
            DESeq(dds, full="~1")
27
28
        m = patsy.dmatrix("~condition", dds.obs)
29
        with self.assertRaisesRegex(
30
            ValueError,
31
            expected_regex="if one of 'full' or 'reduced' is a matrix, the other must also be a matrix",
32
        ):
33
            DESeq(dds, test="LRT", full=m, reduced="~1")
34
        with self.assertRaisesRegex(
35
            ValueError,
36
            expected_regex="the number of columns of 'full' should be larger than the number of columns of 'reduced'",
37
        ):
38
            DESeq(dds, test="LRT", full=m, reduced=m)
39
        with self.assertRaisesRegex(
40
            ValueError,
41
            expected_regex="'betaPrior'=True is not supported for user-provided model matrices",
42
        ):
43
            DESeq(dds, full=m, betaPrior=True)
44
45
        dds.design = "~0 + condition"
46
        with self.assertRaisesRegex(
47
            ValueError,
48
            expected_regex="betaPrior=True can only be used if the design has an intercept. If not, use betaPrior=False",
49
        ):
50
            DESeq(dds, betaPrior=True)
51
52
        dds = makeExampleDESeqDataSet(n=100)
53
        dds.obs["condition"] = Factor(dds.obs["condition"]).add_categories("C")
54
        dds.design = "~condition"
55
        with self.assertRaisesRegex(
56
            ValueError, expected_regex="full model matrix is not full rank"
57
        ):
58
            DESeq(dds)