Skip to content

Instantly share code, notes, and snippets.

@Vini2
Last active September 25, 2021 04:46
Show Gist options
  • Save Vini2/96ed2becdd6de1fcf4ff99be2af5caf0 to your computer and use it in GitHub Desktop.
Save Vini2/96ed2becdd6de1fcf4ff99be2af5caf0 to your computer and use it in GitHub Desktop.
# Read the file and get the DNA string
file = open('sample_dna.txt', 'r')
dna = file.read()
print "DNA Sequence: ", dna
# DNA codon table
protein = {"TTT" : "F", "CTT" : "L", "ATT" : "I", "GTT" : "V",
"TTC" : "F", "CTC" : "L", "ATC" : "I", "GTC" : "V",
"TTA" : "L", "CTA" : "L", "ATA" : "I", "GTA" : "V",
"TTG" : "L", "CTG" : "L", "ATG" : "M", "GTG" : "V",
"TCT" : "S", "CCT" : "P", "ACT" : "T", "GCT" : "A",
"TCC" : "S", "CCC" : "P", "ACC" : "T", "GCC" : "A",
"TCA" : "S", "CCA" : "P", "ACA" : "T", "GCA" : "A",
"TCG" : "S", "CCG" : "P", "ACG" : "T", "GCG" : "A",
"TAT" : "Y", "CAT" : "H", "AAT" : "N", "GAT" : "D",
"TAC" : "Y", "CAC" : "H", "AAC" : "N", "GAC" : "D",
"TAA" : "STOP", "CAA" : "Q", "AAA" : "K", "GAA" : "E",
"TAG" : "STOP", "CAG" : "Q", "AAG" : "K", "GAG" : "E",
"TGT" : "C", "CGT" : "R", "AGT" : "S", "GGT" : "G",
"TGC" : "C", "CGC" : "R", "AGC" : "S", "GGC" : "G",
"TGA" : "STOP", "CGA" : "R", "AGA" : "R", "GGA" : "G",
"TGG" : "W", "CGG" : "R", "AGG" : "R", "GGG" : "G"
}
protein_sequence = ""
# Generate protein sequence
for i in range(0, len(dna)-(3+len(dna)%3), 3):
if protein[dna[i:i+3]] == "STOP" :
break
protein_sequence += protein[dna[i:i+3]]
# Print the protein sequence
print "Protein Sequence: ", protein_sequence
# End of program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment