a b/tests/edgepy/test_addPriorCount.py
1
import unittest
2
3
import numpy as np
4
5
from inmoose.edgepy import addPriorCount
6
from inmoose.utils import rnbinom
7
8
9
class test_addPriorCount(unittest.TestCase):
10
    def setUp(self):
11
        y = np.array(rnbinom(80, size=5, mu=20, seed=42)).reshape((20, 4))
12
        self.y = np.vstack(([0, 0, 0, 0], [0, 0, 2, 2], y))
13
14
    def test_addPriorCount(self):
15
        ref = np.array(
16
            [
17
                [0.9275688, 1.042111, 1.053341, 0.9769792],
18
                [0.9275688, 1.042111, 3.053341, 2.9769792],
19
                [25.9275688, 20.042111, 12.053341, 23.9769792],
20
                [10.9275688, 18.042111, 11.053341, 17.9769792],
21
                [14.9275688, 36.042111, 28.053341, 2.9769792],
22
                [15.9275688, 8.042111, 29.053341, 29.9769792],
23
                [20.9275688, 16.042111, 34.053341, 25.9769792],
24
                [7.9275688, 36.042111, 29.053341, 28.9769792],
25
                [15.9275688, 15.042111, 20.053341, 16.9769792],
26
                [5.9275688, 25.042111, 23.053341, 30.9769792],
27
                [35.9275688, 22.042111, 15.053341, 22.9769792],
28
                [13.9275688, 23.042111, 16.053341, 19.9769792],
29
                [34.9275688, 23.042111, 8.053341, 29.9769792],
30
                [30.9275688, 33.042111, 18.053341, 13.9769792],
31
                [26.9275688, 16.042111, 24.053341, 26.9769792],
32
                [20.9275688, 26.042111, 39.053341, 38.9769792],
33
                [17.9275688, 21.042111, 14.053341, 15.9769792],
34
                [9.9275688, 49.042111, 36.053341, 8.9769792],
35
                [41.9275688, 22.042111, 43.053341, 17.9769792],
36
                [39.9275688, 34.042111, 41.053341, 25.9769792],
37
                [21.9275688, 21.042111, 23.053341, 33.9769792],
38
                [17.9275688, 20.042111, 24.053341, 18.9769792],
39
            ]
40
        )
41
        oref = np.full((22, 4), [6.027929, 6.144366, 6.155085, 6.079828])
42
        (yres, offsetres) = addPriorCount(self.y)
43
        self.assertTrue(np.allclose(yres, ref, atol=0, rtol=1e-6))
44
        self.assertTrue(np.allclose(offsetres, oref, atol=0, rtol=1e-6))
45
46
        with self.assertRaisesRegex(
47
            ValueError, expected_regex="count matrix must be numeric"
48
        ):
49
            addPriorCount(np.array(["foo", "bar"]))