-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphiX174_kmer.cpp
62 lines (52 loc) · 1.31 KB
/
phiX174_kmer.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
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <stack>
std::vector<std::string>
make_Euler_cycle(std::map<std::string, std::vector<std::string>> graph)
{
std::stack<std::string> verteces;
std::vector<std::string> path;
path.reserve(graph.size());
verteces.push(graph.begin()->first);
std::string current = verteces.top();
while (not verteces.empty())
{
current = verteces.top();
if (not graph[current].empty())
{
verteces.push(std::move(graph[current].back()));
graph[current].pop_back();
continue;
}
path.emplace_back(std::move(current));
verteces.pop();
}
std::reverse(path.begin(), path.end());
return path;
}
std::map<std::string, std::vector<std::string>>
construct_DeBruijn_graph()
{
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::string s;
std::map<std::string, std::vector<std::string>> graph;
while (std::cin >> s)
graph[s.substr(0, s.size() - 1)].emplace_back(s.substr(1));
return graph;
}
void print_genome(const std::vector<std::string> &cycle)
{
std::cout << cycle.front();
for (size_t i = 1; i < cycle.size() - 9; ++i)
std::cout << cycle[i].back();
std::cout << std::endl;
}
int main()
{
print_genome(make_Euler_cycle(construct_DeBruijn_graph()));
return 0;
}