def test_add_edge_to_network_using_src_target_node_ids(self): net = NiceCXNetwork() src_node = net.create_node('node1') target_node = net.create_node('node2') ne = NetworkEdge(edge_id=1, source_node_id=src_node, target_node_id=target_node, interaction='activates') self.assertEqual(0, len(net.get_edges())) edge_id = ne.add_edge_to_network(net_cx=net) self.assertEqual(1, len(net.get_edges())) nef = NetworkEdgeFactory() new_ne = nef.get_network_edge_from_network(net_cx=net, edge_id=edge_id) self.assertEqual('node1', new_ne.get_source_node_name()) self.assertEqual('node2', new_ne.get_target_node_name()) self.assertEqual(src_node, new_ne.get_source_node_id()) self.assertEqual(target_node, new_ne.get_target_node_id()) self.assertEqual('activates', new_ne.get_interaction()) self.assertEqual([], new_ne.get_attributes()) new_ne.remove_edge_from_network(net_cx=net) self.assertEqual(0, len(net.get_edges()))
def test_remove_edge_from_network(self): net = NiceCXNetwork() src_node = net.create_node('node1') target_node = net.create_node('node2') edge_id = net.create_edge(edge_source=src_node, edge_target=target_node) self.assertEqual(1, len(net.get_edges())) nef = NetworkEdgeFactory() ne = nef.get_network_edge_from_network(net_cx=net, edge_id=edge_id) ne.remove_edge_from_network(net_cx=net) self.assertEqual(0, len(net.get_edges()))
def test_get_edges(self): net = NiceCXNetwork() # Verify correct operation on empty network res = list(net.get_edges()) self.assertEqual(0, len(res)) # add an edge net.create_edge(edge_source=0, edge_target=1) res = list(net.get_edges()) self.assertEqual(1, len(res)) self.assertEqual(res[0], (0, {'@id': 0, 's': 0, 't': 1})) # add another edge net.create_edge(edge_source=1, edge_target=2) res = list(net.get_edges()) self.assertEqual(2, len(res)) self.assertEqual(res[0], (0, {'@id': 0, 's': 0, 't': 1})) self.assertEqual(res[1], (1, {'@id': 1, 's': 1, 't': 2}))
def test_update_no_family_members(self): net = NiceCXNetwork() node1 = net.create_node('node1') node2 = net.create_node('node2') net.create_edge(edge_source=node1, edge_target=node2, edge_interaction='activates') remover = ProteinFamilyNodeMemberRemover() remover.update(net) self.assertEqual(2, len(net.get_nodes())) self.assertEqual(1, len(net.get_edges()))
def test_add_edge_to_network(self): net = NiceCXNetwork() src_node = net.create_node('node1') target_node = net.create_node('node2') attrs = [] attrs.append(Attribute(name='foo', value='ha')) attrs.append(Attribute(name='foo2', value='ha2', data_type='string')) ne = NetworkEdge(edge_id=1, interaction='activates', attributes=attrs) self.assertEqual(0, len(net.get_edges())) edge_id = ne.add_edge_to_network(net_cx=net, source_node_id=src_node, target_node_id=target_node) self.assertEqual(1, len(net.get_edges())) nef = NetworkEdgeFactory() new_ne = nef.get_network_edge_from_network(net_cx=net, edge_id=edge_id) self.assertEqual('node1', new_ne.get_source_node_name()) self.assertEqual('node2', new_ne.get_target_node_name()) self.assertEqual(src_node, new_ne.get_source_node_id()) self.assertEqual(target_node, new_ne.get_target_node_id()) self.assertEqual('activates', new_ne.get_interaction()) self.assertEqual(2, len(new_ne.get_attributes())) a_dict = {} for attr in new_ne.get_attributes(): a_dict[attr.get_name()] = attr self.assertEqual('ha', a_dict['foo'].get_value()) self.assertEqual('ha2', a_dict['foo2'].get_value()) new_ne.remove_edge_from_network(net_cx=net) self.assertEqual(0, len(net.get_edges()))
def test_basic_network_where_neighbor_of_citations_merges_enabled(self): net = NiceCXNetwork() adjud = RedundantEdgeAdjudicator() edge_map = {} nid = net.create_edge(edge_source=0, edge_target=1, edge_interaction='neighbor-of') net.set_edge_attribute(nid, RedundantEdgeAdjudicator.CITATION, ['pubmed:5'], type='list_of_string') cid = net.create_edge(edge_source=0, edge_target=1, edge_interaction='controls-state-change-of') net.set_edge_attribute(cid, RedundantEdgeAdjudicator.CITATION, ['pubmed:6'], type='list_of_string') neighbor_of_map = {} controls_state_change_map = {} other_edge_exists = {} for k, v in net.get_edges(): s = v['s'] t = v['t'] i = v['i'] if i == 'neighbor-of': if not s in neighbor_of_map: neighbor_of_map[s] = {} if not t in neighbor_of_map: neighbor_of_map[t] = {} neighbor_of_map[s][t] = k neighbor_of_map[t][s] = k elif i == 'controls-state-change-of': adjud._add_to_edge_map(controls_state_change_map, k, s, t) else: adjud._add_to_edge_map(other_edge_exists, k, s, t) adjud.remove_and_merge_neighbor_of(net, neighbor_of_map, edge_map) net.print_summary()
def test_remove_node_from_network_with_edges_and_attrs(self): net = NiceCXNetwork() node_id = net.create_node('node1', node_represents='ha') other_node_id = net.create_node('node2', node_represents='ha') edge_id = net.create_edge(edge_source=node_id, edge_target=other_node_id, edge_interaction='activates') net.set_node_attribute(node_id, 'nodeattr', values='foo') net.set_node_attribute(node_id, 'nodeattr2', values='foo2') net.set_edge_attribute(edge_id, 'edgeattr', values='hello') net.set_edge_attribute(edge_id, 'edgeattr2', values='hello2') nef = NetworkNodeFactory() nn = nef.get_network_node_from_network(net_cx=net, node_id=node_id) nn.remove_node_from_network(net_cx=net) self.assertEqual(1, len(net.get_nodes())) self.assertEqual(0, len(net.get_edges()))
NiceCX_creatures.set_edge_attribute(edge_id, attr_name, attr_value) #print(NiceCX_creatures.get_edge_attribute(edge_id, attr_name)) NiceCX_creatures.get_edge_attributes(edge_id) # #### get_edges() # In[ ]: NiceCX_creatures = NiceCXNetwork() #add 3 edges to the network edge_1 = NiceCX_creatures.create_edge("A", "B") edge_2 = NiceCX_creatures.create_edge("C", "D") edge_3 = NiceCX_creatures.create_edge("B", "C") NiceCX_creatures.get_edges() # ##### get_name() # #### set_name(network name) # In[ ]: #create/initial an empty niceCX network before setting the network name NiceCX_creatures = NiceCXNetwork() NiceCX_creatures.set_name("new web") # ##### getSummary() # ##### set_network_attribute(name=None, values=None, type=None, subnetwork_id=None)