Author: Mani Sebastian
Introduction
In this mini project, we’ll create a user-friendly DNA to Protein Translator using Python and Tkinter. This tool takes a DNA sequence, converts it to mRNA, and then translates it into an amino acid sequence using the standard genetic code.
What is DNA to Protein Translation?
DNA is transcribed into mRNA and then translated into a chain of amino acids that forms a protein. Each triplet of RNA bases (codon) corresponds to a specific amino acid.
Example:
- DNA:
ATGCGTATA
- RNA:
AUGCGUAUA
- Protein:
Methionine-Arginine-Isoleucine
Requirements
Make sure Python is installed. Install Tkinter with pip:
pip install tk
Complete Python Code
Step 1: Import Libraries
import tkinter as tk
from tkinter import messagebox
Step 2: Genetic Code Dictionary
genetic_code = {
'AUG': 'Methionine', 'UUU': 'Phenylalanine', 'UUC': 'Phenylalanine',
'UUA': 'Leucine', 'UUG': 'Leucine', 'UCU': 'Serine', 'UCC': 'Serine',
'UCA': 'Serine', 'UCG': 'Serine', 'UAU': 'Tyrosine', 'UAC': 'Tyrosine',
'UGU': 'Cysteine', 'UGC': 'Cysteine', 'UGG': 'Tryptophan',
'UAA': 'STOP', 'UAG': 'STOP', 'UGA': 'STOP'
}
Step 3: Translation Logic
def dna_to_protein():
dna_sequence = entry.get().upper()
if not all(base in "ATGC" for base in dna_sequence):
messagebox.showerror("Error", "Invalid DNA sequence! Use only A, T, G, and C.")
return
mrna_sequence = dna_sequence.replace('T', 'U')
codons = [mrna_sequence[i:i+3] for i in range(0, len(mrna_sequence), 3) if len(mrna_sequence[i:i+3]) == 3]
protein_sequence = []
for codon in codons:
amino_acid = genetic_code.get(codon, 'Unknown')
if amino_acid == 'STOP':
break
protein_sequence.append(amino_acid)
result_label.config(text="Protein Sequence: " + '-'.join(protein_sequence))
Step 4: GUI Design
root = tk.Tk()
root.title("DNA to Protein Translator")
root.geometry("400x300")
tk.Label(root, text="Enter DNA Sequence:", font=("Arial", 12)).pack(pady=10)
entry = tk.Entry(root, font=("Arial", 12), width=30)
entry.pack()
translate_button = tk.Button(root, text="Translate", font=("Arial", 12), command=dna_to_protein)
translate_button.pack(pady=10)
result_label = tk.Label(root, text="Protein Sequence: ", font=("Arial", 12), wraplength=350)
result_label.pack(pady=10)
root.mainloop()
Summary
- Get DNA input from the user
- Convert DNA to mRNA
- Split into codons
- Translate to amino acids using dictionary
- Show result in the GUI
Future Improvements
- File upload for longer sequences (FASTA format)
- Support for reverse complements
- Codon usage bias analysis
- Enhanced GUI with themes
Explore more Python + Bioinformatics tutorials at My Gene Talks!