# translation.py # Author: Sami Khuri # Last updated: December 28, 2017 # 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 a user-defined function: translate; a dictionary where the key # is a codon and value its amino acid translation, slicing a list, # the while loop, the python function range() and method join() # def translate(seq): """Translate a DNA sequence to an amino acid sequence.""" 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', } seq = seq.upper() length = len(seq) pos = 0 # Let us save the amino acid sequence in a list called protein protein = [] while (pos < (length-2)): # while we still have codons to translate codon = seq[pos:pos+3] # Get the appropriate amino acid from the dictionary aa = geneticode[codon] protein.append(aa) pos = pos + 3 return "".join(protein) # The main program starts here handle_CDS_mutant = open("CDS_mutant.txt","r") seq_CDS_mutant = handle_CDS_mutant.read() outfile = open("Protein_mutant.txt", "w") outfile.write (translate(seq_CDS_mutant)) handle_CDS_mutant.close() outfile.close()