-
Notifications
You must be signed in to change notification settings - Fork 0
/
codon_tables.py
38 lines (28 loc) · 911 Bytes
/
codon_tables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# http://www.petercollingridge.co.uk/tutorials/bioinformatics/codon-table/
class tables:
def __init__(self, nuc_type='DNA'):
bases = "tcag" if nuc_type == 'DNA' else "ucag"
codons = [a + b + c for a in bases for b in bases for c in bases]
amino_acids = 'FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG'
self.codon_to_acid = dict(zip(codons, amino_acids))
self.acid_to_codon = dict()
for codon, acid in self.codon_to_acid.items():
if acid in self.acid_to_codon:
self.acid_to_codon[acid].append(codon)
else:
self.acid_to_codon[acid] = [codon]
tables = tables()
def acid_lookup(codon, tables=tables):
acid = ''
try:
acid = tables.codon_to_acid[codon.lower()]
except KeyError:
acid = acid
return acid
def codon_lookup(acid, tables=tables):
codons = [None]
try:
codons = tables.acid_to_codon[acid]
except KeyError:
codons = codons
return codons