Exemplo n.º 1
0
 def test_no_variance(self):
     ci = HPOSet([self.ontology[1]])
     assert ci.variance() == (0, 0, 0, [])
Exemplo n.º 2
0
class SetMetricsTests(unittest.TestCase):
    def setUp(self):
        self.ontology = mo.make_ontology()
        self.ci = HPOSet([term for term in self.ontology])

    def test_variance(self):
        with patch.object(HPOTerm,
                          'path_to_other',
                          side_effect=[(1, None), (1, None), (1, None),
                                       (1, None), (1, None), (1, None),
                                       (2, None), (2, None), (2, None),
                                       (2, None), (2, None), (3, None),
                                       (3, None), (3, None), (3, None),
                                       (4, None), (4, None), (4, None),
                                       (5, None), (5, None),
                                       (6, None)]) as mock_pto:
            res = self.ci.variance()
            assert len(res) == 4, len(res)
            assert 1 < res[0] < 7, res[0]
            assert res[1] == 1
            assert res[2] == 6, res[2]
            assert len(res[3]) == 6 + 5 + 4 + 3 + 2 + 1, len(res[3])

            calls = [
                call(self.ci._list[1]),
                call(self.ci._list[2]),
                call(self.ci._list[3]),
                call(self.ci._list[4]),
                call(self.ci._list[5]),
                call(self.ci._list[6]),
                call(self.ci._list[2]),
                call(self.ci._list[3]),
                call(self.ci._list[4]),
                call(self.ci._list[5]),
                call(self.ci._list[6]),
                call(self.ci._list[3]),
                call(self.ci._list[4]),
                call(self.ci._list[5]),
                call(self.ci._list[6]),
                call(self.ci._list[4]),
                call(self.ci._list[5]),
                call(self.ci._list[6]),
                call(self.ci._list[5]),
                call(self.ci._list[6]),
                call(self.ci._list[6])
            ]
            mock_pto.assert_has_calls(calls)

    def test_no_variance(self):
        ci = HPOSet([self.ontology[1]])
        assert ci.variance() == (0, 0, 0, [])

    def test_information_content(self):
        i = 0
        for term in self.ci:
            term.information_content.omim = i
            term.information_content.gene = i * 2
            i += 1
        res = self.ci.information_content()

        assert res['mean'] == 3.0
        assert res['total'] == 21
        assert res['max'] == 6
        assert res['all'] == [0, 1, 2, 3, 4, 5, 6]

        # checking default value
        assert self.ci.information_content() == res

        res = self.ci.information_content('gene')

        assert res['mean'] == 6.0
        assert res['total'] == 42
        assert res['max'] == 12
        assert res['all'] == [0, 2, 4, 6, 8, 10, 12]