Exemplo n.º 1
0
    def test_multiple(self):
        """Test building a node predicate with multiple functions."""
        f = function_inclusion_filter_builder([GENE, PROTEIN])

        p1 = protein(n(), n())
        g1 = gene(n(), n())
        b1 = bioprocess(n(), n())

        g = BELGraph()
        g.add_node_from_data(p1)
        g.add_node_from_data(g1)
        g.add_node_from_data(b1)

        self.assertIn(p1, g)
        self.assertIn(g1, g)
        self.assertIn(b1, g)

        self.assertTrue(f(g, p1))
        self.assertTrue(f(g, g1))
        self.assertFalse(f(g, b1))

        f = invert_node_predicate(f)

        self.assertFalse(f(g, p1))
        self.assertFalse(f(g, g1))
        self.assertTrue(f(g, b1))
Exemplo n.º 2
0
def remove_nodes_by_function(graph: BELGraph, func: Strings) -> None:
    """Remove nodes with the given function.

    This could be useful directly to remove pathologies.
    """
    return remove_filtered_nodes(graph,
                                 function_inclusion_filter_builder(func))
Exemplo n.º 3
0
    def test_single(self):
        """Test building a node predicate with a single function."""
        f = function_inclusion_filter_builder(GENE)

        p1 = protein(n(), n())
        g1 = gene(n(), n())

        g = BELGraph()
        g.add_node_from_data(p1)
        g.add_node_from_data(g1)

        self.assertIn(p1, g)
        self.assertIn(g1, g)

        self.assertFalse(f(g, p1))
        self.assertTrue(f(g, g1))

        f = invert_node_predicate(f)

        self.assertTrue(f(g, p1))
        self.assertFalse(f(g, g1))
Exemplo n.º 4
0
 def test_empty_list_error(self):
     """Test that a value error is thrown for an empty list."""
     with self.assertRaises(ValueError):
         function_inclusion_filter_builder([])
Exemplo n.º 5
0
 def test_type_error(self):
     """Test that a type error is thrown for an invalid argument type."""
     with self.assertRaises(TypeError):
         function_inclusion_filter_builder(5)