1 | #include <stdio.h> |
---|
2 | //#include <memory.h> |
---|
3 | #include <string.h> |
---|
4 | #include <arbdb.h> |
---|
5 | #include <arbdbt.h> |
---|
6 | #include <awt_tree.hxx> |
---|
7 | #include "dist.hxx" |
---|
8 | |
---|
9 | char *AP_sequence_parsimony::table; |
---|
10 | AP_weights *AP_sequence::weights; |
---|
11 | AP_rates *AP_sequence::rates; |
---|
12 | |
---|
13 | AP_sequence_parsimony::AP_sequence_parsimony(void) |
---|
14 | { |
---|
15 | update = 0; |
---|
16 | sequence_len = 0; |
---|
17 | sequence = 0; |
---|
18 | is_set_flag = AP_FALSE; |
---|
19 | } |
---|
20 | |
---|
21 | AP_sequence_parsimony::~AP_sequence_parsimony(void) |
---|
22 | { |
---|
23 | delete sequence; |
---|
24 | } |
---|
25 | |
---|
26 | AP_sequence *AP_sequence_parsimony::dup(void) |
---|
27 | { |
---|
28 | return (AP_sequence *)new AP_sequence_parsimony; |
---|
29 | } |
---|
30 | |
---|
31 | void AP_sequence_parsimony::build_table(void) |
---|
32 | { |
---|
33 | int i; |
---|
34 | AP_BASES val; |
---|
35 | table = new char[256]; |
---|
36 | for (i=0;i<256;i++) { |
---|
37 | switch ((char)i) { |
---|
38 | case 'a': |
---|
39 | case 'A': |
---|
40 | val = AP_A; |
---|
41 | break; |
---|
42 | case 'g': |
---|
43 | case 'G': |
---|
44 | val = AP_G; |
---|
45 | break; |
---|
46 | case 'c': |
---|
47 | case 'C': |
---|
48 | val = AP_C; |
---|
49 | break; |
---|
50 | case 't': |
---|
51 | case 'T': |
---|
52 | case 'u': |
---|
53 | case 'U': |
---|
54 | val = AP_T; |
---|
55 | break; |
---|
56 | case 'n': |
---|
57 | case 'N': |
---|
58 | val = (AP_BASES)(AP_A + AP_G + AP_C + AP_T); |
---|
59 | break; |
---|
60 | case '?': |
---|
61 | case '.': |
---|
62 | val = (AP_BASES)(AP_A + AP_G + AP_C + AP_T + AP_S); |
---|
63 | break; |
---|
64 | case '-': |
---|
65 | val = AP_S; |
---|
66 | break; |
---|
67 | case 'm': |
---|
68 | case 'M': |
---|
69 | val = (AP_BASES)(AP_A+AP_C); |
---|
70 | break; |
---|
71 | case 'r': |
---|
72 | case 'R': |
---|
73 | val = (AP_BASES)(AP_A+AP_G); |
---|
74 | break; |
---|
75 | case 'w': |
---|
76 | case 'W': |
---|
77 | val = (AP_BASES)(AP_A+AP_T); |
---|
78 | break; |
---|
79 | case 's': |
---|
80 | case 'S': |
---|
81 | val = (AP_BASES)(AP_C+AP_G); |
---|
82 | break; |
---|
83 | case 'y': |
---|
84 | case 'Y': |
---|
85 | val = (AP_BASES)(AP_C+AP_T); |
---|
86 | break; |
---|
87 | case 'k': |
---|
88 | case 'K': |
---|
89 | val = (AP_BASES)(AP_G+AP_T); |
---|
90 | break; |
---|
91 | case 'v': |
---|
92 | case 'V': |
---|
93 | val = (AP_BASES)(AP_A+AP_C+AP_G); |
---|
94 | break; |
---|
95 | case 'h': |
---|
96 | case 'H': |
---|
97 | val = (AP_BASES)(AP_A+AP_C+AP_T); |
---|
98 | break; |
---|
99 | case 'd': |
---|
100 | case 'D': |
---|
101 | val = (AP_BASES)(AP_A+AP_G+AP_T); |
---|
102 | break; |
---|
103 | case 'b': |
---|
104 | case 'B': |
---|
105 | val = (AP_BASES)(AP_C+AP_G+AP_T); |
---|
106 | break; |
---|
107 | default: |
---|
108 | val = AP_N; |
---|
109 | break; |
---|
110 | } |
---|
111 | table[i] = (char)val; |
---|
112 | } /*for*/ |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | void AP_sequence_parsimony::set(char *isequence) |
---|
118 | { |
---|
119 | char *s,*d,*f,c; |
---|
120 | sequence_len = filter->real_len; |
---|
121 | sequence = new char[sequence_len+1]; |
---|
122 | memset(sequence,AP_N,(size_t)sequence_len); |
---|
123 | s = isequence; |
---|
124 | d = sequence; |
---|
125 | f = filter->filter; |
---|
126 | if (!table) this->build_table(); |
---|
127 | while (c = (*s++) ) { |
---|
128 | if (*(f++)) { |
---|
129 | *(d++) = table[c]; |
---|
130 | } |
---|
131 | } |
---|
132 | update = AP_timer(); |
---|
133 | is_set_flag = AP_TRUE; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | AP_FLOAT AP_sequence_parsimony::combine(const AP_sequence *lefts, const AP_sequence *rights) { |
---|
139 | float tree_length = 0.0; |
---|
140 | AP_sequence_parsimony *left = (AP_sequence_parsimony *)lefts; |
---|
141 | AP_sequence_parsimony *right = (AP_sequence_parsimony *)rights; |
---|
142 | |
---|
143 | if (!sequence) { |
---|
144 | sequence = new char[filter->real_len +1]; |
---|
145 | } |
---|
146 | for (int i = 0; i <= sequence_len;i++ ) { |
---|
147 | if ((left->sequence[i] & right->sequence[i]) == 0) { |
---|
148 | sequence[i] = (left->sequence[i] | right->sequence[i]); } |
---|
149 | else { |
---|
150 | sequence[i] = (left->sequence[i] & right->sequence[i]); |
---|
151 | tree_length = tree_length + weights->weights[i] + rates->rates[i]; |
---|
152 | } |
---|
153 | } |
---|
154 | is_set_flag = AP_TRUE; |
---|
155 | return tree_length; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | void AP_sequence_parsimony::calc_base_rates(AP_rates *ratesi, |
---|
161 | const AP_sequence* lefts, AP_FLOAT leftl, |
---|
162 | const AP_sequence *rights, AP_FLOAT rightl) |
---|
163 | { |
---|
164 | ; |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | |
---|