C ++ DNA翻译问题 [英] C++ DNA translation problem
本文介绍了C ++ DNA翻译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作一个程序,可以使用模板DNA并显示转录和翻译后形成的氨基酸序列
它有效,但仅适用于3个碱基。我希望它尽可能多地工作。
这就是我所拥有的:
我尝试过:
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;
}
推荐答案
你应该这样做:
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];
...
}
你需要找到并获得一些数据库(互联网,同事或学校)而不是写一些代码使用它。这是小菜一碟。
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.
>
不,紧接在
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.
这篇关于C ++ DNA翻译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文