def test_causal_source(self): g = BELGraph() g.add_edge(1, 2, relation=INCREASES) g.add_edge(2, 3, relation=INCREASES) self.assertTrue(is_causal_source(g, 1)) self.assertFalse(is_causal_central(g, 1)) self.assertFalse(is_causal_sink(g, 1)) self.assertFalse(is_causal_source(g, 2)) self.assertTrue(is_causal_central(g, 2)) self.assertFalse(is_causal_sink(g, 2)) self.assertFalse(is_causal_source(g, 3)) self.assertFalse(is_causal_central(g, 3)) self.assertTrue(is_causal_sink(g, 3))
def test_causal_source(self): g = BELGraph() a, b, c = (protein(n(), n()) for _ in range(3)) g.add_increases(a, b, n(), n()) g.add_increases(b, c, n(), n()) self.assertTrue(is_causal_source(g, a)) self.assertFalse(is_causal_central(g, a)) self.assertFalse(is_causal_sink(g, a)) self.assertFalse(is_causal_source(g, b)) self.assertTrue(is_causal_central(g, b)) self.assertFalse(is_causal_sink(g, b)) self.assertFalse(is_causal_source(g, c)) self.assertFalse(is_causal_central(g, c)) self.assertTrue(is_causal_sink(g, c))
def get_causal_central_nodes(graph, function): """Returns a set of all nodes that have both an in-degree > 0 and out-degree > 0. This means that they are an integral part of a pathway, since they are both produced and consumed. :param pybel.BELGraph graph: A BEL graph :param str function: The BEL function to filter by :return: A set of central ABUNDANCE nodes :rtype: set """ return { node for node, data in graph.iter_node_data_pairs() if data[FUNCTION] == function and is_causal_central(graph, node) }