source: branches/profile/PARSIMONY/AP_main.cxx

Last change on this file was 11488, checked in by westram, 10 years ago
  • reintegrates 'tree' into 'trunk'
    • implements #417 (multifurcate tree)
    • tree display
      • adds MULTIFURC MODE
      • reordered modes (synchronizes NTREE and PARSIMONY)
    • branch analysis
      • display number of multifurcations in 'mark long branches'
      • display "in-tree-distance" and "per-species-distance"
    • added function to toggle '100%' bootstraps
    • document bug in GBT_remove_leafs (#452)
  • adds:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : AP_main.cxx                                       //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include "AP_error.hxx"
12#include "ap_tree_nlen.hxx"
13
14using namespace std;
15
16// ---------------
17//      AP_ERR
18
19int AP_ERR::mode = 0;
20
21AP_ERR::~AP_ERR()
22{
23    delete text;
24}
25
26
27AP_ERR::AP_ERR (const char *pntr)
28// setzt den Fehlertext und zeigt ihn an
29{
30    text = pntr;
31    if (mode == 0) {
32        cout << "\n*** WARNING *** \n" << text << "\n";
33        cout.flush();
34    }
35}
36
37AP_ERR::AP_ERR (const char *pntr, const char *pntr2)
38{
39    text = pntr2;
40    if (mode == 0) {
41        cout << "\n***** WARNING  in " << pntr << "\n" << text << "\n";
42        cout.flush();
43    }
44}
45
46AP_ERR::AP_ERR (const char *pntr, const char *pntr2, const int core)
47{
48    text = pntr2;
49    cout << "\n*** FATAL ERROR *** " << core << " in " << pntr << "\n" << text << "\n";
50    cout.flush();
51    GBK_terminate("AP_ERR[1]");
52}
53
54AP_ERR::AP_ERR (const char *pntr, const int core)
55// setzt den Fehlertext
56// bricht ab
57{
58    text = pntr;
59    cout << "\n*** FATAL ERROR *** " << core << "\n" << text << "\n";
60    cout.flush();
61    GBK_terminate("AP_ERR[2]");
62}
63
64const char *AP_ERR::show()
65{
66    return text;
67}
68
69void AP_ERR::set_mode(int i) {
70    mode = i;
71}
72
73// ----------------
74//      AP_main
75
76GB_ERROR AP_main::open(const char *db_server) {
77    GB_ERROR error             = 0;
78    GLOBAL_gb_main             = GB_open(db_server, "rwt");
79    if (!GLOBAL_gb_main) error = GB_await_error();
80    return error;
81}
82
83void AP_main::user_push() {
84    this->user_push_counter = stack_level + 1;
85    this->push();
86}
87
88void AP_main::user_pop() {
89    // checks if user_pop possible
90    if (user_push_counter == stack_level) {
91        this->pop();    // changes user_push_counter if user pop
92    }
93    else {
94        new AP_ERR("AP_main::user_pop()", "No user pop possible");
95    }
96    return;
97}
98
99void AP_main::push() {
100    // if count > 1 the nodes are buffered more than once
101    // WARNING:: node only has to be buffered once in the stack
102    //
103    //
104    stack_level ++;
105    if (stack) list.push(stack);
106    stack = new AP_main_stack;
107    stack->last_user_buffer = this->user_push_counter;
108}
109
110void AP_main::pop() {
111    AP_tree_nlen *knoten;
112    if (!stack) {
113        new AP_ERR("AP_main::pop()", "Stack underflow !");
114        return;
115    }
116    while ((knoten = stack->pop())) {
117        if (stack_level != knoten->stack_level) {
118            GB_internal_error("AP_main::pop: Error in stack_level");
119            cout << "Main UPD - node UPD : " << stack_level << " -- " << knoten->stack_level << " \n";
120            return;
121        }
122        knoten->pop(stack_level);
123    }
124    delete stack;
125    stack_level --;
126    stack = list.pop();
127    user_push_counter = stack ? stack->last_user_buffer : 0;
128}
129
130void AP_main::clear() {
131    // removes count elements from the list
132    // because the current tree is used
133    //
134    // if stack_counter greater than last user_push then
135    // moves all not previous buffered nodes in the
136    // previous stack
137
138    AP_tree_nlen  *knoten;
139    AP_main_stack *new_stack;
140
141    if (!stack) {
142        new AP_ERR("AP_main::clear", "Stack underflow !");
143        return;
144    }
145    if (user_push_counter >= stack_level) {
146        if (stack != 0) {
147            if (stack->size() > 0) {
148                while (stack->size() > 0) {
149                    knoten = stack->pop();
150                    knoten->clear(stack_level, user_push_counter);
151                }
152            }
153            delete stack;
154            stack = list.pop();
155        }
156    }
157    else {
158        if (stack) {
159            new_stack = list.pop();
160            while ((knoten = stack->pop())) {
161                if (knoten->clear(stack_level, user_push_counter) != true) {
162                    // node is not cleared because buffered in previous node stack
163                    // node is instead copied in previous level
164                    if (new_stack) new_stack->push(knoten);
165                }
166            }
167            delete stack;
168            stack = new_stack;
169        }
170        else {
171            new AP_ERR("AP_main::clear");
172        }
173    }
174    stack_level --;
175    if (stack) user_push_counter = stack->last_user_buffer;
176    else user_push_counter = 0;
177
178}
179
180void AP_main::push_node(AP_tree_nlen *node, AP_STACK_MODE mode) {
181    //
182    //  stores node
183    //
184    if (!stack) {
185        if (mode & SEQUENCE)    node->unhash_sequence();
186        return;
187    }
188
189    if (stack_level < node->stack_level) {
190        GB_warning("AP_main::push_node: stack_level < node->stack_level");
191        return;
192    }
193
194    if (node->push(mode, stack_level))  stack->push(node);
195}
196
197void AP_main::set_tree_root(AWT_graphic_tree *agt_) {
198    ap_assert(agt == 0 && agt_ != 0);               // do only once
199    agt = agt_;
200}
201
202const char *AP_main::get_aliname() const {
203    return agt->tree_static->get_aliview()->get_aliname();
204}
205
Note: See TracBrowser for help on using the repository browser.