I am currently working on my first website, which is a dna translator that you can translate your dna into a certain protein. To do that, I've created a class in views that goes like this:
class TranslatorView(View):
template_name = 'main/translated.html'
mapper_1={ #Here's the protein dictionary
"aat": "Asparagine",
"aac": "Asparagine",
"aaa": "Lysine",
"aag": "Lysine",
"act": "Threonine",
"acc": "Threonine",
"aca": "Threonine",
"acg": "Threonine",
"agt": "Serine",
"agc": "Serine",
"aga": "Arginine",
"agg": "Arginine",
"att": "Isoleucine",
"atc": "Isoleucine",
"ata": "Isoleucine",
"atg": "Methionine",
"cat": "Histidine",
"cac": "Histidine",
"caa": "Glutamine",
"cag": "Glutamine",
"cct": "Proline",
"ccc": "Proline",
"cca": "Proline",
"ccg": "Proline",
"cgt": "Arginine",
"cgc": "Arginine",
"cga": "Arginine",
"cgg": "Arginine",
"ctt": "Leucine",
"ctc": "Leucine",
"cta": "Leucine",
"ctg": "Leucine",
"gat": "Aspartic",
"gac": "Aspartic",
"gaa": "Glutamic",
"gag": "Glutamic",
"gct": "Alanine",
"gcc": "Alanine",
"gca": "Alanine",
"gcg": "Alanine",
"ggt": "Glycine",
"ggc": "Glycine",
"gga": "Glycine",
"ggg": "Glycine",
"gtt": "Valine",
"gtc": "Valine",
"gta": "Valine",
"gtg": "Valine",
"tat": "Tyrosine",
"tac": "Tyrosine",
"taa": "Stop",
"tag": "Stop",
"tct": "Serine",
"tcc": "Serine",
"tca": "Serine",
"tcg": "Serine",
"tgt": "Cysteine",
"tgc": "Cysteine",
"tga": "Stop",
"tgg": "Tryptophan",
"ttt": "Phenylalanine",
"ttc": "Phenylalanine",
"tta": "Leucine",
"ttg": "Leucine",
}
def translate_protein(self,phrase):
protein = ""
for letter in phrase:
if letter.lower() in self.mapper_1:
protein += self.mapper_1[letter.lower()].upper() if letter.isupper() else self.mapper_1[letter]
return protein
def get(self, request, *args, **kwargs):
return render(request, 'main/translator.html')
def post(self, request, *args, **kwargs):
protein = request.POST.get('text','protein')
return render(request, self.template_name, {'protein': self.translate_protein(protein)})
I probably have the problem in the dictionary and for loop, because to translate the protein, the forloop needs to get three letters because a codom (rna string) is grouped in three letters.
Example:
AAT should be translated into Asparagine. So the forloop shoul've got the three letters in the rna chain and translated it into Asparagine.
Needless to say, Idk how to do that. So It'd be necessary some help.
By the way, I hope I made myself clear with the explanation.