def test_set_ontology(self):
     ontology = OntologyFactory().create()
     for i in range(4):
         ontology.add_node(i, 'node' + str(i))
     ontology.add_parent(1, 0)
     ontology.add_parent(2, 0)
     ontology.add_parent(3, 0)
     self.df.set_ontology(ontology_type=DataType.GO, ontology=ontology, config=self.conf_parser)
     self.assertTrue(list(self.df.go_ontology.nodes()) == list(ontology.nodes()))
Exemplo n.º 2
0
    def test_set_covering_with_ontology(self):

        #              0                   ic(0) = 0
        #            /| |\
        #           / | | \
        #          1  2 3  4               ic(1) = 0.693147181, ic(2) = 0.470003629, ic(3) = 0.980829253
        #         /\ /\/ \/
        #        /  5 6  7                 ic(5) = 0.980829253, ic(6) = 1.16315081, ic(7) = 1.16315081
        #       /  /\  \/
        #      /  8  9 10                  ic(8) = 1.049822124, ic(10) = 1.252762968
        #      \ / \/   \
        #      11  12   13                 ic(11) = 1.386294361, ic(12) = 1.386294361, ic(13) = 1.386294361

        ontology = OntologyFactory().create()
        for i in range(14):
            ontology.add_node(i, 'node' + str(i))
        ontology.add_parent(1, 0)
        ontology.add_parent(2, 0)
        ontology.add_parent(3, 0)
        ontology.add_parent(4, 0)
        ontology.add_parent(5, 1)
        ontology.add_parent(5, 2)
        ontology.add_parent(6, 2)
        ontology.add_parent(6, 3)
        ontology.add_parent(7, 3)
        ontology.add_parent(7, 4)
        ontology.add_parent(8, 5)
        ontology.add_parent(9, 5)
        ontology.add_parent(10, 6)
        ontology.add_parent(10, 7)
        ontology.add_parent(11, 1)
        ontology.add_parent(11, 8)
        ontology.add_parent(12, 8)
        ontology.add_parent(12, 9)
        ontology.add_parent(13, 10)

        subsets = [
            CommonAncestor(node_id=1,
                           node_label="1",
                           covered_starting_nodes={"11", "12"}),
            CommonAncestor(node_id=2,
                           node_label="2",
                           covered_starting_nodes={"11", "12", "13"}),
            CommonAncestor(node_id=3,
                           node_label="3",
                           covered_starting_nodes={"13"}),
            CommonAncestor(node_id=4,
                           node_label="4",
                           covered_starting_nodes={"13"}),
            CommonAncestor(node_id=5,
                           node_label="2",
                           covered_starting_nodes={"11", "12"}),
            CommonAncestor(node_id=6,
                           node_label="6",
                           covered_starting_nodes={"13"}),
            CommonAncestor(node_id=7,
                           node_label="7",
                           covered_starting_nodes={"13"}),
            CommonAncestor(node_id=8,
                           node_label="8",
                           covered_starting_nodes={"11", "12"}),
            CommonAncestor(node_id=9,
                           node_label="9",
                           covered_starting_nodes={"12"}),
            CommonAncestor(node_id=10,
                           node_label="10",
                           covered_starting_nodes={"13"}),
            CommonAncestor(node_id=11,
                           node_label="11",
                           covered_starting_nodes={"11"}),
            CommonAncestor(node_id=12,
                           node_label="12",
                           covered_starting_nodes={"12"}),
            CommonAncestor(node_id=13,
                           node_label="13",
                           covered_starting_nodes={"13"})
        ]

        values = [1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 100, 1, 1]
        res = find_set_covering(subsets=subsets,
                                ontology=ontology,
                                value=values,
                                max_num_subsets=2)
        self.assertTrue(all([sub[0] != 11 for sub in res]))