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