root/trunk/CONSENSUS_TREE/CT_hash.cxx

Revision 8507, 2.0 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_hash.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_ntree.hxx"
13#include "CT_ctree.hxx"
14
15#include <arb_sort.h>
16
17PART *PartRegistry::get_part() {
18    /*! each call to get_part() returns the next part from the sorted PART-list.
19     * build_sorted_list() has to be called once before.
20     */
21
22    arb_assert(!sorted.empty()); // call build_sorted_list before
23   
24    PART *p = NULL;
25    if (retrieved<sorted.size()) {
26        p = sorted[retrieved++];
27    }
28    return p;
29}
30
31void PartRegistry::put_part(PART*& part) {
32    //! insert part in PartRegistry (destroys/reassigns part)
33
34    arb_assert(sorted.empty()); // too late, already build_sorted_list
35    part->standardize();
36
37    PartSet::iterator found = parts.find(part);
38
39    if (found != parts.end()) {
40        (*found)->add(part);
41        delete part;
42    }
43    else {
44        parts.insert(part);
45    }
46    part = NULL;
47}
48
49inline bool insertionOrder_less(const PART *p1, const PART *p2) {
50    return p1->insertionOrder_cmp(p2)<0;
51}
52
53void PartRegistry::build_sorted_list(double overall_weight) {
54    //! sort the parts into insertion order.
55
56    arb_assert(sorted.empty());
57    arb_assert(!parts.empty());
58     
59    copy(parts.begin(), parts.end(), std::back_insert_iterator<PartVector>(sorted));
60    sort(sorted.begin(), sorted.end(), insertionOrder_less);
61    parts.clear();
62
63    for (size_t i = 0; i<sorted.size(); ++i) {
64        PART *pi = sorted[i];
65        pi->takeMean(overall_weight);
66    }
67
68    arb_assert(!sorted.empty());
69}
Note: See TracBrowser for help on using the browser.