18 float minimal_costs = 0.0;
24 minimal_costs = elem->
costs;
29 if (elem->
costs < minimal_costs)
30 minimal_costs = elem->
costs;
49 if (elem->
costs == costs)
53 if (elem->
costs == costs)
61 if (elem->
costs == costs) {
64 array->
set(counter++, up);
68 if (elem->
costs == costs) {
71 array->
set(counter++, up);
141 inline float ALI_ALIGNER::minimum2(
float v1,
float v2) {
142 return (v1 < v2) ? v1 : v2;
145 inline float ALI_ALIGNER::minimum3(
float v1,
float v2,
float v3) {
146 return (v1 < v2) ? ((v1 < v3) ? v1 : v3) : ((v2 < v3) ? v2 : v3);
154 akt_cell->
d2 = profile->
w_sub(start_y, start_x);
155 akt_cell->
d3 = akt_cell->
d1;
166 unsigned long positiony;
168 positiony = start_y + pos_y;
171 costs = profile->
w_del(positiony, positiony);
172 v1 = del_list->
update(positiony);
173 v2 = up_cell->
d2 + costs;
174 v3 = up_cell->
d3 + costs;
175 akt_cell->
d1 = minimum3(v1, v2, v3);
177 if (v1 == akt_cell->
d1)
179 if (v2 == akt_cell->
d1)
181 if (v3 == akt_cell->
d1)
205 calculate_first_column_first_cell(&(*akt_col->
cells)[0], del_list);
208 calculate_first_column_cell(&(*akt_col->
cells)[cell - 1],
209 &(*akt_col->
cells)[cell],
214 0 + 1, start_x, end_x);
223 unsigned long positionx;
225 positionx = start_x + pos_x;
238 v1 = left_cell->
d1 + profile->
w_ins(positionx, start_y);
239 v2 = left_cell->
d2 + profile->
w_ins(positionx, start_y);
240 v3 = left_cell->
d3 + profile->
w_ins_cheap(positionx, start_y);
241 akt_cell->
d3 = minimum3(v1, v2, v3);
243 if (v1 == akt_cell->
d3)
245 if (v2 == akt_cell->
d3)
247 if (v3 == akt_cell->
d3)
253 unsigned long pos_x,
unsigned long pos_y,
258 unsigned long positionx, positiony;
260 positionx = start_x + pos_x;
261 positiony = start_y + pos_y;
264 costs = profile->
w_del(positiony, positiony);
265 v1 = del_list->
update(positiony);
266 v2 = up_cell->
d2 + costs;
267 v3 = up_cell->
d3 + costs;
268 akt_cell->
d1 = minimum3(v1, v2, v3);
271 if (v1 == akt_cell->
d1)
273 if (v2 == akt_cell->
d1)
275 if (v3 == akt_cell->
d1)
290 costs = profile->
w_sub(positiony, positionx);
291 v1 = diag_cell->
d1 + costs;
292 v2 = diag_cell->
d2 + costs;
293 v3 = diag_cell->
d3 + costs;
294 akt_cell->
d2 = minimum3(v1, v2, v3);
296 if (v1 == akt_cell->
d2)
298 if (v2 == akt_cell->
d2)
300 if (v3 == akt_cell->
d2)
304 costs = profile->
w_ins(positionx, positiony);
305 v1 = left_cell->
d1 + costs;
306 v2 = left_cell->
d2 + costs;
307 v3 = left_cell->
d3 + profile->
w_ins_cheap(positionx, positiony);
308 akt_cell->
d3 = minimum3(v1, v2, v3);
310 if (v1 == akt_cell->
d3)
312 if (v2 == akt_cell->
d3)
314 if (v3 == akt_cell->
d3)
323 calculate_first_cell(&(*prev_col->
cells)[0], &(*akt_col->
cells)[0],
327 calculate_cell(&(*prev_col->
cells)[cell - 1], &(*prev_col->
cells)[cell],
328 &(*akt_col->
cells)[cell - 1], &(*akt_col->
cells)[cell],
329 pos_x, cell, del_list);
334 pos_x + 1, start_x, end_x);
340 void ALI_ALIGNER::calculate_matrix() {
351 calculate_first_column(prev_col, del_list);
353 for (col = 1; col <= end_x - start_x; col++) {
354 calculate_column(prev_col, akt_col, col, del_list);
360 last_cell->
update_up(prev_col, start_y, end_y);
371 long seq_pos, dest_pos;
374 map =
new ALI_MAP(start_x, end_x, start_y, end_y);
377 seq_pos = start_x - 1;
382 switch (stack->
get(i)) {
386 map->
set(seq_pos, 0, 1);
396 for (; i >= 0; i--) {
397 switch (stack->
get(i)) {
400 map->
set(seq_pos, dest_pos, 1);
405 map->
set(seq_pos, dest_pos, 0);
412 "ALI_ALIGNER::generate_result()");
416 if ((
unsigned long)(seq_pos) != map->
last_base())
417 ali_error(
"Stack and map length inconsistent",
418 "ALI_ALIGNER::generate_result()");
420 if (result_counter > 0)
428 unsigned long pos_x,
unsigned long pos_y,
429 unsigned char operation,
int random_mapping_flag)
433 unsigned long random;
436 if ((pos_x < end_x - start_x && pos_y < end_y - start_y) ||
437 (pos_x > end_x - start_x) || (pos_y > end_y - start_y))
443 if (random_mapping_flag == 1) {
447 if (operation &
ALI_UP) plane = 0;
449 if (operation &
ALI_DIAG) plane = 1;
454 if (operation & ALI_UP) plane = 0;
456 if (operation &
ALI_LEFT) plane = 2;
461 if (operation &
ALI_DIAG) plane = 1;
463 if (operation & ALI_UP) plane = 0;
468 if (operation & ALI_DIAG) plane = 1;
470 if (operation &
ALI_LEFT) plane = 2;
475 if (operation &
ALI_LEFT) plane = 2;
477 if (operation & ALI_UP) plane = 0;
482 if (operation & ALI_LEFT) plane = 2;
484 if (operation & ALI_DIAG) plane = 1;
491 mapper_random(stack, plane, pos_x, pos_y);
494 if (operation & ALI_UP) mapper(stack, 0, pos_x, pos_y);
495 if (operation & ALI_DIAG) mapper(stack, 1, pos_x, pos_y);
496 if (operation & ALI_LEFT) mapper(stack, 2, pos_x, pos_y);
499 if (pos_x < end_x - start_x) stack->
pop(end_x - start_x - pos_x);
500 if (pos_y < end_y - start_y) stack->
pop(end_y - start_y - pos_y);
506 if (ins_nu > 0 && del_nu > 0)
508 "ALI_ALIGNER::mapper_post()");
512 generate_result(stack);
518 generate_result(stack);
522 generate_result(stack);
528 unsigned long random;
529 unsigned long stack_counter = 0;
533 unsigned long next_x, next_y;
537 while (next_x <= pos_x && next_y <= pos_y) {
540 path_map[plane]->
get(next_x, next_y, &value, &up_pointer);
541 if (value == 0 && next_x != 0 && next_y != 0)
543 "ALI_ALIGNER::mapper_random()");
568 "ALI_ALIGNER::mapper_random()");
573 if (random == 0 || value == ALI_LUP) {
576 up = up_pointer->
get(random);
578 if (next_y < up.start)
580 "ALI_ALIGNER::mapper_random()");
581 if (up.operation & ALI_UP || up.operation & ALI_LUP)
583 "ALI_ALIGNER::mapper_random()");
585 if (up.start <= next_y) {
587 stack_counter += (next_y - up.start + 1);
590 next_y = up.start - 1;
591 value = up.operation;
599 if (value & ALI_UP) {
603 if (value & ALI_DIAG) {
612 if (value & ALI_UP) {
616 if (value & ALI_LEFT) {
625 if (value & ALI_DIAG) {
629 if (value & ALI_UP) {
638 if (value & ALI_DIAG) {
642 if (value & ALI_LEFT) {
651 if (value & ALI_LEFT) {
655 if (value & ALI_UP) {
664 if (value & ALI_LEFT) {
668 if (value & ALI_DIAG) {
678 "ALI_ALIGNER::mapper_random()");
682 if (next_x <= pos_x) {
683 mapper_post(stack, next_x + 1, 0);
686 if (next_y <= pos_y) {
687 mapper_post(stack, 0, next_y + 1);
690 mapper_post(stack, 0, 0);
694 if (stack_counter > 0)
695 stack->
pop(stack_counter);
705 unsigned long next_x, next_y;
731 if (next_x > pos_x || next_y > pos_y) {
732 if (next_y <= pos_y) {
735 "ALI_ALIGNER::mapper()");
736 mapper_post(stack, 0, next_y + 1);
739 if (next_x <= pos_x) {
742 "ALI_ALIGNER::mapper()");
743 mapper_post(stack, next_x + 1, 0);
746 mapper_post(stack, 0, 0);
751 path_map[plane]->
get(pos_x, pos_y, &value, &up_pointer);
753 if (value & ALI_UP) {
754 mapper(stack, 0, next_x, next_y);
756 if (value & ALI_DIAG) {
757 mapper(stack, 1, next_x, next_y);
759 if (value & ALI_LEFT) {
760 mapper(stack, 2, next_x, next_y);
765 if (value & ALI_LUP) {
767 printf(
"LUP should never be in plane %d\n", plane);
769 for (l = 0; l < up_pointer->
size(); l++) {
770 up = up_pointer->
get(l);
772 if (next_y < up.
start) {
773 printf(
"LUP reference incorrect %d:(%ld,%ld) %ld > %ld\n",
774 plane, pos_x, pos_y, next_y, up.
start);
777 printf(
"LIP reference incorrect %d: wrong operation %d\n",
781 if (up.
start <= next_y)
785 mapper(stack, 1, next_x, up.
start - 1);
787 mapper(stack, 2, next_x, up.
start - 1);
789 if (up.
start <= next_y)
801 unsigned long number;
808 "ALI_ALIGNER::mapper_pre_random_up()");
811 for (; number > 0; number--) {
814 "ALI_ALIGNER::mapper_pre_random_up()");
823 unsigned long number;
830 "ALI_ALIGNER::mapper_pre_random_left()");
833 for (; number > 0; number--) {
836 "ALI_ALIGNER::mapper_pre_random_left()");
846 unsigned long random;
849 min = minimum3(last_cell->
d1, last_cell->
d2, last_cell->
d3);
854 if (last_cell->
d1 == min) {
855 mapper_pre_random_up(stack, &last_cell->
up_starts);
858 if (last_cell->
d2 == min) {
859 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
862 if (last_cell->
d3 == min) {
863 mapper_pre_random_left(stack, &last_cell->
left_starts);
869 if (last_cell->
d1 == min) {
870 mapper_pre_random_up(stack, &last_cell->
up_starts);
873 if (last_cell->
d3 == min) {
874 mapper_pre_random_left(stack, &last_cell->
left_starts);
877 if (last_cell->
d2 == min) {
878 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
884 if (last_cell->
d2 == min) {
885 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
888 if (last_cell->
d1 == min) {
889 mapper_pre_random_up(stack, &last_cell->
up_starts);
892 if (last_cell->
d3 == min) {
893 mapper_pre_random_left(stack, &last_cell->
left_starts);
899 if (last_cell->
d2 == min) {
900 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
903 if (last_cell->
d3 == min) {
904 mapper_pre_random_left(stack, &last_cell->
left_starts);
907 if (last_cell->
d1 == min) {
908 mapper_pre_random_up(stack, &last_cell->
up_starts);
914 if (last_cell->
d3 == min) {
915 mapper_pre_random_left(stack, &last_cell->
left_starts);
918 if (last_cell->
d2 == min) {
919 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
922 if (last_cell->
d1 == min) {
923 mapper_pre_random_up(stack, &last_cell->
up_starts);
929 if (last_cell->
d3 == min) {
930 mapper_pre_random_left(stack, &last_cell->
left_starts);
933 if (last_cell->
d1 == min) {
934 mapper_pre_random_up(stack, &last_cell->
up_starts);
937 if (last_cell->
d2 == min) {
938 mapper_random(stack, 1, end_x-start_x, end_y-start_y);
953 min = minimum3(last_cell->
d1, last_cell->
d2, last_cell->
d3);
955 if (last_cell->
d1 == min) {
967 if (last_cell->
d2 == min) {
968 mapper(stack, 1, end_x - start_x, end_y - start_y);
971 if (last_cell->
d3 == min) {
985 void ALI_ALIGNER::make_map() {
998 unsigned long number_of_sol = number_of_solutions();
1000 if (result_counter <= number_of_sol) {
1002 make_map_systematic(stack);
1007 make_map_random(stack);
1009 while (result_counter > 0);
1013 make_map_random(stack);
1025 unsigned long ALI_ALIGNER::number_of_solutions() {
1028 unsigned long pos_x, pos_y, col_length;
1029 unsigned long number;
1031 unsigned char value;
1037 col_length = end_y - start_y + 1;
1042 if (end_x - (start_x & 0x01)) {
1043 elem_akt_col = column1 + col_length - 1;
1044 elem_left_col = column2 + col_length - 1;
1047 elem_akt_col = column2 + col_length - 1;
1048 elem_left_col = column1 + col_length - 1;
1054 min = minimum3(last_cell->
d1, last_cell->
d2, last_cell->
d3);
1056 if (last_cell->
d1 == min) {
1060 if (up.
start == 0) {
1067 "ALI_ALIGNER::number_of_solutions()");
1070 (elem_akt_col - col_length + 1 + up.
start - 1)->v2 += 1;
1073 (elem_akt_col - col_length + 1 + up.
start - 1)->v3 += 1;
1079 if (up.
start == 0) {
1086 "ALI_ALIGNER::number_of_solutions()");
1089 (elem_akt_col - col_length + 1 + up.
start - 1)->v2 += 1;
1092 (elem_akt_col - col_length + 1 + up.
start - 1)->v3 += 1;
1100 if (last_cell->
d2 == min) {
1101 (elem_akt_col)->v2 += 1;
1105 for (pos_x = end_x - start_x; pos_x > 0;) {
1107 elem_left_col->
v1 = elem_left_col->
v2 = elem_left_col->
v3 = 0;
1110 for (pos_y = end_y - start_y; pos_y > 0; pos_y--) {
1112 (elem_left_col - 1)->v1 = (elem_left_col - 1)->v2 =
1113 (elem_left_col - 1)->v3 = 0;
1115 path_map[0]->
get(pos_x, pos_y, &value, &up_pointer);
1117 (elem_akt_col - 1)->v1 += elem_akt_col->
v1;
1118 if (value & ALI_DIAG)
1119 (elem_akt_col - 1)->v2 += elem_akt_col->
v1;
1120 if (value & ALI_LEFT)
1121 (elem_akt_col - 1)->v3 += elem_akt_col->
v1;
1122 if (value & ALI_LUP) {
1123 for (l = 0; l < up_pointer->
size(); l++) {
1124 up = up_pointer->
get(l);
1128 "ALI_ALIGNER::number_of_solutions()");
1129 if (up.
start == 0) {
1130 number += elem_akt_col->
v1;
1133 (elem_akt_col - pos_y + up.
start - 1)->v2 += elem_akt_col->
v1;
1135 (elem_akt_col - pos_y + up.
start - 1)->v3 += elem_akt_col->
v1;
1139 path_map[1]->
get(pos_x, pos_y, &value, &up_pointer);
1141 (elem_left_col - 1)->v1 += elem_akt_col->
v2;
1142 if (value & ALI_DIAG)
1143 (elem_left_col - 1)->v2 += elem_akt_col->
v2;
1144 if (value & ALI_LEFT)
1145 (elem_left_col - 1)->v3 += elem_akt_col->
v2;
1146 if (value & ALI_LUP)
1148 "ALI_ALIGNER::number_of_solutions()");
1150 path_map[2]->
get(pos_x, pos_y, &value, &up_pointer);
1152 (elem_left_col)->v1 += elem_akt_col->
v3;
1153 if (value & ALI_DIAG)
1154 (elem_left_col)->v2 += elem_akt_col->
v3;
1155 if (value & ALI_DIAG)
1156 (elem_left_col)->v3 += elem_akt_col->
v3;
1157 if (value & ALI_LUP)
1159 "ALI_ALIGNER::number_of_solutions()");
1167 number += elem_akt_col->
v1;
1168 number += elem_akt_col->
v2;
1170 path_map[2]->
get(pos_x, pos_y, &value, &up_pointer);
1172 (elem_left_col)->v1 += elem_akt_col->
v3;
1173 if (value & ALI_DIAG)
1174 (elem_left_col)->v2 += elem_akt_col->
v3;
1175 if (value & ALI_DIAG)
1176 (elem_left_col)->v3 += elem_akt_col->
v3;
1177 if (value & ALI_LUP)
1179 "ALI_ALIGNER::number_of_solutions()");
1184 elem_akt_col = column1 + col_length - 1;
1185 elem_left_col = column2 + col_length - 1;
1188 elem_akt_col = column2 + col_length - 1;
1189 elem_left_col = column1 + col_length - 1;
1193 if (last_cell->
d3 == min) {
1194 (elem_akt_col)->v1 = (elem_akt_col)->
v2 = (elem_akt_col)->v3 = 0;
1198 if (up.
start - 1 == pos_x) {
1201 (elem_akt_col)->v1 += 1;
1204 (elem_akt_col)->v2 += 1;
1208 "ALI_ALIGNER::number_of_solutions()");
1214 if (up.
start == pos_x) {
1217 (elem_akt_col)->v1 += 1;
1220 (elem_akt_col)->v2 += 1;
1224 "ALI_ALIGNER::number_of_solutions()");
1236 for (pos_y = end_y - start_y; pos_y > 0; pos_y--) {
1238 path_map[0]->
get(pos_x, pos_y, &value, &up_pointer);
1240 (elem_akt_col - 1)->v1 += elem_akt_col->
v1;
1241 if (value & ALI_DIAG) {
1242 number += elem_akt_col->
v1;
1244 if (value & ALI_LEFT) {
1245 number += elem_akt_col->
v1;
1247 if (value & ALI_LUP) {
1248 for (l = 0; l < up_pointer->
size(); l++) {
1249 up = up_pointer->
get(l);
1253 "ALI_ALIGNER::number_of_solutions()");
1255 number += elem_akt_col->
v1;
1258 number += elem_akt_col->
v1;
1263 number += elem_akt_col->
v2;
1264 number += elem_akt_col->
v3;
1269 number += elem_akt_col->
v1;
1270 number += elem_akt_col->
v2;
1271 number += elem_akt_col->
v3;
1280 unsigned long sx,
unsigned long ex,
1281 unsigned long sy,
unsigned long ey)
1295 path_map[0] =
new ALI_PATHMAP(end_x - start_x + 1, end_y - start_y + 1);
1296 path_map[1] =
new ALI_PATHMAP(end_x - start_x + 1, end_y - start_y + 1);
1297 path_map[2] =
new ALI_PATHMAP(end_x - start_x + 1, end_y - start_y + 1);
ALI_TLIST< ali_aligner_dellist_elem * > list_of_dels
void ali_out_of_memory_if(bool cond)
ALI_TLIST< ali_pathmap_up_pointer > up_starts
float update(unsigned long position)
void optimize(unsigned long position)
void get(unsigned long x, unsigned long y, unsigned char *val, ALI_TARRAY< ali_pathmap_up_pointer > **up_pointer)
float w_ins(unsigned long, unsigned long)
float w_del(unsigned long begin, unsigned long end)
ali_aligner_cell ** cells
void set(unsigned long position, T value)
float w_del_multi_cheap(unsigned long start, unsigned long end)
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 * CALLOC(long i, long j)
ALI_TARRAY< ali_pathmap_up_pointer > * starts(float costs, unsigned long y_offset)
float w_ins_cheap(unsigned long, unsigned long)
void ali_error(const char *message, const char *func)
void optimize(unsigned long x)
T get(unsigned long position)
void update_border(unsigned long start_x, unsigned long end_x, unsigned long start_y, unsigned long end_y)
void insert(unsigned long start, float costs, unsigned char operation)
GB_write_int const char GB_write_autoconv_string WRITE_SKELETON(write_pointer, GBDATA *,"%p", GB_write_pointer) char *AW_awa if)(!gb_var) return strdup("")
void update_left(ali_aligner_cell *akt_cell, unsigned long akt_pos, unsigned long start_x, unsigned long end_x)
float w_del_cheap(unsigned long position)
ALI_ALIGNER(ALI_ALIGNER_CONTEXT *context, ALI_PROFILE *profile, unsigned long start_x, unsigned long end_x, unsigned long start_y, unsigned long end_y)
void set(unsigned long base, unsigned long pos, int insert=-1)
float gap_percent(unsigned long begin, unsigned long end)
void ali_fatal_error(const char *message, const char *func)
float w_sub(unsigned long positiony, unsigned long positionx)
void ali_message(const char *message)
float w_ins_multi_cheap(unsigned long startx, unsigned long endx)
T pop(unsigned long count=1)
void insert(ALI_MAP *in_map)
void update_up(ali_aligner_cell *akt_cell, unsigned long akt_pos, unsigned long start_y, unsigned long end_y)
unsigned long last_base()
ALI_TLIST< ali_pathmap_up_pointer > left_starts
T get(unsigned long position)
unsigned long column_length