Example #1
0
    def test_infer(self):
        """Test inferring child relations."""
        graph = statin_graph.copy()
        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(8, graph.number_of_edges())

        self.assertNotIn(ec_11134, graph[fluvastatin])
        self.assertNotIn(ec_11188, graph[fluvastatin])
        self.assertNotIn(ec_11134, graph[avorastatin])
        self.assertNotIn(ec_11188, graph[avorastatin])
        self.assertNotIn(ec_11134, graph[synthetic_statin])
        self.assertNotIn(ec_11188, graph[synthetic_statin])
        self.assertNotIn(ec_11134, graph[statin])
        self.assertNotIn(ec_11188, graph[statin])
        self.assertNotIn(ec_11134, graph[mevinolinic_acid])
        self.assertNotIn(ec_11188, graph[mevinolinic_acid])
        self.assertIn(ec_11134, graph[hmgcr_inhibitor])
        self.assertIn(ec_11188, graph[hmgcr_inhibitor])

        infer_child_relations(graph, hmgcr_inhibitor)

        self.assertIn(ec_11134, graph[fluvastatin])
        self.assertIn(ec_11188, graph[fluvastatin])
        self.assertIn(ec_11134, graph[avorastatin])
        self.assertIn(ec_11188, graph[avorastatin])
        self.assertIn(ec_11134, graph[synthetic_statin])
        self.assertIn(ec_11188, graph[synthetic_statin])
        self.assertIn(ec_11134, graph[statin])
        self.assertIn(ec_11188, graph[statin])
        self.assertIn(ec_11134, graph[mevinolinic_acid])
        self.assertIn(ec_11188, graph[mevinolinic_acid])
        self.assertIn(ec_11134, graph[hmgcr_inhibitor])
        self.assertIn(ec_11188, graph[hmgcr_inhibitor])

        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(18, graph.number_of_edges())

        infer_child_relations(graph, ec_11134)

        self.assertIn(hmgcr, graph[fluvastatin])
        self.assertIn(hmgcr, graph[avorastatin])
        self.assertIn(hmgcr, graph[synthetic_statin])
        self.assertIn(hmgcr, graph[statin])
        self.assertIn(hmgcr, graph[mevinolinic_acid])
        self.assertIn(hmgcr, graph[hmgcr_inhibitor])

        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(24, graph.number_of_edges())

        self.assertEqual(9,
                         statin_graph.number_of_nodes(),
                         msg='original graph nodes should not be modified')
        self.assertEqual(8,
                         statin_graph.number_of_edges(),
                         msg='original graph edges should not be modified')
Example #2
0
    def test_does_not_redo(self):
        """Test that :func:`propagate_node_relations` does not add the same edges twice."""
        graph = statin_graph.copy()
        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(8, graph.number_of_edges())

        infer_child_relations(graph, hmgcr_inhibitor)
        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(18, graph.number_of_edges())

        infer_child_relations(graph, hmgcr_inhibitor)
        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(18, graph.number_of_edges(), msg='edges should not be added again')
Example #3
0
    def test_infer(self):
        graph = statin_graph.copy()
        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(8, graph.number_of_edges())

        self.assertNotIn(ec_11134.as_tuple(),
                         graph.edge[fluvastatin.as_tuple()])
        self.assertNotIn(ec_11188.as_tuple(),
                         graph.edge[fluvastatin.as_tuple()])
        self.assertNotIn(ec_11134.as_tuple(),
                         graph.edge[avorastatin.as_tuple()])
        self.assertNotIn(ec_11188.as_tuple(),
                         graph.edge[avorastatin.as_tuple()])
        self.assertNotIn(ec_11134.as_tuple(),
                         graph.edge[synthetic_statin.as_tuple()])
        self.assertNotIn(ec_11188.as_tuple(),
                         graph.edge[synthetic_statin.as_tuple()])
        self.assertNotIn(ec_11134.as_tuple(), graph.edge[statin.as_tuple()])
        self.assertNotIn(ec_11188.as_tuple(), graph.edge[statin.as_tuple()])
        self.assertNotIn(ec_11134.as_tuple(),
                         graph.edge[mevinolinic_acid.as_tuple()])
        self.assertNotIn(ec_11188.as_tuple(),
                         graph.edge[mevinolinic_acid.as_tuple()])
        self.assertIn(ec_11134.as_tuple(),
                      graph.edge[hmgcr_inhibitor.as_tuple()])
        self.assertIn(ec_11188.as_tuple(),
                      graph.edge[hmgcr_inhibitor.as_tuple()])

        infer_child_relations(graph, hmgcr_inhibitor)

        self.assertIn(ec_11134.as_tuple(), graph.edge[fluvastatin.as_tuple()])
        self.assertIn(ec_11188.as_tuple(), graph.edge[fluvastatin.as_tuple()])
        self.assertIn(ec_11134.as_tuple(), graph.edge[avorastatin.as_tuple()])
        self.assertIn(ec_11188.as_tuple(), graph.edge[avorastatin.as_tuple()])
        self.assertIn(ec_11134.as_tuple(),
                      graph.edge[synthetic_statin.as_tuple()])
        self.assertIn(ec_11188.as_tuple(),
                      graph.edge[synthetic_statin.as_tuple()])
        self.assertIn(ec_11134.as_tuple(), graph.edge[statin.as_tuple()])
        self.assertIn(ec_11188.as_tuple(), graph.edge[statin.as_tuple()])
        self.assertIn(ec_11134.as_tuple(),
                      graph.edge[mevinolinic_acid.as_tuple()])
        self.assertIn(ec_11188.as_tuple(),
                      graph.edge[mevinolinic_acid.as_tuple()])
        self.assertIn(ec_11134.as_tuple(),
                      graph.edge[hmgcr_inhibitor.as_tuple()])
        self.assertIn(ec_11188.as_tuple(),
                      graph.edge[hmgcr_inhibitor.as_tuple()])

        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(18, graph.number_of_edges())

        infer_child_relations(graph, ec_11134)

        self.assertIn(hmgcr.as_tuple(), graph.edge[fluvastatin.as_tuple()])
        self.assertIn(hmgcr.as_tuple(), graph.edge[avorastatin.as_tuple()])
        self.assertIn(hmgcr.as_tuple(),
                      graph.edge[synthetic_statin.as_tuple()])
        self.assertIn(hmgcr.as_tuple(), graph.edge[statin.as_tuple()])
        self.assertIn(hmgcr.as_tuple(),
                      graph.edge[mevinolinic_acid.as_tuple()])
        self.assertIn(hmgcr.as_tuple(), graph.edge[hmgcr_inhibitor.as_tuple()])

        self.assertEqual(9, graph.number_of_nodes())
        self.assertEqual(24, graph.number_of_edges())

        self.assertEqual(9,
                         statin_graph.number_of_nodes(),
                         msg='original graph nodes should not be modified')
        self.assertEqual(8,
                         statin_graph.number_of_edges(),
                         msg='original graph edges should not be modified')