1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : ps_my2asciipaths.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Wolfram Foerster in October 2002 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "ps_node.hxx" |
---|
13 | |
---|
14 | // GLOBALS |
---|
15 | |
---|
16 | typedef pair<bool, SpeciesID> Step; |
---|
17 | static vector<Step> *__PATH = new vector<Step>; |
---|
18 | |
---|
19 | static void PS_print_paths(const PS_NodePtr& _ps_node) { |
---|
20 | // recursively print the paths to the leafs |
---|
21 | |
---|
22 | // path |
---|
23 | __PATH->push_back(Step(_ps_node->hasInverseProbes(), _ps_node->hasProbes() ? _ps_node->getNum() : -(_ps_node->getNum()))); |
---|
24 | |
---|
25 | // children |
---|
26 | if (_ps_node->hasChildren()) { |
---|
27 | for (PS_NodeMapConstIterator i = _ps_node->getChildrenBegin(); i != _ps_node->getChildrenEnd(); ++i) { |
---|
28 | PS_print_paths(i->second); |
---|
29 | } |
---|
30 | } |
---|
31 | else { |
---|
32 | // print path in leaf nodes |
---|
33 | printf("[%4zu] ", __PATH->size()); |
---|
34 | for (vector<Step>::const_iterator i=__PATH->begin(); i != __PATH->end(); ++i) { |
---|
35 | printf("%4i%c ", i->second, i->first ? '+' : ' '); |
---|
36 | } |
---|
37 | printf("\n"); |
---|
38 | } |
---|
39 | |
---|
40 | // path |
---|
41 | __PATH->pop_back(); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | // ==================================================== |
---|
46 | // ==================================================== |
---|
47 | |
---|
48 | int main(int argc, char *argv[]) { |
---|
49 | |
---|
50 | // open probe-set-database |
---|
51 | if (argc < 2) { |
---|
52 | printf("Missing arguments\n Usage %s <database name>\n", argv[0]); |
---|
53 | exit(1); |
---|
54 | } |
---|
55 | |
---|
56 | const char *input_DB_name = argv[1]; |
---|
57 | |
---|
58 | printf("Opening probe-set-database '%s'..\n", input_DB_name); |
---|
59 | PS_FileBuffer *fb = new PS_FileBuffer(input_DB_name, PS_FileBuffer::READONLY); |
---|
60 | PS_NodePtr root(new PS_Node(-1)); |
---|
61 | root->load(fb); |
---|
62 | printf("loaded database (enter to continue)\n"); |
---|
63 | |
---|
64 | |
---|
65 | for (PS_NodeMapConstIterator i = root->getChildrenBegin(); i != root->getChildrenEnd(); ++i) { |
---|
66 | PS_print_paths(i->second); |
---|
67 | } |
---|
68 | |
---|
69 | printf("(enter to continue)\n"); |
---|
70 | |
---|
71 | delete fb; |
---|
72 | root.setNull(); |
---|
73 | printf("root should be destroyed now\n"); |
---|
74 | printf("(enter to continue)\n"); |
---|
75 | |
---|
76 | return 0; |
---|
77 | } |
---|