-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdss2dot.cc
65 lines (53 loc) · 1.75 KB
/
mdss2dot.cc
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
#include <cstdlib>
#include <fstream>
#include <string>
#include <set>
#include "argparse.hpp"
#include "mer_op.hpp"
#include "common.hpp"
typedef mer_op_type<K, ALPHA> mer_ops;
typedef mer_ops::mer_t mer_t;
struct MDSs2DOTArgs : argparse::Args {
std::string& mds_arg = arg("DS list file");
void welcome() override {
std::cout << "Generate dot file from MDS list" << std::endl;
}
};
int main(int argc, char* argv[]) {
const auto args = argparse::parse<MDSs2DOTArgs>(argc, argv);
std::ifstream is(args.mds_arg);
if(!is.good()) {
std::cerr << "Failed to open " << args.mds_arg << std::endl;
return EXIT_FAILURE;
}
std::cout << "digraph {\n";
std::string line, token;
std::set<mer_t> mds, dest;
while(std::getline(is, line)) {
mds.clear();
// Read a line <-> MDS
size_t start = 0, end;
while((end = line.find(',', start)) != std::string::npos) {
mds.insert(atoi(line.c_str() + start));
start = end + 1;
}
mds.insert(atoi(line.c_str() + start));
// Find potential F-move in MDS
for(auto m : mds) {
if(mer_ops::lb(m) != 0) continue;
bool has_fmove = true;
for(mer_t b = 1; has_fmove && b < mer_ops::alpha; ++b)
has_fmove = mds.find(mer_ops::lc(m, b)) != mds.end();
if(has_fmove) {
dest = mds;
for(mer_t b = 0; b < mer_ops::alpha; ++b) {
dest.erase(mer_ops::lc(m, b));
dest.insert(mer_ops::nmer(m, b));
}
std::cout << " n" << join(mds, '_') << " -> n" << join(dest, '_') << ";\n";
}
}
}
std::cout << "}\n";
return EXIT_SUCCESS;
}