예제 #1
0
 def test_SetConnection(self):
     """
     Tests if the network file is added
     to the database.
     :return:
     """
     test_config = {
         'host': 'localhost',
         'database': 'test',
         'user': '******',
         'password': '******'
     }
     conn = SetConnection()
     read_config = conn.config
     self.assertTrue(test_config == read_config)
예제 #2
0
 def test_get_union(self):
     """
     Tests if the union of the networks is returned.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     union_set = conn_object.get_union(networks=["g1", "g2"])
     conn_object.delete_tables()
     self.assertTrue(len(union_set.edges), 4)
예제 #3
0
 def test_get_difference(self):
     """
     Tests if the difference is returned with edges that have different weights.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     difference_set = conn_object.get_difference(networks=["g1", "g2"])
     conn_object.delete_tables()
     self.assertEqual(len(difference_set.edges), 3)
예제 #4
0
 def test_aggr_networks(self):
     """
     Tests if network names are aggregated to an edge property
     named 'source'.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     difference_set = conn_object.get_difference(networks=["g1", "g2"])
     conn_object.delete_tables()
     self.assertEqual(
         difference_set.edges[('GG_OTU_1', 'GG_OTU_2')]['source'], 'g1')
예제 #5
0
 def test_get_intersection_3(self):
     """
     Tests if the intersection returns an empty network
     when the intersection is too large.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     intersection_set = conn_object.get_intersection(networks=["g1", "g2"],
                                                     number=3)
     conn_object.delete_tables()
     self.assertEqual(len(intersection_set.edges), 0)
예제 #6
0
 def test_get_intersection_weight(self):
     """
     Tests if the intersection returns the correct number of edges
     when the weight parameter is changed.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     intersection_set = conn_object.get_intersection(networks=["g1", "g2"],
                                                     number=2,
                                                     weight=False)
     conn_object.delete_tables()
     self.assertEqual(len(intersection_set.edges), 3)
예제 #7
0
 def test_get_intersection(self):
     """
     Tests if the import_network function reads the correct database file,
     and imports the network file, by querying the edges table.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     intersection_set = conn_object.get_intersection(networks=["g1", "g2"],
                                                     number=2)
     conn_object.delete_tables()
     self.assertCountEqual(("GG_OTU_2", "GG_OTU_5"),
                           list(intersection_set.edges)[0])
예제 #8
0
 def test_aggr_weight(self):
     """
     Tests if edge weights are aggregated to an edge property
     named 'weight'.
     :return:
     """
     conn_object = BiomConnection()
     conn_object.create_tables()
     conn_object.add_biom(testbiom, 'test')
     conn_object = IoConnection()
     conn_object.add_network(network=g1, name='g1', study='test')
     conn_object.add_network(network=g2, name='g2', study='test')
     conn_object = SetConnection()
     intersection_set = conn_object.get_intersection(networks=["g1", "g2"],
                                                     number=2,
                                                     weight=False)
     conn_object.delete_tables()
     self.assertEqual(
         intersection_set.edges[('GG_OTU_1', 'GG_OTU_2')]['weight'], '1,-1')