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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from codon_table import translate_dna_to_text, get_example_sequences, CODON_TABLE
|
| 3 |
+
|
| 4 |
+
def process_dna_sequence(sequence, reading_frame, detailed_mode, example_dropdown):
|
| 5 |
+
"""Process DNA sequence and return explanation"""
|
| 6 |
+
|
| 7 |
+
# If user selected an example, use that
|
| 8 |
+
if example_dropdown and example_dropdown != "Choose an example...":
|
| 9 |
+
examples = get_example_sequences()
|
| 10 |
+
if example_dropdown in examples:
|
| 11 |
+
sequence = examples[example_dropdown]
|
| 12 |
+
|
| 13 |
+
if not sequence or sequence.strip() == "":
|
| 14 |
+
return "Please enter a DNA sequence or select an example."
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
result = translate_dna_to_text(sequence, reading_frame, detailed_mode)
|
| 18 |
+
return result
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"❌ Error processing sequence: {str(e)}\n\nPlease check your input and try again."
|
| 21 |
+
|
| 22 |
+
def get_genetic_code_table():
|
| 23 |
+
"""Generate a formatted genetic code reference table"""
|
| 24 |
+
output = ["# 🧬 Genetic Code Reference\n"]
|
| 25 |
+
output.append("| Codon | Amino Acid | Type | Description |")
|
| 26 |
+
output.append("|-------|------------|------|-------------|")
|
| 27 |
+
|
| 28 |
+
# Group by amino acid for better organization
|
| 29 |
+
amino_acid_groups = {}
|
| 30 |
+
for codon, info in CODON_TABLE.items():
|
| 31 |
+
aa = info['amino_acid']
|
| 32 |
+
if aa not in amino_acid_groups:
|
| 33 |
+
amino_acid_groups[aa] = []
|
| 34 |
+
amino_acid_groups[aa].append((codon, info))
|
| 35 |
+
|
| 36 |
+
# Sort amino acids, with special codons first
|
| 37 |
+
special_order = ['Methionine', 'STOP']
|
| 38 |
+
regular_amino_acids = sorted([aa for aa in amino_acid_groups.keys() if aa not in special_order])
|
| 39 |
+
|
| 40 |
+
for aa in special_order + regular_amino_acids:
|
| 41 |
+
if aa in amino_acid_groups:
|
| 42 |
+
for codon, info in sorted(amino_acid_groups[aa]):
|
| 43 |
+
icon = "🚀" if info['type'] == 'start' else "🛑" if info['type'] == 'stop' else "🔤"
|
| 44 |
+
output.append(f"| {codon} | {aa} | {icon} | {info['description'][:50]}{'...' if len(info['description']) > 50 else ''} |")
|
| 45 |
+
|
| 46 |
+
return "\n".join(output)
|
| 47 |
+
|
| 48 |
+
# Create the Gradio interface
|
| 49 |
+
with gr.Blocks(
|
| 50 |
+
title="Gene2Text: DNA Codon Explainer",
|
| 51 |
+
theme=gr.themes.Soft(),
|
| 52 |
+
css="""
|
| 53 |
+
.gradio-container {
|
| 54 |
+
max-width: 1200px !important;
|
| 55 |
+
}
|
| 56 |
+
.output-markdown {
|
| 57 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 58 |
+
}
|
| 59 |
+
"""
|
| 60 |
+
) as app:
|
| 61 |
+
|
| 62 |
+
gr.Markdown("""
|
| 63 |
+
# 🧬 Gene2Text: Interpretable Codon-by-Codon Describer
|
| 64 |
+
|
| 65 |
+
**Transform DNA sequences into readable explanations!** This tool takes raw DNA sequences and explains what each three-letter codon codes for, making molecular biology accessible to everyone.
|
| 66 |
+
|
| 67 |
+
Perfect for:
|
| 68 |
+
- 🎓 **Students** learning molecular biology
|
| 69 |
+
- 👩🏫 **Teachers** explaining genetic concepts
|
| 70 |
+
- 🔬 **Researchers** quickly interpreting sequences
|
| 71 |
+
- 🤔 **Anyone curious** about how DNA codes for proteins
|
| 72 |
+
""")
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column(scale=2):
|
| 76 |
+
gr.Markdown("## 📝 Input Your DNA Sequence")
|
| 77 |
+
|
| 78 |
+
# Example dropdown
|
| 79 |
+
example_dropdown = gr.Dropdown(
|
| 80 |
+
choices=["Choose an example..."] + list(get_example_sequences().keys()),
|
| 81 |
+
value="Choose an example...",
|
| 82 |
+
label="📚 Or select an example sequence:",
|
| 83 |
+
info="Choose a pre-loaded example to see how the tool works"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# Main input
|
| 87 |
+
sequence_input = gr.Textbox(
|
| 88 |
+
label="🧬 DNA Sequence",
|
| 89 |
+
placeholder="Enter your DNA sequence here (e.g., ATG GCT TAA)\nSpaces and line breaks will be automatically removed.",
|
| 90 |
+
lines=4,
|
| 91 |
+
info="Enter nucleotides: A, T, G, C only. Other characters will be filtered out."
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
with gr.Row():
|
| 95 |
+
reading_frame = gr.Radio(
|
| 96 |
+
choices=[0, 1, 2],
|
| 97 |
+
value=0,
|
| 98 |
+
label="📍 Reading Frame",
|
| 99 |
+
info="Choose which nucleotide to start reading from (0=first, 1=second, 2=third)"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
detailed_mode = gr.Checkbox(
|
| 103 |
+
value=True,
|
| 104 |
+
label="🔍 Detailed Descriptions",
|
| 105 |
+
info="Include biological context and amino acid properties"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
submit_btn = gr.Button("🔬 Analyze Sequence", variant="primary", size="lg")
|
| 109 |
+
|
| 110 |
+
with gr.Column(scale=3):
|
| 111 |
+
gr.Markdown("## 📋 Results")
|
| 112 |
+
output_text = gr.Markdown(
|
| 113 |
+
value="Enter a DNA sequence to see the codon-by-codon breakdown here...",
|
| 114 |
+
elem_classes=["output-markdown"]
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Genetic Code Reference (collapsible)
|
| 118 |
+
with gr.Accordion("📖 Genetic Code Reference Table", open=False):
|
| 119 |
+
genetic_code_display = gr.Markdown(get_genetic_code_table())
|
| 120 |
+
|
| 121 |
+
# Educational content
|
| 122 |
+
with gr.Accordion("💡 How It Works", open=False):
|
| 123 |
+
gr.Markdown("""
|
| 124 |
+
### The Genetic Code Explained
|
| 125 |
+
|
| 126 |
+
**DNA → RNA → Protein** is the central dogma of molecular biology:
|
| 127 |
+
|
| 128 |
+
1. **Codons**: DNA is read in groups of 3 nucleotides called codons
|
| 129 |
+
2. **Translation**: Each codon codes for a specific amino acid (or stop signal)
|
| 130 |
+
3. **Proteins**: Amino acids chain together to form proteins
|
| 131 |
+
4. **Reading Frames**: DNA can be read in 3 different frames, giving different results
|
| 132 |
+
|
| 133 |
+
**Special Codons:**
|
| 134 |
+
- 🚀 **ATG**: Start codon (Methionine) - where protein synthesis begins
|
| 135 |
+
- 🛑 **TAA, TAG, TGA**: Stop codons - where protein synthesis ends
|
| 136 |
+
|
| 137 |
+
**Why This Matters:**
|
| 138 |
+
Understanding how DNA codes for proteins helps us comprehend genetics, evolution,
|
| 139 |
+
disease mechanisms, and biotechnology applications.
|
| 140 |
+
""")
|
| 141 |
+
|
| 142 |
+
# Event handlers
|
| 143 |
+
submit_btn.click(
|
| 144 |
+
fn=process_dna_sequence,
|
| 145 |
+
inputs=[sequence_input, reading_frame, detailed_mode, example_dropdown],
|
| 146 |
+
outputs=output_text
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
# Auto-update when example is selected
|
| 150 |
+
example_dropdown.change(
|
| 151 |
+
fn=process_dna_sequence,
|
| 152 |
+
inputs=[sequence_input, reading_frame, detailed_mode, example_dropdown],
|
| 153 |
+
outputs=output_text
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
# Footer
|
| 157 |
+
gr.Markdown("""
|
| 158 |
+
---
|
| 159 |
+
**Built with ❤️ for biology education** | Made with [Gradio](https://gradio.app) |
|
| 160 |
+
Perfect for classrooms, labs, and curious minds everywhere!
|
| 161 |
+
""")
|
| 162 |
+
|
| 163 |
+
# Launch the app
|
| 164 |
+
if __name__ == "__main__":
|
| 165 |
+
app.launch(
|
| 166 |
+
share=True,
|
| 167 |
+
server_name="0.0.0.0",
|
| 168 |
+
server_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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Complete genetic code dictionary with biological context
|
| 2 |
+
CODON_TABLE = {
|
| 3 |
+
# Start codon
|
| 4 |
+
'ATG': {'amino_acid': 'Methionine', 'type': 'start', 'description': 'The universal start codon - where protein synthesis begins'},
|
| 5 |
+
|
| 6 |
+
# Stop codons
|
| 7 |
+
'TAA': {'amino_acid': 'STOP', 'type': 'stop', 'description': 'Amber stop codon - signals end of protein synthesis'},
|
| 8 |
+
'TAG': {'amino_acid': 'STOP', 'type': 'stop', 'description': 'Ochre stop codon - signals end of protein synthesis'},
|
| 9 |
+
'TGA': {'amino_acid': 'STOP', 'type': 'stop', 'description': 'Opal stop codon - signals end of protein synthesis'},
|
| 10 |
+
|
| 11 |
+
# Alanine (A)
|
| 12 |
+
'GCT': {'amino_acid': 'Alanine', 'type': 'regular', 'description': 'Small, hydrophobic amino acid - often found in protein cores'},
|
| 13 |
+
'GCC': {'amino_acid': 'Alanine', 'type': 'regular', 'description': 'Small, hydrophobic amino acid - often found in protein cores'},
|
| 14 |
+
'GCA': {'amino_acid': 'Alanine', 'type': 'regular', 'description': 'Small, hydrophobic amino acid - often found in protein cores'},
|
| 15 |
+
'GCG': {'amino_acid': 'Alanine', 'type': 'regular', 'description': 'Small, hydrophobic amino acid - often found in protein cores'},
|
| 16 |
+
|
| 17 |
+
# Arginine (R)
|
| 18 |
+
'CGT': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 19 |
+
'CGC': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 20 |
+
'CGA': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 21 |
+
'CGG': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 22 |
+
'AGA': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 23 |
+
'AGG': {'amino_acid': 'Arginine', 'type': 'regular', 'description': 'Positively charged amino acid - important for protein-DNA interactions'},
|
| 24 |
+
|
| 25 |
+
# Asparagine (N)
|
| 26 |
+
'AAT': {'amino_acid': 'Asparagine', 'type': 'regular', 'description': 'Polar amino acid - often involved in protein folding and stability'},
|
| 27 |
+
'AAC': {'amino_acid': 'Asparagine', 'type': 'regular', 'description': 'Polar amino acid - often involved in protein folding and stability'},
|
| 28 |
+
|
| 29 |
+
# Aspartic acid (D)
|
| 30 |
+
'GAT': {'amino_acid': 'Aspartic acid', 'type': 'regular', 'description': 'Negatively charged amino acid - important for enzyme active sites'},
|
| 31 |
+
'GAC': {'amino_acid': 'Aspartic acid', 'type': 'regular', 'description': 'Negatively charged amino acid - important for enzyme active sites'},
|
| 32 |
+
|
| 33 |
+
# Cysteine (C)
|
| 34 |
+
'TGT': {'amino_acid': 'Cysteine', 'type': 'regular', 'description': 'Contains sulfur - can form disulfide bonds for protein structure'},
|
| 35 |
+
'TGC': {'amino_acid': 'Cysteine', 'type': 'regular', 'description': 'Contains sulfur - can form disulfide bonds for protein structure'},
|
| 36 |
+
|
| 37 |
+
# Glutamic acid (E)
|
| 38 |
+
'GAA': {'amino_acid': 'Glutamic acid', 'type': 'regular', 'description': 'Negatively charged amino acid - common in enzyme active sites'},
|
| 39 |
+
'GAG': {'amino_acid': 'Glutamic acid', 'type': 'regular', 'description': 'Negatively charged amino acid - common in enzyme active sites'},
|
| 40 |
+
|
| 41 |
+
# Glutamine (Q)
|
| 42 |
+
'CAA': {'amino_acid': 'Glutamine', 'type': 'regular', 'description': 'Polar amino acid - involved in protein-protein interactions'},
|
| 43 |
+
'CAG': {'amino_acid': 'Glutamine', 'type': 'regular', 'description': 'Polar amino acid - involved in protein-protein interactions'},
|
| 44 |
+
|
| 45 |
+
# Glycine (G)
|
| 46 |
+
'GGT': {'amino_acid': 'Glycine', 'type': 'regular', 'description': 'Smallest amino acid - provides flexibility in protein structure'},
|
| 47 |
+
'GGC': {'amino_acid': 'Glycine', 'type': 'regular', 'description': 'Smallest amino acid - provides flexibility in protein structure'},
|
| 48 |
+
'GGA': {'amino_acid': 'Glycine', 'type': 'regular', 'description': 'Smallest amino acid - provides flexibility in protein structure'},
|
| 49 |
+
'GGG': {'amino_acid': 'Glycine', 'type': 'regular', 'description': 'Smallest amino acid - provides flexibility in protein structure'},
|
| 50 |
+
|
| 51 |
+
# Histidine (H)
|
| 52 |
+
'CAT': {'amino_acid': 'Histidine', 'type': 'regular', 'description': 'Can be positively charged - often found in enzyme active sites'},
|
| 53 |
+
'CAC': {'amino_acid': 'Histidine', 'type': 'regular', 'description': 'Can be positively charged - often found in enzyme active sites'},
|
| 54 |
+
|
| 55 |
+
# Isoleucine (I)
|
| 56 |
+
'ATT': {'amino_acid': 'Isoleucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - important for protein core structure'},
|
| 57 |
+
'ATC': {'amino_acid': 'Isoleucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - important for protein core structure'},
|
| 58 |
+
'ATA': {'amino_acid': 'Isoleucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - important for protein core structure'},
|
| 59 |
+
|
| 60 |
+
# Leucine (L)
|
| 61 |
+
'TTA': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 62 |
+
'TTG': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 63 |
+
'CTT': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 64 |
+
'CTC': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 65 |
+
'CTA': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 66 |
+
'CTG': {'amino_acid': 'Leucine', 'type': 'regular', 'description': 'Hydrophobic amino acid - very common in proteins'},
|
| 67 |
+
|
| 68 |
+
# Lysine (K)
|
| 69 |
+
'AAA': {'amino_acid': 'Lysine', 'type': 'regular', 'description': 'Positively charged amino acid - important for DNA binding'},
|
| 70 |
+
'AAG': {'amino_acid': 'Lysine', 'type': 'regular', 'description': 'Positively charged amino acid - important for DNA binding'},
|
| 71 |
+
|
| 72 |
+
# Phenylalanine (F)
|
| 73 |
+
'TTT': {'amino_acid': 'Phenylalanine', 'type': 'regular', 'description': 'Aromatic, hydrophobic amino acid - important for protein structure'},
|
| 74 |
+
'TTC': {'amino_acid': 'Phenylalanine', 'type': 'regular', 'description': 'Aromatic, hydrophobic amino acid - important for protein structure'},
|
| 75 |
+
|
| 76 |
+
# Proline (P)
|
| 77 |
+
'CCT': {'amino_acid': 'Proline', 'type': 'regular', 'description': 'Rigid amino acid - creates kinks and turns in protein structure'},
|
| 78 |
+
'CCC': {'amino_acid': 'Proline', 'type': 'regular', 'description': 'Rigid amino acid - creates kinks and turns in protein structure'},
|
| 79 |
+
'CCA': {'amino_acid': 'Proline', 'type': 'regular', 'description': 'Rigid amino acid - creates kinks and turns in protein structure'},
|
| 80 |
+
'CCG': {'amino_acid': 'Proline', 'type': 'regular', 'description': 'Rigid amino acid - creates kinks and turns in protein structure'},
|
| 81 |
+
|
| 82 |
+
# Serine (S)
|
| 83 |
+
'TCT': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 84 |
+
'TCC': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 85 |
+
'TCA': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 86 |
+
'TCG': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 87 |
+
'AGT': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 88 |
+
'AGC': {'amino_acid': 'Serine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 89 |
+
|
| 90 |
+
# Threonine (T)
|
| 91 |
+
'ACT': {'amino_acid': 'Threonine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 92 |
+
'ACC': {'amino_acid': 'Threonine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 93 |
+
'ACA': {'amino_acid': 'Threonine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 94 |
+
'ACG': {'amino_acid': 'Threonine', 'type': 'regular', 'description': 'Polar amino acid - can be phosphorylated for regulation'},
|
| 95 |
+
|
| 96 |
+
# Tryptophan (W)
|
| 97 |
+
'TGG': {'amino_acid': 'Tryptophan', 'type': 'regular', 'description': 'Largest amino acid - important for protein folding and fluorescence'},
|
| 98 |
+
|
| 99 |
+
# Tyrosine (Y)
|
| 100 |
+
'TAT': {'amino_acid': 'Tyrosine', 'type': 'regular', 'description': 'Aromatic amino acid - can be phosphorylated for signaling'},
|
| 101 |
+
'TAC': {'amino_acid': 'Tyrosine', 'type': 'regular', 'description': 'Aromatic amino acid - can be phosphorylated for signaling'},
|
| 102 |
+
|
| 103 |
+
# Valine (V)
|
| 104 |
+
'GTT': {'amino_acid': 'Valine', 'type': 'regular', 'description': 'Hydrophobic amino acid - common in protein cores'},
|
| 105 |
+
'GTC': {'amino_acid': 'Valine', 'type': 'regular', 'description': 'Hydrophobic amino acid - common in protein cores'},
|
| 106 |
+
'GTA': {'amino_acid': 'Valine', 'type': 'regular', 'description': 'Hydrophobic amino acid - common in protein cores'},
|
| 107 |
+
'GTG': {'amino_acid': 'Valine', 'type': 'regular', 'description': 'Hydrophobic amino acid - common in protein cores'}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
def clean_sequence(sequence):
|
| 111 |
+
"""Clean and validate DNA sequence"""
|
| 112 |
+
# Remove spaces, newlines, and convert to uppercase
|
| 113 |
+
cleaned = sequence.upper().replace(" ", "").replace("\n", "").replace("\t", "")
|
| 114 |
+
|
| 115 |
+
# Remove any non-DNA characters
|
| 116 |
+
valid_chars = set('ATGC')
|
| 117 |
+
cleaned = ''.join(char for char in cleaned if char in valid_chars)
|
| 118 |
+
|
| 119 |
+
return cleaned
|
| 120 |
+
|
| 121 |
+
def translate_dna_to_text(sequence, reading_frame=0, detailed=True):
|
| 122 |
+
"""
|
| 123 |
+
Translate DNA sequence to descriptive text
|
| 124 |
+
|
| 125 |
+
Args:
|
| 126 |
+
sequence (str): DNA sequence
|
| 127 |
+
reading_frame (int): 0, 1, or 2 for different reading frames
|
| 128 |
+
detailed (bool): Whether to include detailed descriptions
|
| 129 |
+
|
| 130 |
+
Returns:
|
| 131 |
+
str: Formatted explanation of the sequence
|
| 132 |
+
"""
|
| 133 |
+
sequence = clean_sequence(sequence)
|
| 134 |
+
|
| 135 |
+
if len(sequence) == 0:
|
| 136 |
+
return "❌ No valid DNA sequence found. Please enter a sequence with A, T, G, C characters only."
|
| 137 |
+
|
| 138 |
+
# Adjust for reading frame
|
| 139 |
+
sequence = sequence[reading_frame:]
|
| 140 |
+
|
| 141 |
+
if len(sequence) < 3:
|
| 142 |
+
return "❌ Sequence too short. Need at least 3 nucleotides to form a codon."
|
| 143 |
+
|
| 144 |
+
# Split into codons
|
| 145 |
+
codons = [sequence[i:i+3] for i in range(0, len(sequence), 3)]
|
| 146 |
+
|
| 147 |
+
output = []
|
| 148 |
+
output.append(f"🧬 **DNA Sequence Analysis** (Reading Frame {reading_frame + 1})")
|
| 149 |
+
output.append(f"📊 **Sequence Length:** {len(sequence)} nucleotides ({len(codons)} codons)")
|
| 150 |
+
output.append("")
|
| 151 |
+
|
| 152 |
+
protein_sequence = []
|
| 153 |
+
|
| 154 |
+
for i, codon in enumerate(codons):
|
| 155 |
+
if len(codon) == 3:
|
| 156 |
+
codon_info = CODON_TABLE.get(codon)
|
| 157 |
+
|
| 158 |
+
if codon_info:
|
| 159 |
+
amino_acid = codon_info['amino_acid']
|
| 160 |
+
codon_type = codon_info['type']
|
| 161 |
+
description = codon_info['description']
|
| 162 |
+
|
| 163 |
+
# Add to protein sequence
|
| 164 |
+
if amino_acid == 'STOP':
|
| 165 |
+
protein_sequence.append('*')
|
| 166 |
+
elif amino_acid == 'Methionine':
|
| 167 |
+
protein_sequence.append('M')
|
| 168 |
+
else:
|
| 169 |
+
protein_sequence.append(amino_acid[0])
|
| 170 |
+
|
| 171 |
+
# Format output based on codon type
|
| 172 |
+
if codon_type == 'start':
|
| 173 |
+
output.append(f"🚀 **Codon {i+1}: {codon}** → {amino_acid}")
|
| 174 |
+
elif codon_type == 'stop':
|
| 175 |
+
output.append(f"🛑 **Codon {i+1}: {codon}** → {amino_acid}")
|
| 176 |
+
else:
|
| 177 |
+
output.append(f"🔤 **Codon {i+1}: {codon}** → {amino_acid}")
|
| 178 |
+
|
| 179 |
+
if detailed:
|
| 180 |
+
output.append(f" 💡 {description}")
|
| 181 |
+
output.append("")
|
| 182 |
+
else:
|
| 183 |
+
output.append(f"❓ **Codon {i+1}: {codon}** → Unknown codon")
|
| 184 |
+
output.append("")
|
| 185 |
+
else:
|
| 186 |
+
output.append(f"⚠️ **Incomplete codon: {codon}** (only {len(codon)} nucleotides)")
|
| 187 |
+
output.append("")
|
| 188 |
+
|
| 189 |
+
# Add protein sequence summary
|
| 190 |
+
if protein_sequence:
|
| 191 |
+
protein_str = ''.join(protein_sequence)
|
| 192 |
+
output.append("🧪 **Resulting Protein Sequence:**")
|
| 193 |
+
output.append(f"{protein_str}")
|
| 194 |
+
output.append("")
|
| 195 |
+
|
| 196 |
+
# Count amino acids
|
| 197 |
+
start_codons = sum(1 for codon in codons if len(codon) == 3 and CODON_TABLE.get(codon, {}).get('type') == 'start')
|
| 198 |
+
stop_codons = sum(1 for codon in codons if len(codon) == 3 and CODON_TABLE.get(codon, {}).get('type') == 'stop')
|
| 199 |
+
|
| 200 |
+
output.append(f"📈 **Summary:** {start_codons} start codon(s), {stop_codons}
|
| 201 |
+
return "\n".join(output)
|
| 202 |
+
|
| 203 |
+
def get_example_sequences():
|
| 204 |
+
"""Return example DNA sequences for testing"""
|
| 205 |
+
return {
|
| 206 |
+
"Basic Example": "ATG GCT TAA",
|
| 207 |
+
"Insulin Gene (partial)": "ATG GCC CTG TGG ATG CGC CTC CTG CCC CTG CTG GCG CTG CTG GCC CTG TGG GGG ACC TCG TCG",
|
| 208 |
+
"Beta-globin (partial)": "ATG GTG CAC CTG ACT CCT GAG GAG AAG TCT",
|
| 209 |
+
"Green Fluorescent Protein (partial)": "ATG AGC AAG GGC GAG GAG CTG TTC ACC GGG GTG GTG CCC ATC CTG GTG GAG CTG"
|
| 210 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|