| 1 | // ============================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : CT_dtree.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ============================================================= // |
|---|
| 10 | |
|---|
| 11 | #include "CT_hash.hxx" |
|---|
| 12 | #include "CT_ctree.hxx" |
|---|
| 13 | |
|---|
| 14 | PART *ConsensusTree::dtree(const GBT_TREE *tree, double weight, GBT_LEN len) { |
|---|
| 15 | /* destruct GBT-Tree and build partitions. This is done recursive by concatenate |
|---|
| 16 | all sons to build the father partition. All partitions are inserted in the |
|---|
| 17 | hashtable */ |
|---|
| 18 | // caution: I use the fact that each inner node must have two sons. |
|---|
| 19 | PART *ptree = 0; |
|---|
| 20 | if (tree->is_leaf) { |
|---|
| 21 | ptree = new PART(size, weight); |
|---|
| 22 | ptree->setbit(get_species_index(tree->name)); |
|---|
| 23 | } |
|---|
| 24 | else { |
|---|
| 25 | // In any possible case left and rightson always exist ... |
|---|
| 26 | PART *p1 = dtree(tree->leftson, weight, tree->leftlen); |
|---|
| 27 | PART *p2 = dtree(tree->rightson, weight, tree->rightlen); |
|---|
| 28 | |
|---|
| 29 | arb_assert(p1->disjunct_from(p2)); |
|---|
| 30 | |
|---|
| 31 | ptree = p1->clone(); |
|---|
| 32 | ptree->add_from(p2); |
|---|
| 33 | |
|---|
| 34 | registry->put_part(p1); |
|---|
| 35 | registry->put_part(p2); |
|---|
| 36 | } |
|---|
| 37 | ptree->set_len(len); |
|---|
| 38 | return ptree; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | void ConsensusTree::remember_subtrees(const GBT_TREE *tree, double weight) { |
|---|
| 43 | /* it is necessary to destruct the left and the right side separately, because |
|---|
| 44 | the root is only a virtual node and must be ignored. Moreover the left and |
|---|
| 45 | rightson are the same partition. So I may only insert right son. */ |
|---|
| 46 | |
|---|
| 47 | PART *p1 = dtree(tree->leftson, weight, 0.0); |
|---|
| 48 | PART *p2 = dtree(tree->rightson, weight, 0.0); |
|---|
| 49 | |
|---|
| 50 | arb_assert(p1->disjunct_from(p2)); |
|---|
| 51 | |
|---|
| 52 | delete p1; |
|---|
| 53 | |
|---|
| 54 | p2->set_len(tree->leftlen + tree->rightlen); |
|---|
| 55 | registry->put_part(p2); |
|---|
| 56 | } |
|---|