Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
 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'])
Пример #4
0
 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)
Пример #5
0
 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))
Пример #6
0
 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)
Пример #7
0
        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(line[4].lstrip('<>')),
                            int(line[5].lstrip('<>')), is_reverse))
Пример #8
0
 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)
Пример #9
0
    def seqs_for(self, gene_aliases, distances):
        def seq2str(seq):
            return str(seq.upper()).replace('X', 'N')

        synonyms = self.organism.thesaurus()
        if self.seqmap is None:
            self.seqmap = {synonyms[r.id]: r for r in self.fasta_records if r.id in synonyms}
        result = {}
        for gene in gene_aliases:
            if gene in synonyms and synonyms[gene] in self.seqmap:
                fasta_record = self.seqmap[synonyms[gene]]
                result[synonyms[gene]] = (st.Location('', 0, 0, False),
                                          seq2str(fasta_record.seq.upper()))
            else:
                logging.warn("'%s' not in the sequences !!!!", gene)
        return result