def test_make_edges_from_predictions(self): """tests the make_edges_from_predictions function""" predictions = [('gene1', 'gene2'), ('gene2', 'gene3')] organism = MockOrganism( '64091', { 'gene1': st.Feature('feature1', 'typ1', 'feature_name1', st.Location('contig1', 24, 89, False)), 'gene2': st.Feature('feature2', 'typ1', 'feature_name2', st.Location('contig1', 15, 21, False)), 'gene3': st.Feature('feature3', 'typ2', 'feature_name3', st.Location('contig1', 100, 154, False)) }) edges = mo.make_pairs_from_predictions(predictions, organism) self.assertEquals([('gene2', 'gene1'), ('gene2', 'gene2'), ('gene2', 'gene3')], edges)
def test_make_operon_edges_forward(self): """test when all genes of the operon are on the forward strand""" operon = ['gene1', 'gene2', 'gene3'] features = { 'gene1': st.Feature('feature1', 'typ1', 'feature_name1', st.Location('contig1', 24, 89, False)), 'gene2': st.Feature('feature2', 'typ1', 'feature_name2', st.Location('contig1', 15, 21, False)), 'gene3': st.Feature('feature3', 'typ2', 'feature_name3', st.Location('contig1', 100, 154, False)) } edges = mo.make_operon_pairs(operon, features) self.assertTrue(('gene2', 'gene1') in edges) self.assertTrue(('gene2', 'gene2') in edges) self.assertTrue(('gene2', 'gene3') in edges) self.assertEqual(3, len(edges))
def read_feature(line): """Creates and adds a feature and associated contig from current DelimitedFile line""" contig = line[3] is_reverse = False if line[6] == 'R': is_reverse = True # note that feature positions can sometimes start with a '>' # or '<', so make sure it is stripped away return st.Feature( line[0], line[1], line[2], st.Location(contig, int(string.lstrip(line[4], '<>')), int(string.lstrip(line[5], '<>')), is_reverse))
def __make_organism(self): """makes a mock organism with almost real data""" features = {} dfile = util.read_dfile('testdata/Halobacterium_sp_features', comment='--') for line in dfile.lines: features[line[0]] = st.Feature( line[0], line[1], line[2], st.Location(line[3], int(line[4]), int(line[5]), line[6] == 'R')) tfile = util.read_dfile('testdata/Halobacterium_sp_feature_names', comment='--') synonyms = th.create_from_rsat_feature_names(tfile) return MockOrganismWithSynonyms('64091', features, synonyms)
def test_get_network_factory(self): """test happy path""" microbes_online = MockMicrobesOnline('testdata/gnc64091.named') network = mo.get_network_factory(microbes_online, 20, 123)( MockOrganism( '64091', { 'gene1': st.Feature('feature1', 'typ1', 'feature_name1', st.Location('contig1', 24, 89, False)), 'gene2': st.Feature('feature2', 'typ1', 'feature_name2', st.Location('contig1', 15, 21, False)), 'gene3': st.Feature('feature3', 'typ2', 'feature_name3', st.Location('contig1', 100, 154, False)) }, { 'gene1': 'gene1', 'gene2': 'gene2', 'gene3': 'gene3' }), check_size=False) self.assertEquals(3, network.num_edges()) self.assertEquals(6000, network.total_score()) self.assertEquals(123, network.weight)