source: tags/arb_5.0/CONSENSUS_TREE/CT_ctree.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1/* CTREE -> consensus tree */
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include <arbdb.h>
7#include <arbdbt.h>
8
9#include "CT_part.hxx"
10#include "CT_hash.hxx"
11#include "CT_ntree.hxx"
12#include "CT_rbtree.hxx"
13#include "CT_dtree.hxx"
14
15int Tree_count;
16GB_HASH *Name_hash;
17
18/*  node_count  number of different leafs
19    names       name of each leaf   */
20void ctree_init(int node_count, char **names)
21{
22    int i;
23
24    Name_hash = GBS_create_hash((long) node_count, GB_MIND_CASE);
25
26    for(i=0; i< node_count; i++) {
27        GBS_write_hash(Name_hash, names[i], (long) i);
28    }
29
30    part_init(node_count);  /* Amount of Bits used */
31    hash_init();
32    destree_init(Name_hash);
33    rb_init(names);
34    Tree_count = 0;
35
36}
37
38
39/* Insert a GBT-tree in the Hash-Table */
40/* The GBT-tree is destructed afterwards! */
41void insert_ctree(GBT_TREE *tree, int weight)
42{
43    Tree_count += weight;
44    des_tree(tree, weight);
45}
46
47
48/* Get new consensus-tree -> GBT-tree */
49/* This function is little bit tricky:
50   the root-partition consist of 111....111 so it must have two sons
51   that represent the same partition son1 == ~son2 to do this we must split
52   the fist son-partition in two parts through logical calculation there
53   could only be one son! */
54GBT_TREE *get_ctree(void)
55{
56    PART *p;
57    NT_NODE *n;
58
59    hash_settreecount(Tree_count);
60    ntree_init();
61    build_sorted_list();
62    p = hash_getpart();
63    while(p != NULL) {
64        insert_ntree(p);
65        p = hash_getpart();
66    }
67    n = ntree_get();
68    if(n->son_list->next == NULL) { /* if father has only one son */
69        p  = part_new();
70        n->son_list->node->part->len /= 2;
71        part_copy(n->son_list->node->part, p);
72        part_invert(p);
73        insert_ntree(p);
74        n = ntree_get();
75    }
76    else {  /* if father has tree sons */
77            /* this case should happen nerver! */
78        printf("Es gibt noch was zu tun !!!!!! \n");
79    }
80
81    return rb_gettree(n);
82}
Note: See TracBrowser for help on using the repository browser.