Diff of /tests/test_methylation.py [000000] .. [2c420a]

Switch to unified view

a b/tests/test_methylation.py
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
import unittest
4
from singlecellmultiomics.methylation import MethylationCountMatrix
5
6
"""
7
These tests check if the methylation module is working correctly
8
"""
9
10
class TestMethylationCountMatrix(unittest.TestCase):
11
12
    def test_matrix(self):
13
        mA = MethylationCountMatrix()
14
        mA['sample_A', ('chr1', 10, 20)][0] += 1
15
        mA['sample_A', ('chr2', 10, 20)][0] += 2
16
17
        self.assertTrue( len(mA.counts) == 1 )
18
        self.assertEqual(mA.counts['sample_A'].get(('chr1', 10, 20))[0], 1)
19
        self.assertEqual(mA.counts['sample_A'].get(('chr1', 10, 20))[1], 0)
20
        self.assertEqual(mA.counts['sample_A'].get(('chr2', 10, 20))[0], 2)
21
        self.assertEqual(mA.counts['sample_A'].get(('chr2', 10, 20))[1], 0)
22
23
        self.assertEqual(mA.get_bulk_frame('pd').loc[('chr1', 10, 20)].unmethylated , 1.0)
24
        self.assertEqual(mA.get_bulk_frame('pd').loc[('chr1', 10, 20)].methylated , 0)
25
        self.assertEqual(mA.get_bulk_frame('pd').loc[('chr1', 10, 20)].beta , 0 )
26
27
        mB = MethylationCountMatrix()
28
        mB['sample_A', ('chr2', 10, 20)][1] += 2
29
        mB['sample_B', ('chr2', 10, 20)][1] += 1
30
        mB['sample_B', ('chr2', 10, 20)][0] = 2
31
32
        mA.update(mB)
33
        self.assertEqual(len(mA.counts), 2)
34
        self.assertEqual(mA.get_frame('beta')[('chr2', 10, 20)]['sample_A'], 1)
35
        self.assertEqual(mA.get_frame('beta')[('chr2', 10, 20)]['sample_B'], 1 / 3)
36
37
        self.assertEqual(mA.get_bulk_frame()['n_samples'].max(), 2)
38
        self.assertEqual(mA.get_bulk_frame()['n_samples'].min(), 1)
39
        self.assertEqual(mA.get_bulk_frame()['methylated'].sum(), 3)
40
        self.assertEqual(mA.get_bulk_frame()['unmethylated'].sum(), 3)
41
42
43
44
if __name__ == '__main__':
45
    unittest.main()