Beispiel #1
0
 def test_merge_networks(self):
     # Test network manipulation functions
     from nampy.manipulation import manipulation
     the_network = self.model
     the_edges = the_network.edges[0:16]
     the_node_pairs = [x.get_node_pair() for x in the_edges]
     the_node_id_set_both = set([])
     the_node_id_set_1 = set([])
     the_node_id_set_2 = set([])
     the_node_pairs_1 = the_node_pairs[0:10]
     the_node_pairs_2 = the_node_pairs[8:16]
     the_node_ids_1 = []
     all_node_ids = []
     for the_node_pair in the_node_pairs_1:
         the_node_ids_1 += [the_node_pair[0].id, the_node_pair[1].id]
     the_node_ids_2 = []
     for the_node_pair in the_node_pairs_2:            
         the_node_ids_2 += [the_node_pair[0].id, the_node_pair[1].id]
     the_node_ids_1 = list(set(the_node_ids_1))
     the_node_ids_2 = list(set(the_node_ids_2))
     all_node_ids = list(set(the_node_ids_1 + the_node_ids_2))
     the_subnetwork_1 = manipulation.make_subnetwork(the_network, the_node_ids_1, 'subnetwork_1')
     the_subnetwork_2 = manipulation.make_subnetwork(the_network, the_node_ids_2, 'subnetwork_2')
     the_merged_network = manipulation.merge_networks_by_node(the_subnetwork_1, the_subnetwork_2, 'merged_network')
     the_node_ids = [x.id for x in the_merged_network.nodetypes[0].nodes]
     self.assertEqual(set(the_node_ids), set(all_node_ids))        
Beispiel #2
0
 def test_textfile_read_and_propagate(self):
     from nampy.manipulation import manipulation
     from nampy.monopartiteanalysis import prince
     the_network = create_test_model(test_network_file = test_network_text_filename)
     the_node_pairs = [x.get_node_pair() for x in the_network.edges]
     the_node_pairs_1 = the_node_pairs[0:16]
     the_node_ids_1 = []
     for the_node_pair in the_node_pairs_1:
         the_node_ids_1 += [the_node_pair[0].id, the_node_pair[1].id]
     the_node_ids_1 = list(set(the_node_ids_1))
     the_subnetwork_1 = manipulation.make_subnetwork(the_network, the_node_ids_1, 'subnetwork_1')
     for the_node in the_subnetwork_1.nodetypes[0].nodes:
         the_node.source = 1
     the_result, the_permutations = prince.prince(the_subnetwork_1, n_permutations = 10, verbose = False)    
     self.assertEqual(len(the_permutations[the_node_ids_1[0]]), 10)