root/trunk/CONSENSUS_TREE/CT_dtree.cxx

Revision 8507, 2.1 KB (checked in by westram, 2 months ago)
  • use double for weights ([0..1] instead of [0..10000])
  • added tests using weights != 1
    • fixed weight/length calculation to make generated consense tree independent from used weight (as long as the same weight is used for all added trees)
  • no longer generates zero-bootstrap at root
    • strictly speaking it is wrong now (since the edge from virtual root to tree cant exist, ergo it's probability should be zero)
    • practically
      • that zero probability would be a special case (and is an error at all other edges)
      • a probability of 100% is used (which gets skipped when saving the tree)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
14PART *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
42void 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}
Note: See TracBrowser for help on using the browser.