Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a program that can take Template DNA and show the amino acid sequence that is formed after transcription and translation
It works, but only for 3 bases. I would like it to work for as many bases as possible.
This is what I have:

What I have tried:

#include <iostream>
#include 
#include <string>

using namespace std;

typedef std::map<std::string, std::string> TStrStrMap;
typedef std::pair<std::string, std::string> dnaTemplatePair;

int main(int argc, char *argv[])
{
	TStrStrMap oMap;

	oMap.insert(dnaTemplatePair("TTT", "Phe"));
	oMap.insert(dnaTemplatePair("TTC", "Phe"));
	oMap.insert(dnaTemplatePair("TTA", "Leu"));
	oMap.insert(dnaTemplatePair("TTG", "Leu"));
	oMap.insert(dnaTemplatePair("TCT", "Ser"));
	oMap.insert(dnaTemplatePair("TCC", "Ser"));
	oMap.insert(dnaTemplatePair("TCA", "Ser"));
	oMap.insert(dnaTemplatePair("TCG", "Ser"));
	oMap.insert(dnaTemplatePair("TAT", "Tyr"));
	oMap.insert(dnaTemplatePair("TAC", "Tyr"));
	oMap.insert(dnaTemplatePair("TAA", "STOP"));
	oMap.insert(dnaTemplatePair("TAG", "STOP"));
	oMap.insert(dnaTemplatePair("TGT", "Cys"));
	oMap.insert(dnaTemplatePair("TGC", "Cys"));
	oMap.insert(dnaTemplatePair("TGA", "STOP"));
	oMap.insert(dnaTemplatePair("TGG", "Trp"));
	oMap.insert(dnaTemplatePair("CTT", "Leu"));
	oMap.insert(dnaTemplatePair("CTC", "Leu"));
	oMap.insert(dnaTemplatePair("CTA", "Leu"));
	oMap.insert(dnaTemplatePair("CTG", "Leu"));
	oMap.insert(dnaTemplatePair("CCT", "Pro"));
	oMap.insert(dnaTemplatePair("CCC", "Pro"));
	oMap.insert(dnaTemplatePair("CCA", "Pro"));
	oMap.insert(dnaTemplatePair("CCG", "Pro"));
	oMap.insert(dnaTemplatePair("CAT", "His"));
	oMap.insert(dnaTemplatePair("CAC", "His"));
	oMap.insert(dnaTemplatePair("CAA", "Gln"));
	oMap.insert(dnaTemplatePair("CAG", "Gln"));
	oMap.insert(dnaTemplatePair("CGU", "Arg"));
	oMap.insert(dnaTemplatePair("CGC", "Arg"));
	oMap.insert(dnaTemplatePair("CGA", "Arg"));
	oMap.insert(dnaTemplatePair("CGG", "Arg"));
	oMap.insert(dnaTemplatePair("ATT", "Ile"));
	oMap.insert(dnaTemplatePair("ATC", "Ile"));
	oMap.insert(dnaTemplatePair("ATA", "Ile"));
	oMap.insert(dnaTemplatePair("ATG", "Met"));
	oMap.insert(dnaTemplatePair("ACT", "Thr"));
	oMap.insert(dnaTemplatePair("ACC", "Thr"));
	oMap.insert(dnaTemplatePair("ACA", "Thr"));
	oMap.insert(dnaTemplatePair("ACG", "Thr"));
	oMap.insert(dnaTemplatePair("AAT", "Asn"));
	oMap.insert(dnaTemplatePair("AAC", "Asn"));
	oMap.insert(dnaTemplatePair("AAA", "Lys"));
	oMap.insert(dnaTemplatePair("AAG", "Lys"));
	oMap.insert(dnaTemplatePair("AGT", "Ser"));
	oMap.insert(dnaTemplatePair("AGC", "Ser"));
	oMap.insert(dnaTemplatePair("AGA", "Arg"));
	oMap.insert(dnaTemplatePair("AGG", "Arg"));
	oMap.insert(dnaTemplatePair("GTT", "Val"));
	oMap.insert(dnaTemplatePair("GTC", "Val"));
	oMap.insert(dnaTemplatePair("GTA", "Val"));
	oMap.insert(dnaTemplatePair("GTG", "Val"));
	oMap.insert(dnaTemplatePair("GCT", "Ala"));
	oMap.insert(dnaTemplatePair("GCC", "Ala"));
	oMap.insert(dnaTemplatePair("GCA", "Ala"));
	oMap.insert(dnaTemplatePair("GCG", "Ala"));
	oMap.insert(dnaTemplatePair("GAT", "Asp"));
	oMap.insert(dnaTemplatePair("GAC", "Asp"));
	oMap.insert(dnaTemplatePair("GAA", "Glu"));
	oMap.insert(dnaTemplatePair("GAG", "Glu"));
	oMap.insert(dnaTemplatePair("GGT", "Gly"));
	oMap.insert(dnaTemplatePair("GGC", "Gly"));
	oMap.insert(dnaTemplatePair("GGA", "Gly"));
	oMap.insert(dnaTemplatePair("GGG", "Gly"));
	std::string dnaTemplate;
	std:: cout << "Enter DNA Template: " << std::endl;;
	std:: cin >> dnaTemplate;

	std::string strValue = oMap[dnaTemplate];
	if(strValue!="")
	{
			std::cout << "The Amino Acid Sequence will be: " << strValue << endl;
	}
	else
	{
		TStrStrMap::iterator p;
					bool bFound=false;

			for(p = oMap.begin(); p!=oMap.end(); ++p)
			{
					std::string strKey;
					strValue = dnaTemplate;
					strKey= p->second;
					if( strValue == strKey)
					{

							std::cout << "The Amino Acid Sequence will be: " << p->first << std::endl;
							bFound = true;
					}
			}

			if(!bFound)
			{
					std::cout << "Look at your DNA Template again, and try again." << std::endl;
			}
	}
	return 0;

}
Posted
Updated 22-Nov-17 22:11pm
v2
Comments
phil.o 16-Nov-17 16:49pm    
You have a map which associates bases-sequences with corresponding amino-acids. You just have to qualify your map with larger bases-sequences.
I suspect it's more a genetic-engineering problem than a coding problem.
Member 13525452 16-Nov-17 18:20pm    
How? DNA is randomized and comes in base pairs. Doing every single combination a DNA template could have and putting that into the map would take forever.
phil.o 16-Nov-17 18:31pm    
I understand that. But then I do not understand your statement saying you would like it to work with as many bases as possible. Are you talking about the number of bases in the map's keys? What is the question, exactly? You can find lots of code samples which will allow you to find all possible sequences (combinations) of bases of a certain length, but then, you will have somehow to link them to an amino-acid, or to a STOP codon.
Or maybe you simply mean that DNA template can be larger than 3, and you want to split it into 3-bases chunks?
Please clarify.
Member 13525452 21-Nov-17 16:25pm    
I just commented below and explained it but to answer the second question. Yes, the input can be larger than 3 and I want it split into 3-bases "chunks."
Bernhard Hiller 17-Nov-17 4:39am    
Where is your problem? You just need to iterate thru the input data in junks of 3 bases, find the amino acid for the triplet, take the next triplet, etc.
Only later on you'll think of start and stop codons, and even more complicated cases of sequences around a start codon, splicing, ...

You should do something like that:
int n = dnaTemplate.size()-2;
for (int i = 0; i < n; i+=3)
{
   std::string triplet = s.substr(i, 3);
   std::string aminoacid = oMap[triplet];
   ...
}
 
Share this answer
 
Comments
Member 13525452 21-Nov-17 16:23pm    
Where would I place this?
Mikhail Semenov 21-Nov-17 17:40pm    
After you get your template.Instead of ... you put the printing of your amino acid and extra processing if you wish.
Member 13525452 22-Nov-17 15:25pm    
Can you be a little more specific. So immediately after if(strValue!="") ?
You need to find and get some database (internet, collegues or schools) and than write some code to work with it. This is a piece of cake.
 
Share this answer
 
No, immediately after
std:: cin >> dnaTemplate;


The line
std::string strValue = oMap[dnaTemplate];


is incorrect: you are trying to use the whole string as an index in a map. You should use one triplet at a time.
 
Share this answer
 
Comments
Member 13525452 22-Nov-17 15:57pm    
so what is s.substr it is not being recognized.
Sorry, my nmistake:

int n = dnaTemplate.size()-2;
for (int i = 0; i < n; i+=3)
{
   std::string triplet = dnaTemplate.substr(i, 3);
   std::string aminoacid = oMap[triplet];
   ...
}
 
Share this answer
 
Comments
Mikomike123453 27-Nov-17 16:08pm    
Hey, I made a new account. Would it be like this?

#include <iostream>
#include
#include <string>

using namespace std;

typedef std::map<std::string, std::string> TStrStrMap;
typedef std::pair<std::string, std::string> dnaTemplatePair;

int main(int argc, char *argv[])
{
TStrStrMap oMap;

oMap.insert(dnaTemplatePair("TTT", "Phe"));
oMap.insert(dnaTemplatePair("TTC", "Phe"));
oMap.insert(dnaTemplatePair("TTA", "Leu"));
oMap.insert(dnaTemplatePair("TTG", "Leu"));
oMap.insert(dnaTemplatePair("TCT", "Ser"));
oMap.insert(dnaTemplatePair("TCC", "Ser"));
oMap.insert(dnaTemplatePair("TCA", "Ser"));
oMap.insert(dnaTemplatePair("TCG", "Ser"));
oMap.insert(dnaTemplatePair("TAT", "Tyr"));
oMap.insert(dnaTemplatePair("TAC", "Tyr"));
oMap.insert(dnaTemplatePair("TAA", "STOP"));
oMap.insert(dnaTemplatePair("TAG", "STOP"));
oMap.insert(dnaTemplatePair("TGT", "Cys"));
oMap.insert(dnaTemplatePair("TGC", "Cys"));
oMap.insert(dnaTemplatePair("TGA", "STOP"));
oMap.insert(dnaTemplatePair("TGG", "Trp"));
oMap.insert(dnaTemplatePair("CTT", "Leu"));
oMap.insert(dnaTemplatePair("CTC", "Leu"));
oMap.insert(dnaTemplatePair("CTA", "Leu"));
oMap.insert(dnaTemplatePair("CTG", "Leu"));
oMap.insert(dnaTemplatePair("CCT", "Pro"));
oMap.insert(dnaTemplatePair("CCC", "Pro"));
oMap.insert(dnaTemplatePair("CCA", "Pro"));
oMap.insert(dnaTemplatePair("CCG", "Pro"));
oMap.insert(dnaTemplatePair("CAT", "His"));
oMap.insert(dnaTemplatePair("CAC", "His"));
oMap.insert(dnaTemplatePair("CAA", "Gln"));
oMap.insert(dnaTemplatePair("CAG", "Gln"));
oMap.insert(dnaTemplatePair("CGU", "Arg"));
oMap.insert(dnaTemplatePair("CGC", "Arg"));
oMap.insert(dnaTemplatePair("CGA", "Arg"));
oMap.insert(dnaTemplatePair("CGG", "Arg"));
oMap.insert(dnaTemplatePair("ATT", "Ile"));
oMap.insert(dnaTemplatePair("ATC", "Ile"));
oMap.insert(dnaTemplatePair("ATA", "Ile"));
oMap.insert(dnaTemplatePair("ATG", "Met"));
oMap.insert(dnaTemplatePair("ACT", "Thr"));
oMap.insert(dnaTemplatePair("ACC", "Thr"));
oMap.insert(dnaTemplatePair("ACA", "Thr"));
oMap.insert(dnaTemplatePair("ACG", "Thr"));
oMap.insert(dnaTemplatePair("AAT", "Asn"));
oMap.insert(dnaTemplatePair("AAC", "Asn"));
oMap.insert(dnaTemplatePair("AAA", "Lys"));
oMap.insert(dnaTemplatePair("AAG", "Lys"));
oMap.insert(dnaTemplatePair("AGT", "Ser"));
oMap.insert(dnaTemplatePair("AGC", "Ser"));
oMap.insert(dnaTemplatePair("AGA", "Arg"));
oMap.insert(dnaTemplatePair("AGG", "Arg"));
oMap.insert(dnaTemplatePair("GTT", "Val"));
oMap.insert(dnaTemplatePair("GTC", "Val"));
oMap.insert(dnaTemplatePair("GTA", "Val"));
oMap.insert(dnaTemplatePair("GTG", "Val"));
oMap.insert(dnaTemplatePair("GCT", "Ala"));
oMap.insert(dnaTemplatePair("GCC", "Ala"));
oMap.insert(dnaTemplatePair("GCA", "Ala"));
oMap.insert(dnaTemplatePair("GCG", "Ala"));
oMap.insert(dnaTemplatePair("GAT", "Asp"));
oMap.insert(dnaTemplatePair("GAC", "Asp"));
oMap.insert(dnaTemplatePair("GAA", "Glu"));
oMap.insert(dnaTemplatePair("GAG", "Glu"));
oMap.insert(dnaTemplatePair("GGT", "Gly"));
oMap.insert(dnaTemplatePair("GGC", "Gly"));
oMap.insert(dnaTemplatePair("GGA", "Gly"));
oMap.insert(dnaTemplatePair("GGG", "Gly"));
std::string dnaTemplate;
std:: cout << "Enter DNA Template: " << std::endl;;
std:: cin >> dnaTemplate;
int n = dnaTemplate.size()-2;
for (int i = 0; i < n; i+=3)
{
std::string triplet = dnaTemplate.substr(i, 3);
std::string strValue = oMap[triplet];
if(strValue!="")
}
{
std::cout << "The Amino Acid Sequence will be: " << strValue << endl;
}
else
{
TStrStrMap::iterator p;
bool bFound=false;

for(p = oMap.begin(); p!=oMap.end(); ++p)
{
std::string strKey;
strValue = dnaTemplate;
strKey= p->second;
if( strValue == strKey)
{

std::cout << "The Amino Acid Sequ

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900