1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : NJ.hxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #ifndef NJ_HXX |
---|
12 | #define NJ_HXX |
---|
13 | |
---|
14 | #ifndef ARB_ASSERT_H |
---|
15 | #include <arb_assert.h> |
---|
16 | #endif |
---|
17 | #ifndef ARBTOOLS_H |
---|
18 | #include <arbtools.h> |
---|
19 | #endif |
---|
20 | #ifndef AP_MATRIX_HXX |
---|
21 | #include <AP_matrix.hxx> |
---|
22 | #endif |
---|
23 | |
---|
24 | #define ph_assert(cond) arb_assert(cond) |
---|
25 | |
---|
26 | typedef double AP_FLOAT; |
---|
27 | |
---|
28 | struct PH_NEIGHBOUR_DIST { |
---|
29 | long i, j; |
---|
30 | AP_FLOAT val; |
---|
31 | |
---|
32 | PH_NEIGHBOUR_DIST *next, *previous; |
---|
33 | |
---|
34 | PH_NEIGHBOUR_DIST(); |
---|
35 | |
---|
36 | void remove() { |
---|
37 | ph_assert(previous); // already removed |
---|
38 | if (next) { next->previous = previous; } |
---|
39 | previous->next = next; previous = 0; |
---|
40 | }; |
---|
41 | |
---|
42 | void add(PH_NEIGHBOUR_DIST *root) { |
---|
43 | next = root->next; |
---|
44 | root->next = this; |
---|
45 | previous = root; |
---|
46 | if (next) next->previous = this; |
---|
47 | }; |
---|
48 | }; |
---|
49 | |
---|
50 | class PH_NEIGHBOURJOINING : virtual Noncopyable { |
---|
51 | PH_NEIGHBOUR_DIST **dist_matrix; |
---|
52 | PH_NEIGHBOUR_DIST *dist_list; // array of dist_list lists |
---|
53 | long dist_list_size; |
---|
54 | AP_FLOAT dist_list_corr; |
---|
55 | AP_FLOAT *net_divergence; |
---|
56 | |
---|
57 | long size; |
---|
58 | long *swap_tab; |
---|
59 | long swap_size; |
---|
60 | |
---|
61 | void remove_taxa_from_dist_list(long i); |
---|
62 | void add_taxa_to_dist_list(long j); |
---|
63 | AP_FLOAT get_max_net_divergence(); |
---|
64 | void remove_taxa_from_swap_tab(long i); |
---|
65 | |
---|
66 | public: |
---|
67 | |
---|
68 | PH_NEIGHBOURJOINING(const AP_smatrix& smatrix); |
---|
69 | ~PH_NEIGHBOURJOINING(); |
---|
70 | |
---|
71 | void join_nodes(long i, long j, AP_FLOAT &leftl, AP_FLOAT& rightlen); |
---|
72 | AP_FLOAT get_min_ij(long& i, long& j); |
---|
73 | void get_last_ij(long& i, long& j); |
---|
74 | AP_FLOAT get_dist(long i, long j); |
---|
75 | |
---|
76 | #if defined(UNIT_TESTS) // UT_DIFF |
---|
77 | // test inspection |
---|
78 | AP_FLOAT get_net_divergence(long i) { return net_divergence[i]; } |
---|
79 | #endif |
---|
80 | }; |
---|
81 | |
---|
82 | #else |
---|
83 | #error NJ.hxx included twice |
---|
84 | #endif // NJ_HXX |
---|