source: tags/svn.1.5.4/PROBE/PT_debug.cxx

Last change on this file was 8309, checked in by westram, 14 years ago
  • moved much code into static scope

(partly reverted by [8310])

File size: 6.5 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : PT_debug.cxx                                    //
4//   Purpose   : debugging code                                  //
5//                                                               //
6//   Coded by Ralf Westram (coder@reallysoft.de) in March 2011   //
7//   Institute of Microbiology (Technical University Munich)     //
8//   http://www.arb-home.de/                                     //
9//                                                               //
10// ============================================================= //
11
12#include "probe.h"
13#include "probe_tree.h"
14#include "pt_prototypes.h"
15
16#if defined(DEBUG)
17
18#define DEBUG_MAX_CHAIN_SIZE 1000
19#define DEBUG_TREE_DEEP      PT_POS_TREE_HEIGHT+50
20
21struct PT_debug {
22    int chainsizes[DEBUG_MAX_CHAIN_SIZE][DEBUG_TREE_DEEP];
23    int chainsizes2[DEBUG_MAX_CHAIN_SIZE];
24    int splits[DEBUG_TREE_DEEP][PT_B_MAX];
25    int nodes[DEBUG_TREE_DEEP];
26    int tips[DEBUG_TREE_DEEP];
27    int chains[DEBUG_TREE_DEEP];
28    int chaincount;
29};
30static PT_debug *ptds;
31
32struct PT_chain_count {
33    int operator() (const DataLoc&) {
34        psg.height++;
35        return 0;
36    }
37};
38
39static void analyse_tree(POS_TREE *pt, int height) {
40    PT_NODE_TYPE type;
41    POS_TREE *pt_help;
42    int i;
43    int basecnt;
44    type = PT_read_type(pt);
45    switch (type) {
46        case PT_NT_NODE:
47            ptds->nodes[height]++;
48            basecnt = 0;
49            for (i=PT_QU; i<PT_B_MAX; i++) {
50                if ((pt_help = PT_read_son(pt, (PT_BASES)i)))
51                {
52                    basecnt++;
53                    analyse_tree(pt_help, height+1);
54                };
55            }
56            ptds->splits[height][basecnt]++;
57            break;
58        case PT_NT_LEAF:
59            ptds->tips[height]++;
60            break;
61        default:
62            ptds->chains[height]++;
63            psg.height = 0;
64            PT_forwhole_chain(pt, PT_chain_count());
65            if (psg.height >= DEBUG_MAX_CHAIN_SIZE) psg.height = DEBUG_MAX_CHAIN_SIZE;
66            ptds->chainsizes[psg.height][height]++;
67            ptds->chainsizes2[psg.height]++;
68            ptds->chaincount++;
69            if (ptds->chaincount<20) {
70                printf("\n\n\n\n");
71                PT_forwhole_chain(pt, PTD_chain_print());
72            }
73            break;
74    };
75}
76#endif
77
78void PT_dump_tree_statistics() {
79#if defined(DEBUG)
80    // show various debug information about the tree
81    ptds = (PT_debug *)calloc(sizeof(PT_debug), 1);
82    analyse_tree(psg.pt, 0);
83    int i, j, k;
84    int sum = 0;            // sum of chains
85    for (i=0; i<DEBUG_TREE_DEEP; i++) {
86        k = ptds->nodes[i];
87        if (k) {
88            sum += k;
89            printf("nodes at deep %i: %i        sum %i\t\t", i, k, sum);
90            for (j=0; j<PT_B_MAX; j++) {
91                k =     ptds->splits[i][j];
92                printf("%i:%i\t", j, k);
93            }
94            printf("\n");
95        }
96    }
97    sum = 0;
98    for (i=0; i<DEBUG_TREE_DEEP; i++) {
99        k = ptds->tips[i];
100        sum += k;
101        if (k)  printf("tips at deep %i: %i     sum %i\n", i, k, sum);
102    }
103    sum = 0;
104    for (i=0; i<DEBUG_TREE_DEEP; i++) {
105        k = ptds->chains[i];
106        if (k) {
107            sum += k;
108            printf("chains at deep %i: %i       sum %i\n", i, k, sum);
109        }
110    }
111    sum = 0;
112    int sume = 0;           // sum of chain entries
113    for (i=0; i<DEBUG_MAX_CHAIN_SIZE; i++) {
114            k =     ptds->chainsizes2[i];
115            sum += k;
116            sume += i*k;
117            if (k) printf("chain of size %i occur %i    sc %i   sce %i\n", i, k, sum, sume);
118    }
119#endif
120}
121
122// --------------------------------------------------------------------------------
123
124#if defined(DEBUG)
125
126inline char PT_BASES_2_char(PT_BASES i) {
127    static char buffer[] = "x";
128
129    buffer[0] = i;
130    PT_base_2_string(buffer, 1);
131
132    return buffer[0];
133}
134
135class PT_dump_leaf {
136    const char *prefix;
137public:
138    PT_dump_leaf(const char *Prefix) : prefix(Prefix) {}
139
140    int operator()(const DataLoc& leaf) {
141        struct probe_input_data& data = psg.data[leaf.name];
142
143        PT_BASES b = (PT_BASES)data.get_data()[leaf.rpos];
144
145        printf("%s[%c] %s apos=%i rpos=%i\n", prefix, PT_BASES_2_char(b), data.get_name(), leaf.apos, leaf.rpos);
146        return 0;
147    }
148};
149#endif // DEBUG
150
151void PT_dump_POS_TREE_recursive(POS_TREE *IF_DEBUG(pt), const char *IF_DEBUG(prefix)) {
152#if defined(DEBUG)
153    switch (PT_read_type(pt)) {
154        case PT_NT_NODE:
155            for (int i = PT_QU; i<PT_B_MAX; i++) {
156                PT_BASES  b   = PT_BASES(i);
157                POS_TREE *son = PT_read_son(pt, b);
158                if (son) {
159                    char *subPrefix = GBS_global_string_copy("%s%c", prefix, b == PT_QU ? '.' : PT_BASES_2_char(b));
160                    PT_dump_POS_TREE_recursive(son, subPrefix);
161                    free(subPrefix);
162                }
163            }
164            break;
165        case PT_NT_LEAF: {
166            char         *subPrefix = GBS_global_string_copy("{l} %s", prefix);
167            PT_dump_leaf  dump_leaf(subPrefix);
168            dump_leaf(DataLoc(pt));
169            free(subPrefix);
170            break;
171        }
172        case PT_NT_CHAIN: {
173            char *subPrefix = GBS_global_string_copy("{c} %s", prefix);
174            PT_forwhole_chain(pt, PT_dump_leaf(subPrefix));
175            free(subPrefix);
176            break;
177        }
178        default:
179            printf("%s [unhandled]\n", prefix);
180            pt_assert(0);
181            break;
182    }
183#endif
184}
185
186// --------------------------------------------------------------------------------
187
188void PT_dump_POS_TREE(POS_TREE * IF_DEBUG(node)) {
189    // Debug function for all stages
190#if defined(DEBUG)
191    if (!node) printf("Zero node\n");
192
193    {
194        long i;
195        PT_READ_PNTR(&node->data, i);
196        printf("node father 0x%lx\n", i);
197    }
198
199    switch (PT_read_type(node)) {
200        case PT_NT_LEAF: {
201            DataLoc loc(node);
202            printf("leaf %i:%i,%i\n", loc.name, loc.rpos, loc.apos);
203            break;
204        }
205        case PT_NT_NODE:
206            for (long i = 0; i < PT_B_MAX; i++) {
207                printf("%6li:0x%p\n", i, PT_read_son(node, (PT_BASES)i));
208            }
209            break;
210        case PT_NT_CHAIN:
211            printf("chain:\n");
212            PT_forwhole_chain(node, PTD_chain_print());
213            break;
214        case PT_NT_SAVED:
215            printf("saved:\n");
216            break;
217        default:
218            printf("?????\n");
219            break;
220    }
221#endif
222}
223
Note: See TracBrowser for help on using the repository browser.