33                             "ali_prealigner_mask::insert()");
 
   55     unsigned long   start_hel, end_hel;
 
   56     unsigned long   start_seq, end_seq;
 
   57     unsigned long   start_mapped, end_mapped;
 
   58     unsigned long   start_ok=0, end_ok=0;
 
   60     unsigned long   found_helix;
 
   61     unsigned long   error_counter;
 
   63     unsigned long   map_pos, i, j;
 
   64     float           max_cost, helix_cost;
 
   65     unsigned long   helix_counter;
 
   67     unsigned char   base1, base2;
 
   69     printf(
"MASK : calls = %ld  joins = %ld last_new = %ld last_joins = %ld\n",
 
   84                     for (j = i - error_counter + 1; j <= i; j++)
 
   91             if (error_counter > 0 &&
 
  105         if (profile->
is_in_helix(i, &start_hel, &end_hel)) {
 
  108                                 "ali_prealigner_mask::delete_expensive()");
 
  111             if (compl_pos > 
long(end_hel)) {
 
  114                 while (i <= end_hel) {
 
  118                             base1 = (profile->
sequence())->base(
 
  126                             base2 = (profile->
sequence())->base(
 
  134                             helix_cost += profile->
w_bind(i, base1, compl_pos, base2);
 
  141                 if (helix_counter > 0) helix_cost /= helix_counter;
 
  143                     for (j = start_hel; j <= end_hel; j++) {
 
  171             end_seq    = map_pos - 1;
 
  177             for (i = start_seq; i <= end_seq; i++) {
 
  181                     if (start_hel >= start_mapped && end_hel <= end_mapped) {
 
  182                         if (start_ok_flag == 0) {
 
  183                             start_ok = start_hel;
 
  192             if (start_ok_flag == 1) {
 
  198                 if (found_helix > 0) {
 
  199                     for (i = start_seq; i <= end_seq; i++)
 
  209                         for (i = start_seq; i <= end_seq; i++) 
map->
undefine(i);
 
  220 inline float ALI_PREALIGNER::minimum2(
float a, 
float b) {
 
  221     return (a < b) ? a : b;
 
  224 inline float ALI_PREALIGNER::minimum3(
float a, 
float b, 
float c) {
 
  225     return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
 
  229 inline void ALI_PREALIGNER::calculate_first_column_first_cell(
ali_prealigner_cell * akt_cell) {
 
  233     v2 = profile->
w_sub(start_y, start_x);
 
  235     akt_cell->
d = minimum2(v1, v2);
 
  246     unsigned long   positiony;
 
  248     positiony = start_y + pos_y;
 
  250     v1 = up_cell->
d + profile->
w_sub_gap(positiony);
 
  254     akt_cell->
d = minimum3(v1, v2, v3);
 
  256     if (v1 == akt_cell->
d) path_map->
set(0, pos_y, 
ALI_UP);
 
  257     if (v2 == akt_cell->
d) path_map->
set(0, pos_y, 
ALI_DIAG);
 
  258     if (v3 == akt_cell->
d) path_map->
set(0, pos_y, 
ALI_LEFT);
 
  264     calculate_first_column_first_cell(&(*akt_column->
cells)[0]);
 
  267         calculate_first_column_cell(&(*akt_column->
cells)[pos_y - 1],
 
  268                                     &(*akt_column->
cells)[pos_y],
 
  278     unsigned long   positionx;
 
  280     positionx = start_x + pos_x;
 
  284     v3 = left_cell->
d + profile->
w_ins(positionx, start_y);
 
  286     akt_cell->
d = minimum3(v1, v2, v3);
 
  288     if (v1 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_UP);
 
  289     if (v2 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_DIAG);
 
  290     if (v3 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_LEFT);
 
  295                                            unsigned long pos_x, 
unsigned long pos_y)
 
  298     unsigned long   positionx, positiony;
 
  300     positionx = start_x + pos_x;
 
  301     positiony = start_y + pos_y;
 
  303     v1 = up_cell->
d + profile->
w_sub_gap(positiony);
 
  304     v2 = diag_cell->
d + profile->
w_sub(positiony, positionx);
 
  305     v3 = left_cell->
d + profile->
w_ins(positionx, positiony);
 
  307     akt_cell->
d = minimum3(v1, v2, v3);
 
  309     if (v1 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_UP);
 
  310     if (v2 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_DIAG);
 
  311     if (v3 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_LEFT);
 
  320     calculate_first_cell(&(*prev_col->
cells)[0], &(*akt_col->
cells)[0], pos_x);
 
  323         calculate_cell(&(*prev_col->
cells)[pos_y - 1], &(*prev_col->
cells)[pos_y],
 
  324                        &(*akt_col->
cells)[pos_y - 1], &(*akt_col->
cells)[pos_y],
 
  328 inline void ALI_PREALIGNER::calculate_last_column_first_cell(
ali_prealigner_cell * left_cell,
 
  333     unsigned long   positionx;
 
  335     positionx = start_x + pos_x;
 
  339     v3 = left_cell->
d + profile->
w_ins(positionx, start_y);
 
  341     akt_cell->
d = minimum3(v1, v2, v3);
 
  343     if (v1 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_UP);
 
  344     if (v2 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_DIAG);
 
  345     if (v3 == akt_cell->
d) path_map->
set(pos_x, 0, 
ALI_LEFT);
 
  350                                                        unsigned long pos_x, 
unsigned long pos_y)
 
  353     unsigned long   positionx, positiony;
 
  355     positionx = start_x + pos_x;
 
  356     positiony = start_y + pos_y;
 
  359     v2 = diag_cell->
d + profile->
w_sub(positiony, positionx);
 
  360     v3 = left_cell->
d + profile->
w_ins(positionx, positiony);
 
  362     akt_cell->
d = minimum3(v1, v2, v3);
 
  364     if (v1 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_UP);
 
  365     if (v2 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_DIAG);
 
  366     if (v3 == akt_cell->
d) path_map->
set(pos_x, pos_y, 
ALI_LEFT);
 
  375     calculate_last_column_first_cell(&(*prev_col->
cells)[0],
 
  376                                      &(*akt_col->
cells)[0], pos_x);
 
  379         calculate_last_column_cell(&(*prev_col->
cells)[pos_y - 1],
 
  380                                    &(*prev_col->
cells)[pos_y],
 
  381                                    &(*akt_col->
cells)[pos_y - 1], &(*akt_col->
cells)[pos_y],
 
  386 void ALI_PREALIGNER::calculate_matrix() {
 
  393     calculate_first_column(prev_col);
 
  395     for (pos_x = 1; pos_x < end_x - start_x + 1; pos_x++) {
 
  397             calculate_last_column(prev_col, akt_col, pos_x);
 
  399             calculate_column(prev_col, akt_col, pos_x);
 
  409 void ALI_PREALIGNER::generate_solution(
ALI_MAP * map) {
 
  412     unsigned long   map_pos;
 
  413     unsigned long   start_seg, end_seg, pos_seg;
 
  419         for (start_seg  = map_pos;
 
  423         if (start_seg <= map->last_base()) {
 
  424             for (end_seg  = start_seg;
 
  430             seg_map = 
new ALI_MAP(start_seg,
 
  435             for (pos_seg = start_seg; pos_seg <= end_seg; pos_seg++) {
 
  437                     seg_map->
set(pos_seg,
 
  440                     seg_map->
set(pos_seg,
 
  444             if (sub_solution->
insert(seg_map) != 1)
 
  446                                 "ALI_PREALIGNER::generate_solution()");
 
  456     float           cost_of_bindings;
 
  458     unsigned long   seq_pos, dest_pos;
 
  461     map = 
new ALI_MAP(start_x, end_x, start_y, end_y);
 
  465     for (i = (
long) stack->
akt_size() - 1; i >= 0; i--) {
 
  466         switch (stack->
get(i)) {
 
  468                 map->
set(seq_pos++, dest_pos, 1);
 
  471                 map->
set(seq_pos++, dest_pos++, 0);
 
  477                 map->
set(seq_pos, dest_pos, 1);
 
  481                 map->
set(seq_pos, dest_pos++, 0);
 
  489                                 "ALI_PREALIGNER::generate_result_mask()");
 
  493     if (result_mask_counter > 0)
 
  494         result_mask_counter--;
 
  501     result_mask.
insert(map, cost_of_bindings);
 
  506     if (ins_nu > 0 && del_nu > 0)
 
  508                         "ALI_PREALIGNER::mapper_post()");
 
  512         generate_result_mask(stack);
 
  518             generate_result_mask(stack);
 
  521             generate_result_mask(stack);
 
  527     if (ins_nu > 0 && del_nu > 0)
 
  529                         "ALI_PREALIGNER::mapper_post_multi()");
 
  533         generate_result_mask(stack);
 
  539             generate_result_mask(stack);
 
  542             generate_result_mask(stack);
 
  548     unsigned long   next_x, next_y;
 
  549     unsigned long   random;
 
  551     unsigned long   stack_counter = 0;
 
  557     while (next_x <= pos_x && next_y <= pos_y) {
 
  562         value = path_map->
get_value(next_x, next_y);
 
  565                             "ALI_PREALIGNER::mapper_random()");
 
  586                 if (value & ALI_UP) {
 
  603                 if (value & ALI_DIAG) {
 
  609                     if (value & ALI_UP) {
 
  620                 if (value & ALI_DIAG) {
 
  626                     if (value & ALI_LEFT) {
 
  637                 if (value & ALI_LEFT) {
 
  642                     if (value & ALI_UP) {
 
  654                 if (value & ALI_LEFT) {
 
  659                     if (value & ALI_DIAG) {
 
  672                                 "ALI_PREALIGNER::mapper_random()");
 
  676     if (next_x <= pos_x) {
 
  677         mapper_post(stack, next_x + 1, 0);
 
  680         if (next_y <= pos_y) {
 
  681             mapper_post(stack, 0, next_y + 1);
 
  684             mapper_post(stack, 0, 0);
 
  688     if (stack_counter > 0)
 
  689         stack->
pop(stack_counter);
 
  695     unsigned long   stack_counter = 0;
 
  697     value = path_map->
get_value(pos_x, pos_y);
 
  699     if (pos_x == 0 || pos_y == 0) {
 
  700         if (value & ALI_UP) {
 
  703                 mapper_post(stack, pos_x + 1, 0);
 
  705                 mapper(stack, pos_x, pos_y - 1);
 
  708         if (value & ALI_DIAG) {
 
  711                 mapper_post(stack, 0, pos_y);
 
  715                     mapper_post(stack, pos_x, 0);
 
  718                     mapper_post(stack, 0, 0);
 
  723         if (value & ALI_LEFT) {
 
  726                 mapper_post(stack, 0, pos_y + 1);
 
  728                 mapper(stack, pos_x - 1, pos_y);
 
  734     while (value == ALI_UP || value == ALI_DIAG || value == ALI_LEFT) {
 
  752         value = path_map->
get_value(pos_x, pos_y);
 
  754         if (pos_x == 0 || pos_y == 0) {
 
  755             if (value & ALI_UP) {
 
  758                     mapper_post(stack, pos_x + 1, 0);
 
  760                     mapper(stack, pos_x, pos_y - 1);
 
  763             if (value & ALI_DIAG) {
 
  766                     mapper_post(stack, 0, pos_y);
 
  770                         mapper_post(stack, pos_x, 0);
 
  773                         mapper_post(stack, 0, 0);
 
  778             if (value & ALI_LEFT) {
 
  781                     mapper_post(stack, 0, pos_y + 1);
 
  783                     mapper(stack, pos_x - 1, pos_y);
 
  786             if (stack_counter > 0)
 
  787                 stack->
pop(stack_counter);
 
  793     if (value & ALI_UP) {
 
  795         mapper(stack, pos_x, pos_y - 1);
 
  798     if (value & ALI_DIAG) {
 
  800         mapper(stack, pos_x - 1, pos_y - 1);
 
  803     if (value & ALI_LEFT) {
 
  805         mapper(stack, pos_x - 1, pos_y);
 
  808     if (stack_counter > 0)
 
  809         stack->
pop(stack_counter);
 
  813 void ALI_PREALIGNER::make_map() {
 
  815     unsigned long   number_of_sol;
 
  821     number_of_sol = number_of_solutions();
 
  822     printf(
"%lu solutions generated\n", number_of_sol);
 
  824     if (number_of_sol == 0 || number_of_sol > result_mask_counter) {
 
  827             mapper_random(stack, end_x - start_x, end_y - start_y);
 
  828         } 
while (result_mask_counter > 0);
 
  832         mapper(stack, end_x - start_x, end_y - start_y);
 
  851                         "ALI_PREALIGNER::generate_approximation()");
 
  859     result_approx.
insert(map, ins_marker, binding_costs);
 
  868     if (area_no > map_lists->size())
 
  871     if (area_no == map_lists->size()) {
 
  872         generate_approximation(work_sol);
 
  876     map_list = map_lists->get(area_no);
 
  879                         "ALI_PREALIGNER::mapper_approximation()");
 
  882     map = map_list->
first();
 
  884         if (!work_sol->
insert(map))
 
  886                             "ALI_PREALIGNER::mapper_approximation()");
 
  888         mapper_approximation(area_no + 1, map_lists, work_sol);
 
  892                             "ALI_PREALIGNER::mapper_approximation()");
 
  895             map = map_list->
next();
 
  907     unsigned long   area_number;
 
  908     unsigned long   start_seq, end_seq, start_ref, end_ref;
 
  917     printf(
"number of areas = %ld (Maximal %ld solutions)\n", area_number,
 
  924     while (sub_solution->
free_area(&start_seq, &end_seq, &start_ref, &end_ref,
 
  926         printf(
"aligning area %ld (%ld,%ld) - (%ld,%ld)\n",
 
  927                area_number, start_seq, end_seq, start_ref, end_ref);
 
  929         aligner = 
new ALI_ALIGNER(&aligner_context, profile,
 
  930                                   start_seq, end_seq, start_ref, end_ref);
 
  933         printf(
"%d solutions generated\n",
 
  934                map_lists->
get(area_number)->cardinality());
 
  941     mapper_approximation(0, map_lists, work_solution);
 
  943     delete work_solution;
 
  949 unsigned long ALI_PREALIGNER::number_of_solutions() {
 
  951 #define INFINIT 1000000 
  952 #define ADD(a, b) if (a>=INFINIT || b>=INFINIT) { a = INFINIT; } else { a += b; } 
  954     unsigned long   pos_x, pos_y, col_length;
 
  955     unsigned long   number;
 
  957     unsigned long  *column1, *column2, *elem_akt_col, *elem_left_col;
 
  959     col_length = end_y - start_y + 1;
 
  960     column1 = (
unsigned long *) 
CALLOC((
unsigned int) col_length, 
sizeof(
unsigned long));
 
  961     column2 = (
unsigned long *) 
CALLOC((
unsigned int) col_length, 
sizeof(
unsigned long));
 
  964     ali_message(
"Start: Checking number of solutions");
 
  966     if (end_x - (start_x & 0x01)) {
 
  967         elem_akt_col = column1 + col_length - 1;
 
  968         elem_left_col = column2 + col_length - 1;
 
  971         elem_akt_col = column2 + col_length - 1;
 
  972         elem_left_col = column1 + col_length - 1;
 
  977     for (pos_x = end_x - start_x; pos_x > 0;) {
 
  978         *(elem_left_col) = 0;
 
  979         for (pos_y = end_y - start_y; pos_y > 0; pos_y--) {
 
  980             *(elem_left_col - 1) = 0;
 
  981             value = path_map->
get_value(pos_x, pos_y);
 
  982             if (value & ALI_UP) {
 
  983                 ADD(*(elem_akt_col - 1), *elem_akt_col);
 
  985             if (value & ALI_DIAG) {
 
  986                 ADD(*(elem_left_col - 1), *elem_akt_col);
 
  988             if (value & ALI_LEFT) {
 
  989                 ADD(*(elem_left_col), *elem_akt_col);
 
  995         if (value & ALI_UP) {
 
  996             ADD(number, *elem_akt_col);
 
  998         if (value & ALI_DIAG) {
 
  999             ADD(number, *elem_akt_col);
 
 1001         if (value & ALI_LEFT) {
 
 1002             ADD(*(elem_left_col), *elem_akt_col);
 
 1007             elem_akt_col = column1 + col_length - 1;
 
 1008             elem_left_col = column2 + col_length - 1;
 
 1011             elem_akt_col = column2 + col_length - 1;
 
 1012             elem_left_col = column1 + col_length - 1;
 
 1016     for (pos_y = end_y - start_y; pos_y > 0; pos_y--) {
 
 1018         if (value & ALI_UP) {
 
 1019             ADD(*(elem_akt_col - 1), *elem_akt_col);
 
 1021         if (value & ALI_DIAG) {
 
 1022             ADD(number, *elem_akt_col);
 
 1024         if (value & ALI_LEFT) {
 
 1025             ADD(number, *elem_akt_col);
 
 1030     ADD(number, *elem_akt_col);
 
 1043                                unsigned long sx, 
unsigned long ex,
 
 1044                                unsigned long sy, 
unsigned long ey)
 
 1057     path_map = 
new ALI_PATHMAP(end_x - start_x + 1, end_y - start_y + 1);
 
 1066     generate_solution(result_mask.
map);
 
 1068     make_approximation(context);
 
float w_bind(unsigned long pos_1, unsigned char base_1, unsigned long pos_2, unsigned char base_2)
void insert(ALI_MAP *in_map, float costs)
#define ALI_PREALIGNER_INS
void ali_out_of_memory_if(bool cond)
long position(unsigned long base)
ALI_PREALIGNER(ALI_PREALIGNER_CONTEXT *context, ALI_PROFILE *profile, unsigned long start_x, unsigned long end_x, unsigned long start_y, unsigned long end_y)
float w_sub_gap_cheap(unsigned long positiony)
float w_sub_multi_gap_cheap(unsigned long start, unsigned long end)
unsigned long column_length
float w_binding(unsigned long first_position_of_sequence, ALI_SEQUENCE *sequence)
int is_in_helix(unsigned long pos, unsigned long *first, unsigned long *last)
float w_ins(unsigned long, unsigned long)
unsigned long first_base()
unsigned long first_reference_base()
void delete_expensive(ALI_PREALIGNER_CONTEXT *context, ALI_PROFILE *profile)
void set(unsigned long position, T value)
int is_undefined(unsigned long base)
void set(unsigned long x, unsigned long y, unsigned char val, ALI_TARRAY< ali_pathmap_up_pointer > *up_pointer=NULp)
void push(T value, unsigned long count=1)
void insert(ALI_MAP *in_map, char *in_insert_marker, float costs)
void * CALLOC(long i, long j)
int free_area(unsigned long *start, unsigned long *end, unsigned long *start_ref, unsigned long *end_ref, unsigned long area_number=0)
ALI_NORM_SEQUENCE * sequence()
int complement_position(unsigned long pos)
#define ALI_PREALIGNER_DEL
ALI_SEQUENCE * sequence_without_inserts(ALI_NORM_SEQUENCE *ref_seq)
#define ALI_PREALIGNER_SUB
T get(unsigned long position)
int is_internal_last(unsigned long pos)
ALI_TLIST< ALI_MAP * > * solutions()
ALI_MAP * inverse_without_inserts()
void set(unsigned long base, unsigned long pos, int insert=-1)
unsigned long error_count
unsigned long last_reference_base()
void ali_fatal_error(const char *message, const char *func)
unsigned long number_of_free_areas()
long max_number_of_maps_aligner
float w_sub(unsigned long positiony, unsigned long positionx)
#define ALI_PREALIGNER_MULTI_FLAG
void ali_message(const char *message)
float w_ins_multi_cheap(unsigned long startx, unsigned long endx)
unsigned char get_value(unsigned long x, unsigned long y)
int is_inserted(unsigned long base)
T pop(unsigned long count=1)
int delete_map(ALI_MAP *map)
unsigned long last_base()
ali_prealigner_cell ** cells
T get(unsigned long position)
float max_cost_of_sub_percent
void undefine(unsigned long base)
float w_sub_gap(unsigned long positiony)