-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interactive.hpp
102 lines (95 loc) · 4.02 KB
/
Interactive.hpp
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
#ifndef _Interactive_HPP_
#define _Interactive_HPP_
#include "MetagraphInterface.h"
#include "seedExtension/VisualizeGraph.hpp"
#include <iostream>
class InteractiveAndRender {
public:
InteractiveAndRender(std::shared_ptr<Configuration const> config) {
auto graph = config->metagraphInterface();
std::cout << "k in Graph = " << graph->getK() << '\n';
std::cout << "nNodes = " << graph->numNodes() << '\n';
std::cout << "enter kmer (all capital letters) or id=int " << graph->numNodes() << " or \"show\" to render sub graph" << '\n';
std::string s = "";
std::cin >> s;
size_t id = graph->getK() - 10;
while (s != "q") {
// read Kmer
if(s.size() == graph->getK()) {
id = graph->getNode(s);
}
// render graph
else if((int)(s.find("show")) != -1 || (int)(s.find("Show")) != -1) {
std::vector<MetagraphInterface::NodeID> ids{id};
std::cout << "if current node should be rendered: enter int=pathlength" << '\n';
std::cout << "or kmers one after the other (followed by int=pathlength) to plot multiple nodes" << '\n';
std::string userinput = "";
std::cin >> userinput;
// read kmers
//clear previous node ids
if (userinput.size()>2) {
ids.clear();
}
// read kmers
while (userinput.size()>2) {
ids.push_back(graph->getNode(userinput));
std::cin >> userinput;
}
unsigned pathlength = 1;
try {
pathlength = std::stoi(userinput);
std::cout << "you entered: " << pathlength << '\n';
}
catch (std::invalid_argument & e) {
std::cout << "this aint a number" << '\n';
}
if ((int)(s.find("show")) != -1) VisualizeGraph{graph, ids, pathlength, config->binsize(), false};
// also draw edges that dont have an extending annotation
if ((int)(s.find("Show")) != -1) VisualizeGraph{graph, ids, pathlength, config->binsize(), true};
int dot = system("dot -Tpng graph.gv -o graph.png");
if (dot != 0) {
std::cout << "error when calling dot" << '\n';
}
int eog = system("eog graph.png");
if (eog != 0) {
std::cout << "error when calling eog" << '\n';
}
}
// node id
else {
try {
id = std::stoull(s);
id = id >= graph->numNodes() ? graph->numNodes() - 1 : id;
}
catch (std::invalid_argument & e) {
std::cout << "this aint a number" << '\n';
}
}
std::cout << "current id = " << id << ", kmer = " << graph->getKmer(id) << '\n';
PathBundleTip tt;
for (auto anno : graph->getAnnotation(id)) {
std::cout << "\t";
tt.printMetaAnno(anno);
}
std::cout << '\n';
for (auto outId : graph->getOutgoing(id)) {
std::cout << "outgoing id = " << outId << ", kmer = " << graph->getKmer(outId) << '\n';
for (auto anno: graph->getAnnotation(outId)) {
std::cout << "\t";
tt.printMetaAnno(anno);
}
}
std::cout << '\n';
for (auto outId : graph->getIncoming(id)) {
std::cout << "incoming id = " << outId << ", kmer = " << graph->getKmer(outId) << '\n';
for (auto anno: graph->getAnnotation(outId)) {
std::cout << "\t";
tt.printMetaAnno(anno);
}
}
std::cin>>s;
}
exit(0);
}
};
#endif // _Interactive_HPP_