-
Notifications
You must be signed in to change notification settings - Fork 0
/
aminotranslate.cpp
107 lines (92 loc) · 2.45 KB
/
aminotranslate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* aminotranslate.cpp
*
* Created on: 2018/03/10
* Author: user
*/
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <algorithm>
#include <vector>
std::vector<std::string> translate(std::string seq)
{
std::map<char,std::vector<std::string> > codontable{
{'I', {"ATA", "ATC", "ATT"}},
{'M', {"ATG"}},
{'T', {"ACA", "ACC", "ACG", "ACT"}},
{'N', {"AAC", "AAT"}},
{'K', {"AAA", "AAG"}},
{'S', {"AGC", "AGT", "TCA", "TCC", "TCG", "TCT"}},
{'R', {"AGA", "AGG", "CGA", "CGC", "CGG", "CGT"}},
{'L', {"CTA", "CTC", "CTG", "CTT", "TTA", "TTG"}},
{'P', {"CCA", "CCC", "CCG", "CCT"}},
{'H', {"CAC", "CAT"}},
{'Q', {"CAA", "CAG"}},
{'V', {"GTA", "GTC", "GTG", "GTT"}},
{'A', {"GCA", "GCC", "GCG", "GCT"}},
{'D', {"GAC", "GAT"}},
{'E', {"GAA", "GAG"}},
{'G', {"GGA", "GGC", "GGG", "GGT"}},
{'F', {"TTC", "TTT"}},
{'Y', {"TAC", "TAT"}},
{'C', {"TGC", "TGT"}},
{'W', {"TGG"}}
};
std::map<char,std::vector<std::string> >::iterator mapkey;
std::size_t strlen;
strlen = seq.size();
char amino;
std::string buff, temp;
if(int(strlen) == 1)
{
std::vector<std::string> DNAseq;
amino = seq.back();
mapkey = codontable.find(amino);
for(auto vectit = mapkey->second.begin(); vectit < mapkey->second.end(); ++vectit)
{
buff = *vectit;
DNAseq.push_back(buff);
}
return DNAseq;
}
else
{
amino = seq.back();
temp = seq.substr(0, strlen - 1);
std::vector<std::string> DNAseq = translate(temp);
int n = DNAseq.size();
for(int i = 0; i < n; ++i)
{
std::string buff1 = DNAseq[i];
mapkey = codontable.find(amino);
for(auto vectit = mapkey->second.begin(); vectit < mapkey->second.end(); ++vectit)
{
std::string buff2 = *vectit;
buff = buff1 + buff2;
DNAseq.push_back(buff);
}
}
DNAseq.erase(DNAseq.begin(), DNAseq.begin()+n);
return DNAseq;
}
}
int main()
{
int i = 0;
std::string seq;
std::vector<std::string> DNAseq;
seq = "";
std::cout << "This program generates all possible DNA sequences coding the amino acid sequence." << std::endl;
std::cout << "Input amino acid sequence :" << std::endl;
std::cout << "(Press Enter key to finish.)" << std::endl;
std::getline(std::cin,seq);
DNAseq = translate(seq);
for(i = 0; i < int(DNAseq.size()); ++i)
{
std::cout << DNAseq[i] << std::endl;
}
return 0;
}