Our cells go through a process called protein synthesis to translate the instructions in DNA into an amino acid chain, or polypeptide.

Your job is to replicate this!

---

**Step 1: Transcription**

Your input will be a string of DNA that looks like this:

`"TACAGCTCGCTATGAATC"`


You then must transcribe it to mRNA. Each letter, or base, gets transcribed.


```T -> A
A -> U
G -> C
C -> G```

Also, you will split it into groups of three, or _codons_.

The above example would become:

`"AUG UCG AGC GAU ACU UAG"`

---

**Step 2: Translation**

After you have the mRNA strand, you will turn it into an amino acid chain.

Each codon corresponds to an amino acid:

```
Ala     GCU, GCC, GCA, GCG
Leu     UUA, UUG, CUU, CUC, CUA, CUG
Arg     CGU, CGC, CGA, CGG, AGA, AGG
Lys     AAA, AAG
Asn     AAU, AAC
Met     AUG
Asp     GAU, GAC
Phe     UUU, UUC
Cys     UGU, UGC
Pro     CCU, CCC, CCA, CCG
Gln     CAA, CAG
Ser     UCU, UCC, UCA, UCG, AGU, AGC
Glu     GAA, GAG
Thr     ACU, ACC, ACA, ACG
Gly     GGU, GGC, GGA, GGG
Trp     UGG
His     CAU, CAC
Tyr     UAU, UAC
Ile     AUU, AUC, AUA
Val     GUU, GUC, GUA, GUG
Stop   UAG, UGA, UAA```

Phew, that's a long list!

The above example would become:

`"Met Ser Ser Thr Asp Stop"`

Any additional sets of bases that aren't in a group of three aren't included. For example:

`"AUG C"`

would become

`"Met"`

---

Anyway, your final output will be the mRNA sequence and the polypeptide.

Here are some examples:

*In:*

`"TACAGCTCGCTATGAATC"`

*Out:*

`["AUG UCG AGC GAU ACU UAG","Met Ser Ser Asp Thr Stop"]`

---

*In:*

`"ACGTG"`

*Out:*

`["UGC AC","Cys"]`

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def protein_synthesis(dna):
	

Solutions:
import re
TABLE = str.maketrans('ACGT', 'UGCA')

def protein_synthesis(dna):
	rna = re.findall('.{1,3}', dna.translate(TABLE))
	return (' '.join(rna), ' '.join((x for x in map(CODON_DICT.get, rna) if x)))


MRNA_TABLE = str.maketrans('ACGT', 'UGCA')

def protein_synthesis(dna):
	rna = dna.translate(MRNA_TABLE)
	codons = [rna[i:i + 3] for i in range(0, len(rna), 3)]
	return (' '.join(codons), ' '.join((CODON_DICT[codon] for codon in codons if codon in CODON_DICT)))


from itertools import zip_longest
tbl = str.maketrans('TAGC', 'AUCG')

def protein_synthesis(dna: str):
	codons = [''.join(xs) for xs in zip_longest(*[iter(dna.translate(tbl))] * 3, fillvalue='')]
	rna = ' '.join(codons)
	protein = ' '.join((CODON_DICT[codon] for codon in codons if codon in CODON_DICT))
	return (rna, protein)


def protein_synthesis(dna):
	r = dna.translate(str.maketrans('TACG', 'AUGC'))
	r = list((r[i:i + 3] for i in range(0, len(r), 3)))
	return (' '.join(r), ' '.join([CODON_DICT[i] if len(i) > 2 else '' for i in r]).strip())


def protein_synthesis(dna):
	DNA2RNA = {'A': 'U', 'C': 'G', 'G': 'C', 'T': 'A'}
	rnaList = [DNA2RNA[i] for i in dna]
	aa = []
	for i in range(0, len(rnaList) - 2, 3):
		aa.append(CODON_DICT[''.join(rnaList[i:i + 3])])
	mRNA = [''.join(rnaList[i:i + 3]) for i in range(0, len(rnaList), 3)]
	return (' '.join(mRNA), ' '.join(aa))


def protein_synthesis(dna):
	table = str.maketrans('GCAT', 'CGUA')
	pressed_rna = dna.translate(table)
	rna = []
	for bit in range(0, len(pressed_rna)):
		if bit % 3 == 0:
			rna.append(' ')
		rna.append(pressed_rna[bit])
	rna = ''.join(rna).strip()
	protein = []
	for rna_bit in rna.split(' '):
		protein_bit = CODON_DICT.get(rna_bit, None)
		if protein_bit is not None:
			protein.append(protein_bit)
	protein = ' '.join(protein)
	return (rna, protein)


def protein_synthesis(dna):
	dna_to_rna = {'G': 'C', 'C': 'G', 'A': 'U', 'T': 'A'}
	rna = ''
	counter = 1
	for acid in dna:
		rna += dna_to_rna[acid]
		if counter % 3 == 0:
			rna += ' '
		counter += 1
	protein = ''
	for codon in rna.split(' '):
		amac = CODON_DICT.get(codon, None)
		if amac is not None:
			protein += amac + ' '
	return (rna.strip(), protein.strip())


def protein_synthesis(dna: str):
	RNA_DICT = {'A': 'U', 'G': 'C', 'C': 'G', 'T': 'A'}
	rna_strand = ''.join([RNA_DICT[base] for base in dna])
	rna = ' '.join([rna_strand[base:base + 3] for base in range(0, len(rna_strand), 3)])
	print(rna)
	length_rna = len(rna.split(' '))
	protein = [CODON_DICT.get(rna.split(' ')[codon_i], '') for codon_i in range(0, length_rna)]
	print(protein)
	protein = ' '.join([_f for _f in protein if _f])
	print(protein)
	return (rna, protein)


def protein_synthesis(dna):
	s = dna.translate(str.maketrans('TAGC', 'AUCG'))
	rna = [s[i:i + 3] for i in range(0, len(s), 3)]
	protein = [CODON_DICT[r] for r in rna if r in CODON_DICT]
	return (' '.join(rna), ' '.join(protein))


def protein_synthesis(dna):
	rna = ''
	protein = ''
	for i in range(len(dna)):
		if i % 3 == 0 and i != 0:
			rna += ' '
		if dna[i] == 'C':
			rna += 'G'
		elif dna[i] == 'G':
			rna += 'C'
		elif dna[i] == 'T':
			rna += 'A'
		elif dna[i] == 'A':
			rna += 'U'
	rna_list = rna.split(' ')
	for element in rna_list:
		if len(element) == 3:
			protein += CODON_DICT[element] + ' '
	return (rna, protein.strip())