def test_mock_contents(self): nfkb_complex_tuple = egf_example.nfkb_complex.as_tuple() rela_tuple = egf_example.rela.as_tuple() self.assertIn(nfkb_complex_tuple, self.manager.graphs[0], msg='Graph missing NFKB complex') self.assertIn(rela_tuple, self.manager.graphs[0], msg='Graph missing RELA') self.assertIn(nfkb_complex_tuple, self.manager.hash_to_tuple.values(), msg='NFKB is unindexed') self.assertIn(rela_tuple, self.manager.hash_to_tuple.values(), msg='RELA is unindexed') self.assertIn(hash_node(nfkb_complex_tuple), self.manager.hash_to_tuple.keys(), msg='NFKB is unindexed') self.assertIn(hash_node(rela_tuple), self.manager.hash_to_tuple.keys(), msg='RELA is unindexed')
def test_bound_mutation(self): """Tests when a node is deleted then re-expanded""" pipeline = Pipeline(universe=self.graph) pipeline.append('delete_node_by_hash', hash_node(egf_example.nfkb_complex.as_tuple())) pipeline.append('expand_node_neighborhood_by_hash', hash_node(egf_example.rela.as_tuple())) result = pipeline.run(self.graph, in_place=False) self.check_original_unchanged() self.assertEqual(self.original_number_nodes, result.number_of_nodes()) self.assertGreater(self.original_number_edges, result.number_of_edges())
def test_complex_with_name(self): """Tests a what happens with a named complex .. code-block:: complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:HUS1) complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD1) complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD9A) """ hus1 = protein(namespace='HGNC', name='HUS1') rad1 = protein(namespace='HGNC', name='RAD1') rad9a = protein(namespace='HGNC', name='RAD9A') members = [hus1, rad1, rad9a] nine_one_one = complex_abundance(members=members, namespace='SCOMP', name='9-1-1 Complex') node_tuple = (COMPLEX, ) + tuple(member.as_tuple() for member in members) self.assertEqual(node_tuple, nine_one_one.as_tuple()) self.assertEqual(hash(node_tuple), hash(nine_one_one)) self.assertEqual(hash_node(node_tuple), nine_one_one.as_sha512())
def test_as_tuple(self): namespace, name = n(), n() node_tuple = ABUNDANCE, namespace, name node = abundance(namespace=namespace, name=name) self.assertEqual(node_tuple, node.as_tuple()) self.assertEqual(hash(node_tuple), hash(node)) self.assertEqual(hash_node(node_tuple), node.as_sha512())
def insert_graph(self, graph): """Inserts a graph :param pybel.BELGraph graph: :rtype: Network """ network_id = len(self.graphs) self.graphs.append(graph) self.id_graph[network_id] = graph for node in graph: if not isinstance(node, tuple): raise TypeError(node) self.hash_to_tuple[hash_node(node)] = node return MockNetwork(id=network_id)
def add_identifiers(graph): # FIXME this function shouldn't have to exist. """Adds stable node and edge identifiers to the graph, in-place using the PyBEL node and edge hashes as a hexadecimal str. :param pybel.BELGraph graph: A BEL Graph """ for node, data in graph.iter_node_data_pairs(): if HASH in data: continue canonical_node_tuple = node_to_tuple(data) canonical_node_hash = hash_node(canonical_node_tuple) graph.node[node][HASH] = canonical_node_hash for u, v, k, data in graph.edges_iter(keys=True, data=True): if HASH in data: continue graph.edge[u][v][k][HASH] = hash_edge(u, v, data)