Much like replication, the chemical machinery underlying transcription and translation is fascinating, but from a computational perspective, both processes are straightforward. Transcription simply transforms a DNA string into an RNA string by replacing all occurrences of T with U. The resulting strand of RNA is translated into an amino acid sequence via the genetic code. This process converts each 3-mer of RNA — called a codon — into one of 20 amino acids.

genetic code
The genetic code describes the translation of an RNA codon into one of 20 different amino acids. The first three circles, moving from the inside out, represent the first, second, and third nucleotides of a given codon. The fourth, fifth, and sixth circles define the translated amino acid in three ways: the amino acid's full name, its 3-letter abbreviation, and its single-letter abbreviation. Three of the 64 total RNA codons are stop codons, which halt translation and implicitly add a 21st stop symbol to the amino acid alphabet.

As illustrated in the figure above, each of the 64 RNA codons encodes its own amino acid (some codons encode the same amino acid), with the exception of three stop codons that do not translate into amino acids and serve to halt translation. For example, the DNA string TATACGAAA transcribes into the RNA string UAUACGAAA, which in turn translates into the amino acid string Tyr-Thr-Lys.

The following problem asks you to find the translation of an RNA string into an amino acid string.

Assignment

Write a function translate that takes the locations of two FASTA files. The first FASTA file contains an RNA string $$s$$ corresponding to a strand of mRNA. The function must write the translation of $$s$$ into an amino acid string to the FASTA file whose location is passed as the second argument. Stop codons must be represented by an asterisk (*).

Example

In the following interactive session, we assume the FASTA files data01.fna1, data02.fna2, data01.faa3 and data02.faa4 to be located in the current directory.

>>> translate('data01.fna', 'data01.faa')
>>> print(open('data01.faa').read().rstrip())
>seq01
MAMAPRTEINSTRING*

>>> translate('data02.fna', 'data02.faa')
>>> print(open('data02.faa').read().rstrip())
>seq01
MYHDISRSIMEANNTMKSEHGPYIWLGLWGWFFFNNSPTMIFELNWHIQFLW*