def test_equals_true(self): """Tests the equality operator""" location1 = st.Location("contig", 1, 2, True) location2 = st.Location("contig", 1, 2, True) self.assertTrue(location1 == location1) self.assertTrue(location1 == location2)
def test_equals_false(self): """Tests the equality operator""" location1 = st.Location("contig1", 1, 2, True) location2 = st.Location("contig1", 1, 2, False) location3 = st.Location("contig2", 1, 2, True) self.assertFalse(location1 == location2) self.assertFalse(location1 == location3)
def test_init_genome(self): """Tests the init_genome() method""" organism = self.organism scan_seqs = organism.sequences_for_genes_scan(['VNG12345G'], seqtype='upstream') self.assertEquals((st.Location('NC_000915.1', -128, 152, False), 'ACGTTTAAAAGAGAGAGAGACACAGTATATATTTTTTTAAAA'), scan_seqs['NP_206803.1']) search_seqs = organism.sequences_for_genes_search(['VNG12345G'], seqtype='upstream') self.assertEquals((st.Location('NC_000915.1', -28, 142, False), 'ACGTTTAAAAGAGAGAGAGACACAGTATATATTTTTTTAAAA'), search_seqs['NP_206803.1'])
def __sequences_for_genes(self, seqtype, genes, distance): """retrieves the specified sequences from the supplied genomic data""" if not seqtype in self.__seqs: logging.info('loading %s sequences' % seqtype) dfile = util.read_dfile(self.__seq_filenames[seqtype], sep=',') self.__seqs[seqtype] = {} for line in dfile.lines: self.__seqs[seqtype][line[0].upper()] = line[1].upper() logging.info('loaded %i %s sequences' % (len(self.__seqs[seqtype]), seqtype)) result = {} for alias in genes: if alias in self.thesaurus(): gene = self.thesaurus()[alias] if gene in self.__seqs[seqtype]: # note that we have to return the sequence as a (location, sequence) # pair even if we do not actually use the Location result[gene] = (st.Location(gene, 0, 0, False), self.__seqs[seqtype][gene]) else: #logging.warn("Gene '%s' not found in 3' UTRs", gene) pass else: #logging.warn("Alias '%s' not in thesaurus !", alias) pass return result
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)