This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys,os,re | |
def translate(datafile): | |
# | |
# Regex strips all of space and non alphabetic from the sentence | |
# | |
regex = re.compile('[\s|\W|0-9_]') | |
# | |
# Dictionary for the Amido acid – Codon relationship | |
# | |
codon = { | |
'A':'GCT', # Alanine | |
'B':'GTG', # Let's use one of 'V' codon as 'B'. | |
'C':'TGT', # Cysteine | |
'D':'GAT', # Aspartate | |
'E':'GAA', # Glutamate | |
'F':'TTT', # Phenylanaline | |
'G':'GGT', # Glycine | |
'H':'CAT', # Histidine | |
'I':'ATT', # Isoleucine | |
'J':'AGA', # In this time, let's steal one of Argninine Codon. | |
'K':'AAA', # Lysine | |
'L':'TTA', # Leucine | |
'M':'ATG', # Methionine | |
'N':'AAT', # Asparagine | |
'O':'TAG', # Pyrrolysine..Do you know new 22th amino acid is out there? It is called 'Pyrrolysine' | |
'P':'CCT', # Proline | |
'Q':'CAA', # Glutamine | |
'R':'CGT', # Arginine | |
'S':'TCT', # Serine | |
'T':'ACT', # Threonine | |
'U':'TGA', # Selenocysteine..This is 21th amino acid | |
'V':'GTT', # Valine | |
'W':'TGG', # Tryptopin | |
'X':'AGT', # 'X' amino acid would be so weird..Anyway, steal again from serine. | |
'Y':'TAT', # Tyrosine | |
'Z':'GGG', # 'Z'…Let's steal one of Glycine Codon 'GGG' | |
'*':'TAA' # This is the 'Stop' Codon. | |
# There are other two stop codon (TAG and TGA), | |
# but they are already used for two rare amino acids. | |
} | |
try: | |
f=open(datafile) | |
filecontent=f.readlines() | |
oneline="" | |
for line in filecontent: | |
oneline = oneline+regex.sub('',line) | |
aminoacid='M'+oneline.upper()+'*' | |
# | |
# Add 'Start Codon' and 'Stop Codon'. Yes..I would like to make a 'functional' protein..LOL | |
# | |
nucleotide ="" | |
for ch in aminoacid: | |
nucleotide = nucleotide+codon[ch]; | |
print ">"+oneline | |
print nucleotide | |
except IOError as e: | |
print 'f**k' | |
if __name__ =='__main__': | |
for arg in sys.argv[1:]: | |
if os.path.isfile(arg): | |
translate(arg) |
1. Save the above scripts like ‘translate.py’
2. change permission
chmod +x translate.py
3. compose your love letter or something in ‘plain english’ and save it as text. Let’s assume you wrote something like this
I love you so much, babe..
4. Then execute the script.
./translate.py love.txt >Iloveyousomuchbabe ATGATTTTATAGGTTGAATATTAGTGATCTTAGATGTGATGTCATGTGGCTGTGGAATAA
Now you have a functional ‘gene’ for your ‘love letter’!. Even it will be translated in the cell cause it has start and stop codon.