[b44cdf]: / tests / deseq2 / test_methods.py

Download this file

40 lines (35 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import unittest
import numpy as np
import pandas as pd
from inmoose.deseq2 import DESeqDataSet
from inmoose.utils import Factor
class Test(unittest.TestCase):
def test_method_errors(self):
"""test that methods throw errors"""
coldata = pd.DataFrame({"x": Factor(["A", "A", "B", "B"])})
counts = np.arange(1, 17).reshape((4, 4))
dds = DESeqDataSet(counts, coldata, "~x")
with self.assertLogs("inmoose", level="WARNING") as logChecker:
dds.counts(replaced=True)
self.assertRegex(
logChecker.output[0],
"There is no layer named 'replacedCounts', using original.",
)
with self.assertRaisesRegex(
ValueError,
expected_regex="first calculate size factors, add normalizationFactors, or set normalized=False",
):
dds.counts(normalized=True)
with self.assertRaisesRegex(
ValueError, expected_regex="size factors should be positive"
):
dds.sizeFactors = [-1, -1, -1, -1]
with self.assertRaisesRegex(
ValueError, expected_regex="normalization factors should be positive"
):
dds.normalizationFactors = np.full((4, 4), -1)
with self.assertRaisesRegex(
ValueError,
expected_regex="first call estimateSizeFactors or provide a normalizationFactor matrix before calling estimateDispersions",
):
dds.estimateDispersions()