# translation.py # Author: Sami Khuri # Last updated: January 14, 2016 # Purpose: To perform translation of a coding sequence (CDS). # A CDS starts with the start codon: ATG, and ends with a # stop codon: TAA, TAG, or TGA, and its length is a multiple of three. # Program uses dictionary, slicing a list, and built-in python function range() def translate(cds): """The input sequence is a DNA coding sequence (CDS)""" geneticode = { 'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M', 'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T', 'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K', 'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R', 'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L', 'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P', 'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q', 'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R', 'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V', 'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A', 'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E', 'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G', 'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S', 'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L', 'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_', 'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W', } prot = "" for i in range(0,len(cds),3): codon = cds[i:i+3] # slice is i,1+1,i+2 prot = prot + geneticode[codon] return prot cds = "ATGTATCCCTACACCCATAATTGA" print "CDS is", cds print "Translation of CDS is", translate(cds)