source: tags/arb_5.3/NALIGNER/ali_prealigner.hxx

Last change on this file was 4912, checked in by westram, 17 years ago
  • untabified + indented
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1
2
3#ifndef _ALI_PREALIGNER_INC_
4#define _ALI_PREALIGNER_INC_
5
6#include "ali_profile.hxx"
7#include "ali_pathmap.hxx"
8#include "ali_tstack.hxx"
9#include "ali_solution.hxx"
10
11#define ALI_PREALIGNER_INS        1
12#define ALI_PREALIGNER_SUB        2
13#define ALI_PREALIGNER_DEL        3
14#define ALI_PREALIGNER_MULTI_FLAG 4
15
16
17
18struct ALI_PREALIGNER_CONTEXT {
19    long max_number_of_maps;
20    long max_number_of_maps_aligner;
21    int intervall_border;
22    int intervall_center;
23    float max_cost_of_sub_percent;
24    float max_cost_of_helix;
25    unsigned long error_count;
26};
27
28/*
29 * Structure for a cell in the (simple) distance matrix
30 */
31struct ali_prealigner_cell {
32    float d;
33
34    ali_prealigner_cell(void) {
35        d = 0.0;
36    }
37};
38
39/*
40 * Structure for a column in the (simple) distance matrix
41 */
42struct ali_prealigner_column {
43    unsigned long column_length;
44    //ali_prealigner_cell (*cells)[];
45    ali_prealigner_cell **cells;
46
47    ali_prealigner_column(unsigned long length) {
48        column_length = length;
49        //cells = (ali_prealigner_cell (*) [0]) calloc((unsigned int) column_length, sizeof(ali_prealigner_cell));
50        //cells = (ali_prealigner_cell (*) [1]) calloc((unsigned int) column_length, sizeof(ali_prealigner_cell));
51        cells = (ali_prealigner_cell **) calloc((unsigned int) column_length, sizeof(ali_prealigner_cell));
52        if (cells == 0)
53            ali_fatal_error("Out of memory");
54    }
55    ~ali_prealigner_column(void) {
56        if (cells)
57            free((char *) cells);
58    }
59};
60
61/*
62 * Structure for the intersection of maps
63 */
64struct ali_prealigner_mask {
65    ALI_MAP *map;
66    float cost_of_binding;
67
68    unsigned long calls, joins, last_new, last_joins;
69
70    ali_prealigner_mask(void) {
71        last_new = last_joins = 0;
72        map = 0;
73        calls = joins = 0;
74    }
75
76    void insert(ALI_MAP *in_map, float costs);
77    void delete_expensive(ALI_PREALIGNER_CONTEXT *context,ALI_PROFILE *profile);
78    void clear(void) {
79        last_new = last_joins = 0;
80        delete map;
81        calls = joins = 0;
82    }
83};
84
85/*
86 * Structure for a approximation of a map
87 */
88struct ali_prealigner_approx_element {
89    ALI_MAP *map;
90    char *ins_marker;
91
92    ali_prealigner_approx_element(ALI_MAP *m = 0, char *im = 0) {
93        map = m;
94        ins_marker = im;
95    }
96    ~ali_prealigner_approx_element(void) {
97        /*
98          if (map)
99          delete map;
100          if (ins_marker)
101          free((char *) ins_marker);
102        */
103    }
104    void print(void) {
105        printf("map = %p, ins_marker = %p\n",map,ins_marker);
106        map->print();
107        printf("<%20s>\n",ins_marker);
108    }
109};
110
111/*
112 * Structure for a list of approximated maps
113 */
114struct ali_prealigner_approximation {
115    ALI_TLIST<ali_prealigner_approx_element *> *approx_list;
116    float cost_of_binding;
117
118    ali_prealigner_approximation(void) {
119        cost_of_binding = 0.0;
120        approx_list = new ALI_TLIST<ali_prealigner_approx_element *>;
121    }
122    ~ali_prealigner_approximation(void) {
123        if (approx_list) {
124            clear();
125            delete approx_list;
126        }
127    }
128
129    /*
130     * Insert a new approximation (dependence of the costs)
131     */
132    void insert(ALI_MAP *in_map, char *in_insert_marker, float costs) {
133        ali_prealigner_approx_element *approx_elem;
134
135        if (approx_list == 0)
136            approx_list = new ALI_TLIST<ali_prealigner_approx_element *>;
137
138        if (costs < cost_of_binding || approx_list->is_empty()) {
139            cost_of_binding = costs;
140            clear();
141        }
142
143        if (costs == cost_of_binding) {
144            if (approx_list->cardinality() < 20) {
145                approx_elem = new ali_prealigner_approx_element(in_map,
146                                                                in_insert_marker);
147
148                approx_list->append_end(approx_elem);
149            }
150            else {
151                delete in_map;
152                delete in_insert_marker;
153            }
154        }
155        else {
156            delete in_map;
157            delete in_insert_marker;
158        }
159    }
160    ALI_TLIST<ali_prealigner_approx_element *> *list(void) {
161        ALI_TLIST<ali_prealigner_approx_element *> *ret_list;
162        ret_list = approx_list;
163        approx_list = 0;
164        return ret_list;
165    }
166    void clear(void) {
167        if (approx_list) {
168            if (!approx_list->is_empty()) {
169                delete approx_list->first();
170                while (approx_list->is_next())
171                    delete approx_list->next();
172                approx_list->make_empty();
173            }
174        }
175    }
176    void print(void) {
177        ali_prealigner_approx_element *approx_elem;
178        printf("\nList of Approximations\n");
179        printf("cost_of_binding = %f\n",cost_of_binding);
180        if (approx_list) {
181            if (!approx_list->is_empty()) {
182                approx_elem = approx_list->first();
183                approx_elem->print();
184                while (approx_list->is_next()) {
185                    approx_elem = approx_list->next();
186                    approx_elem->print();
187                }
188            }
189            else {
190                printf("List is empty\n");
191            }
192        }
193        else {
194            printf("List not existent\n");
195        }
196    }
197};
198
199
200
201/*
202 * Class of the prealigner
203 */
204class ALI_PREALIGNER {
205    ALI_PROFILE *profile;
206    ALI_PATHMAP *path_map;
207    ALI_SUB_SOLUTION *sub_solution;
208
209    ali_prealigner_mask result_mask;
210    unsigned long result_mask_counter;
211    unsigned long start_x, end_x, start_y, end_y;
212    ali_prealigner_approximation result_approx;
213
214    float minimum2(float a, float b);
215    float minimum3(float a, float b, float c);
216
217    void calculate_first_column_first_cell(ali_prealigner_cell *akt_cell);
218    void calculate_first_column_cell(ali_prealigner_cell *up_cell,
219                                     ali_prealigner_cell *akt_cell,
220                                     unsigned long pos_y);
221    void calculate_first_column(ali_prealigner_column *akt_column);
222
223    void calculate_first_cell(ali_prealigner_cell *left_cell,
224                              ali_prealigner_cell *akt_cell,
225                              unsigned long pos_x);
226    void calculate_cell(
227                        ali_prealigner_cell *diag_cell, ali_prealigner_cell *left_cell,
228                        ali_prealigner_cell *up_cell, ali_prealigner_cell *akt_cell,
229                        unsigned long pos_x, unsigned long pos_y);
230    void calculate_column(ali_prealigner_column *prev_col,
231                          ali_prealigner_column *akt_col,
232                          unsigned long pos_x);
233
234    void calculate_last_column_first_cell(ali_prealigner_cell *left_cell,
235                                          ali_prealigner_cell *akt_cell,
236                                          unsigned long pos_x);
237    void calculate_last_column_cell(
238                                    ali_prealigner_cell *diag_cell, ali_prealigner_cell *left_cell,
239                                    ali_prealigner_cell *up_cell, ali_prealigner_cell *akt_cell,
240                                    unsigned long pos_x, unsigned long pos_y);
241    void calculate_last_column(ali_prealigner_column *prev_col,
242                               ali_prealigner_column *akt_col,
243                               unsigned long pos_x);
244
245    void calculate_matrix(void);
246
247    int find_multiple_path(unsigned long start_x, unsigned long start_y,
248                           unsigned long *end_x, unsigned long *end_y);
249    void generate_solution(ALI_MAP *map);
250    void generate_result_mask(ALI_TSTACK<unsigned char> *stack);
251    void mapper_pre(ALI_TSTACK<unsigned char> *stack,
252                    unsigned long pos_x, unsigned long pos_y);
253    void mapper_post(ALI_TSTACK<unsigned char> *stack,
254                     unsigned long pos_x, unsigned long pos_y);
255    void mapper_post_multi(ALI_TSTACK<unsigned char> *stack,
256                           unsigned long pos_x, unsigned long pos_y);
257    void mapper_random(ALI_TSTACK<unsigned char> *stack,
258                       unsigned long pos_x, unsigned long pos_y);
259    void mapper(ALI_TSTACK<unsigned char> *stack,
260                unsigned long pos_x, unsigned long pos_y);
261    void quick_mapper(ALI_TSTACK<unsigned char> *stack,
262                      unsigned long pos_x, unsigned long pos_y);
263    void make_map(void);
264    void make_quick_map(void);
265
266    void generate_approximation(ALI_SUB_SOLUTION *work_sol);
267    void mapper_approximation(unsigned long area_number,
268                              ALI_TARRAY<ALI_TLIST<ALI_MAP *> *> *map_lists,
269                              ALI_SUB_SOLUTION *work_sol);
270    void make_approximation(ALI_PREALIGNER_CONTEXT *context);
271
272    unsigned long number_of_solutions(void);
273
274public:
275
276    ALI_PREALIGNER(ALI_PREALIGNER_CONTEXT *context, ALI_PROFILE *profile,
277                   unsigned long start_x, unsigned long end_x,
278                   unsigned long start_y, unsigned long end_y);
279    ~ALI_PREALIGNER(void) {
280        if (sub_solution)
281            delete sub_solution;
282    }
283
284    ALI_SEQUENCE *sequence(void) {
285        return result_mask.map->sequence(profile->sequence());
286    }
287    ALI_SEQUENCE *sequence_without_inserts(void) {
288        return result_mask.map->sequence_without_inserts(profile->sequence());
289    }
290    ALI_SUB_SOLUTION *solution(void) {
291        ALI_SUB_SOLUTION *ret_sol = sub_solution;
292        sub_solution = 0;
293        return ret_sol;
294    }
295    ALI_TLIST<ali_prealigner_approx_element *> *approximation(void) {
296        return result_approx.list();
297    }
298};
299
300
301#endif
302
Note: See TracBrowser for help on using the repository browser.