source: tags/arb-6.0/NALIGNER/ali_prealigner.hxx

Last change on this file was 8616, checked in by westram, 12 years ago

merge from e4fix [8190] [8196] [8198] [8197] [8199] [8221] [8226]

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