1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "largeblockdp.h"
5
6
7 # line 6 "largeblockdp.c"
8
9
10 /***************** C functions ****************/
11 /* Written using dynamite */
12 /* Sat Sep 8 09:05:32 2007 */
13 /* email birney@sanger.ac.uk */
14 /* http://www.sanger.ac.uk/Users/birney/dynamite */
15 /*************************************************/
16
17
18 /* Please report any problems or bugs to */
19 /* Ewan Birney, birney@sanger.ac.uk */
20
21
22 /* basic set of macros to map states to numbers */
23 #define MATCH 0
24 #define INSERT 1
25 #define DELETE 2
26 #define UNMATCHED 3
27
28
29 #define START 0
30 #define END 1
31
32
33 #define LargeBlockAligner_EXPL_MATRIX(this_matrix,i,j,STATE) this_matrix->basematrix->matrix[((j+1)*4)+STATE][i+1]
34 #define LargeBlockAligner_EXPL_SPECIAL(matrix,i,j,STATE) matrix->basematrix->specmatrix[STATE][j+1]
35 #define LargeBlockAligner_READ_OFF_ERROR -3
36
37
38
39 #define LargeBlockAligner_VSMALL_MATRIX(mat,i,j,STATE) mat->basematrix->matrix[(j+2)%2][((i+1)*4)+STATE]
40 #define LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,STATE) mat->basematrix->specmatrix[(j+2)%2][STATE]
41
42
43
44
45 #define LargeBlockAligner_SHATTER_SPECIAL(matrix,i,j,STATE) matrix->shatter->special[STATE][j]
46 #define LargeBlockAligner_SHATTER_MATRIX(matrix,i,j,STATE) fetch_cell_value_ShatterMatrix(mat->shatter,i,j,STATE)
47
48
49 /* Function: PackAln_read_Shatter_LargeBlockAligner(mat)
50 *
51 * Descrip: Reads off PackAln from shatter matrix structure
52 *
53 *
54 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
55 *
56 * Return [UNKN ] Undocumented return value [PackAln *]
57 *
58 */
PackAln_read_Shatter_LargeBlockAligner(LargeBlockAligner * mat)59 PackAln * PackAln_read_Shatter_LargeBlockAligner(LargeBlockAligner * mat)
60 {
61 LargeBlockAligner_access_func_holder holder;
62
63
64 holder.access_main = LargeBlockAligner_shatter_access_main;
65 holder.access_special = LargeBlockAligner_shatter_access_special;
66 assert(mat);
67 assert(mat->shatter);
68 return PackAln_read_generic_LargeBlockAligner(mat,holder);
69 }
70
71
72 /* Function: LargeBlockAligner_shatter_access_main(mat,i,j,state)
73 *
74 * Descrip: No Description
75 *
76 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
77 * Arg: i [UNKN ] Undocumented argument [int]
78 * Arg: j [UNKN ] Undocumented argument [int]
79 * Arg: state [UNKN ] Undocumented argument [int]
80 *
81 * Return [UNKN ] Undocumented return value [int]
82 *
83 */
LargeBlockAligner_shatter_access_main(LargeBlockAligner * mat,int i,int j,int state)84 int LargeBlockAligner_shatter_access_main(LargeBlockAligner * mat,int i,int j,int state)
85 {
86 return LargeBlockAligner_SHATTER_MATRIX(mat,i,j,state);
87 }
88
89
90 /* Function: LargeBlockAligner_shatter_access_special(mat,i,j,state)
91 *
92 * Descrip: No Description
93 *
94 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
95 * Arg: i [UNKN ] Undocumented argument [int]
96 * Arg: j [UNKN ] Undocumented argument [int]
97 * Arg: state [UNKN ] Undocumented argument [int]
98 *
99 * Return [UNKN ] Undocumented return value [int]
100 *
101 */
LargeBlockAligner_shatter_access_special(LargeBlockAligner * mat,int i,int j,int state)102 int LargeBlockAligner_shatter_access_special(LargeBlockAligner * mat,int i,int j,int state)
103 {
104 return LargeBlockAligner_SHATTER_SPECIAL(mat,i,j,state);
105 }
106
107
108 /* Function: calculate_shatter_LargeBlockAligner(mat,dpenv)
109 *
110 * Descrip: This function calculates the LargeBlockAligner matrix when in shatter mode
111 *
112 *
113 * Arg: mat [UNKN ] (null) [LargeBlockAligner *]
114 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
115 *
116 * Return [UNKN ] Undocumented return value [boolean]
117 *
118 */
calculate_shatter_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)119 boolean calculate_shatter_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)
120 {
121 int i;
122 int j;
123 int k;
124 int should_calc;
125 int leni;
126 int lenj;
127 int tot;
128 int num;
129 int starti;
130 int startj;
131 int endi;
132 int endj;
133
134
135 int * SIG_0_0;
136 int * SIG_1_1;
137 int * SIG_0_1;
138 int * SIG_1_0;
139
140
141 leni = mat->leni;
142 lenj = mat->lenj;
143
144
145 mat->shatter = new_ShatterMatrix(dpenv,4,lenj,2);
146 prepare_DPEnvelope(dpenv);
147 starti = dpenv->starti;
148 if( starti < 0 )
149 starti = 0;
150 startj = dpenv->startj;
151 if( startj < 0 )
152 startj = 0;
153 endi = dpenv->endi;
154 if( endi > mat->leni )
155 endi = mat->leni;
156 endj = dpenv->endj;
157 if( endj > mat->lenj )
158 endj = mat->lenj;
159 tot = (endi-starti) * (endj-startj);
160 num = 0;
161
162
163 start_reporting("LargeBlockAligner Matrix calculation: ");
164 for(j=startj;j<endj;j++) {
165 auto int score;
166 auto int temp;
167 for(i=starti;i<endi;i++) {
168 /* Check if is in envelope - code identical to is_in_DPEnvelope, but aggressively inlined here for speed */
169 should_calc = 0;
170 for(k=0;k<dpenv->len;k++) {
171 auto DPUnit * u;
172 u = dpenv->dpu[k];
173 switch(u->type) {
174 case DPENV_RECT :
175 if( i >= u->starti && j >= u->startj && i < (u->starti+u->height) && j < (u->startj+u->length))
176 should_calc = 1;
177 break;
178 case DPENV_DIAG :
179 if( abs( (i-j) - (u->starti-u->startj)) <= u->height && i+j >= u->starti+u->startj && i+j+u->length >= u->starti+u->startj)
180 should_calc = 1;
181 break;
182 }
183 if( should_calc == 1 )
184 break;
185 }
186 if( should_calc == 0)
187 continue;
188
189
190 SIG_0_0 = fetch_cell_from_ShatterMatrix(mat->shatter,i,j);
191 SIG_1_1 = fetch_cell_from_ShatterMatrix(mat->shatter,i-1,j-1);
192 SIG_0_1 = fetch_cell_from_ShatterMatrix(mat->shatter,i-0,j-1);
193 SIG_1_0 = fetch_cell_from_ShatterMatrix(mat->shatter,i-1,j-0);
194
195
196
197
198 /* For state MATCH */
199 /* setting first movement to score */
200 score = SIG_1_1[MATCH] + 0;
201 /* From state INSERT to state MATCH */
202 temp = SIG_1_1[INSERT] + 0;
203 if( temp > score ) {
204 score = temp;
205 }
206 /* From state DELETE to state MATCH */
207 temp = SIG_1_1[DELETE] + 0;
208 if( temp > score ) {
209 score = temp;
210 }
211 /* From state UNMATCHED to state MATCH */
212 temp = SIG_1_1[UNMATCHED] + mat->block_open;
213 if( temp > score ) {
214 score = temp;
215 }
216 /* From state START to state MATCH */
217 temp = LargeBlockAligner_SHATTER_SPECIAL(mat,i-1,j-1,START) + mat->block_open;
218 if( temp > score ) {
219 score = temp;
220 }
221
222
223 /* Ok - finished max calculation for MATCH */
224 /* Add any movement independant score and put away */
225 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
226 SIG_0_0[MATCH] = score;
227
228
229 /* state MATCH is a source for special END */
230 temp = score + (0) + (0) ;
231 if( temp > LargeBlockAligner_SHATTER_SPECIAL(mat,i,j,END) ) {
232 LargeBlockAligner_SHATTER_SPECIAL(mat,i,j,END) = temp;
233 }
234
235
236
237
238 /* Finished calculating state MATCH */
239
240
241 /* For state INSERT */
242 /* setting first movement to score */
243 score = SIG_0_1[MATCH] + mat->gap_open;
244 /* From state INSERT to state INSERT */
245 temp = SIG_0_1[INSERT] + mat->gap_ext;
246 if( temp > score ) {
247 score = temp;
248 }
249
250
251 /* Ok - finished max calculation for INSERT */
252 /* Add any movement independant score and put away */
253 SIG_0_0[INSERT] = score;
254
255
256 /* Finished calculating state INSERT */
257
258
259 /* For state DELETE */
260 /* setting first movement to score */
261 score = SIG_1_0[MATCH] + mat->gap_open;
262 /* From state DELETE to state DELETE */
263 temp = SIG_1_0[DELETE] + mat->gap_ext;
264 if( temp > score ) {
265 score = temp;
266 }
267
268
269 /* Ok - finished max calculation for DELETE */
270 /* Add any movement independant score and put away */
271 SIG_0_0[DELETE] = score;
272
273
274 /* Finished calculating state DELETE */
275
276
277 /* For state UNMATCHED */
278 /* setting first movement to score */
279 score = SIG_1_1[MATCH] + mat->un_dual;
280 /* From state START to state UNMATCHED */
281 temp = LargeBlockAligner_SHATTER_SPECIAL(mat,i-1,j-1,START) + mat->un_dual;
282 if( temp > score ) {
283 score = temp;
284 }
285 /* From state UNMATCHED to state UNMATCHED */
286 temp = SIG_1_1[UNMATCHED] + mat->un_dual;
287 if( temp > score ) {
288 score = temp;
289 }
290 /* From state UNMATCHED to state UNMATCHED */
291 temp = SIG_0_1[UNMATCHED] + mat->un_single;
292 if( temp > score ) {
293 score = temp;
294 }
295 /* From state UNMATCHED to state UNMATCHED */
296 temp = SIG_1_0[UNMATCHED] + mat->un_single;
297 if( temp > score ) {
298 score = temp;
299 }
300
301
302 /* Ok - finished max calculation for UNMATCHED */
303 /* Add any movement independant score and put away */
304 SIG_0_0[UNMATCHED] = score;
305
306
307 /* state UNMATCHED is a source for special END */
308 temp = score + (0) + (0) ;
309 if( temp > LargeBlockAligner_SHATTER_SPECIAL(mat,i,j,END) ) {
310 LargeBlockAligner_SHATTER_SPECIAL(mat,i,j,END) = temp;
311 }
312
313
314
315
316 /* Finished calculating state UNMATCHED */
317 }
318
319
320 /* Special state START has no special to special movements */
321
322
323 /* Special state END has no special to special movements */
324 }
325 stop_reporting();
326 return TRUE;
327 }
328
329
330 /* Function: search_LargeBlockAligner(dbsi,out,q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext)
331 *
332 * Descrip: This function makes a database search of LargeBlockAligner
333 * It uses the dbsi structure to choose which implementation
334 * to use of the database searching. This way at run time you
335 * can switch between single threaded/multi-threaded or hardware
336 *
337 *
338 * Arg: dbsi [UNKN ] Undocumented argument [DBSearchImpl *]
339 * Arg: out [UNKN ] Undocumented argument [Hscore *]
340 * Arg: q [UNKN ] Undocumented argument [ComplexSequence*]
341 * Arg: t [UNKN ] Undocumented argument [ComplexSequence*]
342 * Arg: dm [UNKN ] Undocumented argument [DnaMatrix*]
343 * Arg: real_ext [UNKN ] Undocumented argument [Score]
344 * Arg: block_open [UNKN ] Undocumented argument [Score]
345 * Arg: un_dual [UNKN ] Undocumented argument [Score]
346 * Arg: un_single [UNKN ] Undocumented argument [Score]
347 * Arg: gap_open [UNKN ] Undocumented argument [Score]
348 * Arg: gap_ext [UNKN ] Undocumented argument [Score]
349 *
350 * Return [UNKN ] Undocumented return value [Search_Return_Type]
351 *
352 */
search_LargeBlockAligner(DBSearchImpl * dbsi,Hscore * out,ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)353 Search_Return_Type search_LargeBlockAligner(DBSearchImpl * dbsi,Hscore * out,ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)
354 {
355 if( out == NULL ) {
356 warn("Passed in a null Hscore object into search_LargeBlockAligner. Can't process results!");
357 return SEARCH_ERROR;
358 }
359 if( dbsi == NULL ) {
360 warn("Passed in a null DBSearchImpl object into search_LargeBlockAligner. Can't process results!");
361 return SEARCH_ERROR;
362 }
363 if( dbsi->trace_level > 5 )
364 warn("Asking for trace level of %d in database search for LargeBlockAligner, but it was compiled with a trace level of -2139062144. Not all trace statements can be shown",dbsi->trace_level);
365 switch(dbsi->type) { /*switch on implementation*/
366 case DBSearchImpl_Serial :
367 return serial_search_LargeBlockAligner(out,q,t ,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext);
368 case DBSearchImpl_Pthreads :
369 warn("This matrix LargeBlockAligner was not dyc compiled with thread support");
370 return SEARCH_ERROR;
371 default :
372 warn("database search implementation %s was not provided in the compiled dynamite file from LargeBlockAligner",impl_string_DBSearchImpl(dbsi));
373 return SEARCH_ERROR;
374 } /* end of switch on implementation */
375
376
377 }
378
379
380 /* Function: serial_search_LargeBlockAligner(out,q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext)
381 *
382 * Descrip: This function makes a database search of LargeBlockAligner
383 * It is a single processor implementation
384 *
385 *
386 * Arg: out [UNKN ] Undocumented argument [Hscore *]
387 * Arg: q [UNKN ] Undocumented argument [ComplexSequence*]
388 * Arg: t [UNKN ] Undocumented argument [ComplexSequence*]
389 * Arg: dm [UNKN ] Undocumented argument [DnaMatrix*]
390 * Arg: real_ext [UNKN ] Undocumented argument [Score]
391 * Arg: block_open [UNKN ] Undocumented argument [Score]
392 * Arg: un_dual [UNKN ] Undocumented argument [Score]
393 * Arg: un_single [UNKN ] Undocumented argument [Score]
394 * Arg: gap_open [UNKN ] Undocumented argument [Score]
395 * Arg: gap_ext [UNKN ] Undocumented argument [Score]
396 *
397 * Return [UNKN ] Undocumented return value [Search_Return_Type]
398 *
399 */
serial_search_LargeBlockAligner(Hscore * out,ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)400 Search_Return_Type serial_search_LargeBlockAligner(Hscore * out,ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)
401 {
402 int db_status;
403 int score;
404 int query_pos = 0;
405 int target_pos = 0;
406 DataScore * ds;
407
408
409 push_errormsg_stack("Before any actual search in db searching");
410
411
412 target_pos = 0;
413
414
415
416
417 /* No maximum length - allocated on-the-fly */
418 score = score_only_LargeBlockAligner(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext);
419 if( should_store_Hscore(out,score) == TRUE ) { /*if storing datascore*/
420 ds = new_DataScore_from_storage(out);
421 if( ds == NULL ) {
422 warn("LargeBlockAligner search had a memory error in allocating a new_DataScore (?a leak somewhere - DataScore is a very small datastructure");
423 return SEARCH_ERROR;
424 }
425 /* Now: add query/target information to the entry */
426 ds->score = score;
427 add_Hscore(out,ds);
428 } /* end of if storing datascore */
429 pop_errormsg_stack();
430 push_errormsg_stack("DB searching: just finished [Query Pos: %d] [Target Pos: %d]",query_pos,target_pos);
431
432
433 pop_errormsg_stack();
434 return SEARCH_OK;
435 }
436
437
438 /* Function: score_only_LargeBlockAligner(q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext)
439 *
440 * Descrip: This function just calculates the score for the matrix
441 * I am pretty sure we can do this better, but hey, for the moment...
442 * It calls /allocate_LargeBlockAligner_only
443 *
444 *
445 * Arg: q [UNKN ] query data structure [ComplexSequence*]
446 * Arg: t [UNKN ] target data structure [ComplexSequence*]
447 * Arg: dm [UNKN ] Resource [DnaMatrix*]
448 * Arg: real_ext [UNKN ] Resource [Score]
449 * Arg: block_open [UNKN ] Resource [Score]
450 * Arg: un_dual [UNKN ] Resource [Score]
451 * Arg: un_single [UNKN ] Resource [Score]
452 * Arg: gap_open [UNKN ] Resource [Score]
453 * Arg: gap_ext [UNKN ] Resource [Score]
454 *
455 * Return [UNKN ] Undocumented return value [int]
456 *
457 */
score_only_LargeBlockAligner(ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)458 int score_only_LargeBlockAligner(ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)
459 {
460 int bestscore = NEGI;
461 int i;
462 int j;
463 int k;
464 LargeBlockAligner * mat;
465
466
467 mat = allocate_LargeBlockAligner_only(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext);
468 if( mat == NULL ) {
469 warn("Memory allocation error in the db search - unable to communicate to calling function. this spells DIASTER!");
470 return NEGI;
471 }
472 if((mat->basematrix = BaseMatrix_alloc_matrix_and_specials(2,(mat->leni + 1) * 4,2,2)) == NULL) {
473 warn("Score only matrix for LargeBlockAligner cannot be allocated, (asking for 1 by %d cells)",mat->leni*4);
474 mat = free_LargeBlockAligner(mat);
475 return 0;
476 }
477 mat->basematrix->type = BASEMATRIX_TYPE_VERYSMALL;
478
479
480 /* Now, initiate matrix */
481 for(j=0;j<3;j++) {
482 for(i=(-1);i<mat->leni;i++) {
483 for(k=0;k<4;k++)
484 LargeBlockAligner_VSMALL_MATRIX(mat,i,j,k) = NEGI;
485 }
486 LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,START) = 0;
487 LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,END) = NEGI;
488 }
489
490
491 /* Ok, lets do-o-o-o-o it */
492
493
494 for(j=0;j<mat->lenj;j++) { /*for all target positions*/
495 auto int score;
496 auto int temp;
497 for(i=0;i<mat->leni;i++) { /*for all query positions*/
498
499
500 /* For state MATCH */
501 /* setting first movement to score */
502 score = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,MATCH) + 0;
503 /* From state INSERT to state MATCH */
504 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,INSERT) + 0;
505 if( temp > score ) {
506 score = temp;
507 }
508 /* From state DELETE to state MATCH */
509 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,DELETE) + 0;
510 if( temp > score ) {
511 score = temp;
512 }
513 /* From state UNMATCHED to state MATCH */
514 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
515 if( temp > score ) {
516 score = temp;
517 }
518 /* From state START to state MATCH */
519 temp = LargeBlockAligner_VSMALL_SPECIAL(mat,i-1,j-1,START) + mat->block_open;
520 if( temp > score ) {
521 score = temp;
522 }
523
524
525 /* Ok - finished max calculation for MATCH */
526 /* Add any movement independant score and put away */
527 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
528 LargeBlockAligner_VSMALL_MATRIX(mat,i,j,MATCH) = score;
529
530
531 /* state MATCH is a source for special END */
532 temp = score + (0) + (0) ;
533 if( temp > LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,END) ) {
534 LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,END) = temp;
535 }
536
537
538
539
540 /* Finished calculating state MATCH */
541
542
543 /* For state INSERT */
544 /* setting first movement to score */
545 score = LargeBlockAligner_VSMALL_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
546 /* From state INSERT to state INSERT */
547 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
548 if( temp > score ) {
549 score = temp;
550 }
551
552
553 /* Ok - finished max calculation for INSERT */
554 /* Add any movement independant score and put away */
555 LargeBlockAligner_VSMALL_MATRIX(mat,i,j,INSERT) = score;
556
557
558 /* Finished calculating state INSERT */
559
560
561 /* For state DELETE */
562 /* setting first movement to score */
563 score = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
564 /* From state DELETE to state DELETE */
565 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
566 if( temp > score ) {
567 score = temp;
568 }
569
570
571 /* Ok - finished max calculation for DELETE */
572 /* Add any movement independant score and put away */
573 LargeBlockAligner_VSMALL_MATRIX(mat,i,j,DELETE) = score;
574
575
576 /* Finished calculating state DELETE */
577
578
579 /* For state UNMATCHED */
580 /* setting first movement to score */
581 score = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
582 /* From state START to state UNMATCHED */
583 temp = LargeBlockAligner_VSMALL_SPECIAL(mat,i-1,j-1,START) + mat->un_dual;
584 if( temp > score ) {
585 score = temp;
586 }
587 /* From state UNMATCHED to state UNMATCHED */
588 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
589 if( temp > score ) {
590 score = temp;
591 }
592 /* From state UNMATCHED to state UNMATCHED */
593 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
594 if( temp > score ) {
595 score = temp;
596 }
597 /* From state UNMATCHED to state UNMATCHED */
598 temp = LargeBlockAligner_VSMALL_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
599 if( temp > score ) {
600 score = temp;
601 }
602
603
604 /* Ok - finished max calculation for UNMATCHED */
605 /* Add any movement independant score and put away */
606 LargeBlockAligner_VSMALL_MATRIX(mat,i,j,UNMATCHED) = score;
607
608
609 /* state UNMATCHED is a source for special END */
610 temp = score + (0) + (0) ;
611 if( temp > LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,END) ) {
612 LargeBlockAligner_VSMALL_SPECIAL(mat,i,j,END) = temp;
613 }
614
615
616
617
618 /* Finished calculating state UNMATCHED */
619 } /* end of for all query positions */
620
621
622
623
624 /* Special state START has no special to special movements */
625
626
627 /* Special state END has no special to special movements */
628 if( bestscore < LargeBlockAligner_VSMALL_SPECIAL(mat,0,j,END) )
629 bestscore = LargeBlockAligner_VSMALL_SPECIAL(mat,0,j,END);
630 } /* end of for all target positions */
631
632
633 mat = free_LargeBlockAligner(mat);
634 return bestscore;
635 }
636
637
638 /* Function: PackAln_bestmemory_LargeBlockAligner(q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext,dpenv,dpri)
639 *
640 * Descrip: This function chooses the best memory set-up for the alignment
641 * using calls to basematrix, and then implements either a large
642 * or small memory model.
643 *
644 * It is the best function to use if you just want an alignment
645 *
646 * If you want a label alignment, you will need
647 * /convert_PackAln_to_AlnBlock_LargeBlockAligner
648 *
649 *
650 * Arg: q [UNKN ] query data structure [ComplexSequence*]
651 * Arg: t [UNKN ] target data structure [ComplexSequence*]
652 * Arg: dm [UNKN ] Resource [DnaMatrix*]
653 * Arg: real_ext [UNKN ] Resource [Score]
654 * Arg: block_open [UNKN ] Resource [Score]
655 * Arg: un_dual [UNKN ] Resource [Score]
656 * Arg: un_single [UNKN ] Resource [Score]
657 * Arg: gap_open [UNKN ] Resource [Score]
658 * Arg: gap_ext [UNKN ] Resource [Score]
659 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
660 * Arg: dpri [UNKN ] Undocumented argument [DPRunImpl *]
661 *
662 * Return [UNKN ] Undocumented return value [PackAln *]
663 *
664 */
PackAln_bestmemory_LargeBlockAligner(ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext,DPEnvelope * dpenv,DPRunImpl * dpri)665 PackAln * PackAln_bestmemory_LargeBlockAligner(ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext,DPEnvelope * dpenv,DPRunImpl * dpri)
666 {
667 long long total;
668 LargeBlockAligner * mat;
669 PackAln * out;
670 DebugMatrix * de;
671 DPRunImplMemory strategy;
672 assert(dpri);
673
674
675 total = q->seq->len * t->seq->len;
676 if( dpri->memory == DPIM_Default ) {
677 if( (total * 4 * sizeof(int)) > 1000*dpri->kbyte_size) {
678 strategy = DPIM_Linear;
679 }
680 else {
681 strategy = DPIM_Explicit;
682 }
683 }
684 else {
685 strategy = dpri->memory;
686 }
687
688
689 if( dpenv != NULL ) {
690 if( strategy == DPIM_Explicit) {
691 if( (mat=allocate_Expl_LargeBlockAligner(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext,dpri)) == NULL ) {
692 warn("Unable to allocate large LargeBlockAligner version");
693 return NULL;
694 }
695 calculate_dpenv_LargeBlockAligner(mat,dpenv);
696 out = PackAln_read_Expl_LargeBlockAligner(mat);
697 }
698 else {
699 mat = allocate_LargeBlockAligner_only(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext);
700 calculate_shatter_LargeBlockAligner(mat,dpenv);
701 out = PackAln_read_Shatter_LargeBlockAligner(mat);
702 }
703 }
704 else {
705 if( strategy == DPIM_Linear ) {
706 /* use small implementation */
707 if( (mat=allocate_Small_LargeBlockAligner(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext)) == NULL ) {
708 warn("Unable to allocate small LargeBlockAligner version");
709 return NULL;
710 }
711 out = PackAln_calculate_Small_LargeBlockAligner(mat,dpenv);
712 }
713 else {
714 /* use Large implementation */
715 if( (mat=allocate_Expl_LargeBlockAligner(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext,dpri)) == NULL ) {
716 warn("Unable to allocate large LargeBlockAligner version");
717 return NULL;
718 }
719 if( dpri->debug == TRUE) {
720 fatal("Asked for dydebug, but dynamite file not compiled with -g. Need to recompile dynamite source");
721 }
722 else {
723 calculate_LargeBlockAligner(mat);
724 out = PackAln_read_Expl_LargeBlockAligner(mat);
725 }
726 }
727 }
728
729
730 mat = free_LargeBlockAligner(mat);
731 return out;
732 }
733
734
735 /* Function: allocate_LargeBlockAligner_only(q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext)
736 *
737 * Descrip: This function only allocates the LargeBlockAligner structure
738 * checks types where possible and determines leni and lenj
739 * The basematrix area is delt with elsewhere
740 *
741 *
742 * Arg: q [UNKN ] query data structure [ComplexSequence*]
743 * Arg: t [UNKN ] target data structure [ComplexSequence*]
744 * Arg: dm [UNKN ] Resource [DnaMatrix*]
745 * Arg: real_ext [UNKN ] Resource [Score]
746 * Arg: block_open [UNKN ] Resource [Score]
747 * Arg: un_dual [UNKN ] Resource [Score]
748 * Arg: un_single [UNKN ] Resource [Score]
749 * Arg: gap_open [UNKN ] Resource [Score]
750 * Arg: gap_ext [UNKN ] Resource [Score]
751 *
752 * Return [UNKN ] Undocumented return value [LargeBlockAligner *]
753 *
754 */
allocate_LargeBlockAligner_only(ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)755 LargeBlockAligner * allocate_LargeBlockAligner_only(ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)
756 {
757 LargeBlockAligner * out;
758
759
760 if((out= LargeBlockAligner_alloc()) == NULL) {
761 warn("Allocation of basic LargeBlockAligner structure failed...");
762 return NULL;
763 }
764
765
766 out->q = q;
767 out->t = t;
768 out->dm = dm;
769 out->real_ext = real_ext;
770 out->block_open = block_open;
771 out->un_dual = un_dual;
772 out->un_single = un_single;
773 out->gap_open = gap_open;
774 out->gap_ext = gap_ext;
775 out->leni = q->seq->len;
776 out->lenj = t->seq->len;
777 return out;
778 }
779
780
781 /* Function: allocate_Expl_LargeBlockAligner(q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext,dpri)
782 *
783 * Descrip: This function allocates the LargeBlockAligner structure
784 * and the basematrix area for explicit memory implementations
785 * It calls /allocate_LargeBlockAligner_only
786 *
787 *
788 * Arg: q [UNKN ] query data structure [ComplexSequence*]
789 * Arg: t [UNKN ] target data structure [ComplexSequence*]
790 * Arg: dm [UNKN ] Resource [DnaMatrix*]
791 * Arg: real_ext [UNKN ] Resource [Score]
792 * Arg: block_open [UNKN ] Resource [Score]
793 * Arg: un_dual [UNKN ] Resource [Score]
794 * Arg: un_single [UNKN ] Resource [Score]
795 * Arg: gap_open [UNKN ] Resource [Score]
796 * Arg: gap_ext [UNKN ] Resource [Score]
797 * Arg: dpri [UNKN ] Undocumented argument [DPRunImpl *]
798 *
799 * Return [UNKN ] Undocumented return value [LargeBlockAligner *]
800 *
801 */
allocate_Expl_LargeBlockAligner(ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext,DPRunImpl * dpri)802 LargeBlockAligner * allocate_Expl_LargeBlockAligner(ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext,DPRunImpl * dpri)
803 {
804 LargeBlockAligner * out;
805
806
807 out = allocate_LargeBlockAligner_only(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext);
808 if( out == NULL )
809 return NULL;
810 if( dpri->should_cache == TRUE ) {
811 if( dpri->cache != NULL ) {
812 if( dpri->cache->maxleni >= (out->lenj+1)*4 && dpri->cache->maxlenj >= (out->leni+1))
813 out->basematrix = hard_link_BaseMatrix(dpri->cache);
814 else
815 dpri->cache = free_BaseMatrix(dpri->cache);
816 }
817 }
818 if( out->basematrix == NULL ) {
819 if( (out->basematrix = BaseMatrix_alloc_matrix_and_specials((out->lenj+1)*4,(out->leni+1),2,out->lenj+1)) == NULL) {
820 warn("Explicit matrix LargeBlockAligner cannot be allocated, (asking for %d by %d main cells)",out->leni,out->lenj);
821 free_LargeBlockAligner(out);
822 return NULL;
823 }
824 }
825 if( dpri->should_cache == TRUE && dpri->cache == NULL)
826 dpri->cache = hard_link_BaseMatrix(out->basematrix);
827 out->basematrix->type = BASEMATRIX_TYPE_EXPLICIT;
828 init_LargeBlockAligner(out);
829 return out;
830 }
831
832
833 /* Function: init_LargeBlockAligner(mat)
834 *
835 * Descrip: This function initates LargeBlockAligner matrix when in explicit mode
836 * Called in /allocate_Expl_LargeBlockAligner
837 *
838 *
839 * Arg: mat [UNKN ] LargeBlockAligner which contains explicit basematrix memory [LargeBlockAligner *]
840 *
841 */
init_LargeBlockAligner(LargeBlockAligner * mat)842 void init_LargeBlockAligner(LargeBlockAligner * mat)
843 {
844 register int i;
845 register int j;
846 if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT) {
847 warn("Cannot iniate matrix, is not an explicit memory type and you have assummed that");
848 return;
849 }
850
851
852 for(i= (-1);i<mat->q->seq->len;i++) {
853 for(j= (-1);j<2;j++) {
854 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = NEGI;
855 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = NEGI;
856 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = NEGI;
857 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = NEGI;
858 }
859 }
860 for(j= (-1);j<mat->t->seq->len;j++) {
861 for(i= (-1);i<2;i++) {
862 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = NEGI;
863 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = NEGI;
864 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = NEGI;
865 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = NEGI;
866 }
867 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,START) = 0;
868 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = NEGI;
869 }
870 return;
871 }
872
873
874 /* Function: recalculate_PackAln_LargeBlockAligner(pal,mat)
875 *
876 * Descrip: This function recalculates the PackAln structure produced by LargeBlockAligner
877 * For example, in linear space methods this is used to score them
878 *
879 *
880 * Arg: pal [UNKN ] Undocumented argument [PackAln *]
881 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
882 *
883 */
recalculate_PackAln_LargeBlockAligner(PackAln * pal,LargeBlockAligner * mat)884 void recalculate_PackAln_LargeBlockAligner(PackAln * pal,LargeBlockAligner * mat)
885 {
886 int i,j,k,offi,offj;
887 PackAlnUnit * prev;
888 PackAlnUnit * pau;
889
890
891 for(k=1,prev=pal->pau[0];k < pal->len;k++,prev=pau) {
892 pau = pal->pau[k];
893 i = pau->i;
894 j = pau->j;
895 offi = pau->i - prev->i;
896 offj = pau->j - prev->j;
897 switch(pau->state) {
898 case MATCH :
899 if( offi == 1 && offj == 1 && prev->state == MATCH ) {
900 pau->score = 0 + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
901 continue;
902 }
903 if( offi == 1 && offj == 1 && prev->state == INSERT ) {
904 pau->score = 0 + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
905 continue;
906 }
907 if( offi == 1 && offj == 1 && prev->state == DELETE ) {
908 pau->score = 0 + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
909 continue;
910 }
911 if( offi == 1 && offj == 1 && prev->state == UNMATCHED ) {
912 pau->score = mat->block_open + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
913 continue;
914 }
915 if( offj == 1 && prev->state == (START+4) ) {
916 pau->score = mat->block_open + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
917 continue;
918 }
919 warn("In recaluclating PackAln with state MATCH, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
920 break;
921 case INSERT :
922 if( offi == 0 && offj == 1 && prev->state == MATCH ) {
923 pau->score = mat->gap_open + (0);
924 continue;
925 }
926 if( offi == 0 && offj == 1 && prev->state == INSERT ) {
927 pau->score = mat->gap_ext + (0);
928 continue;
929 }
930 warn("In recaluclating PackAln with state INSERT, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
931 break;
932 case DELETE :
933 if( offi == 1 && offj == 0 && prev->state == MATCH ) {
934 pau->score = mat->gap_open + (0);
935 continue;
936 }
937 if( offi == 1 && offj == 0 && prev->state == DELETE ) {
938 pau->score = mat->gap_ext + (0);
939 continue;
940 }
941 warn("In recaluclating PackAln with state DELETE, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
942 break;
943 case UNMATCHED :
944 if( offi == 1 && offj == 1 && prev->state == MATCH ) {
945 pau->score = mat->un_dual + (0);
946 continue;
947 }
948 if( offj == 1 && prev->state == (START+4) ) {
949 pau->score = mat->un_dual + (0);
950 continue;
951 }
952 if( offi == 1 && offj == 1 && prev->state == UNMATCHED ) {
953 pau->score = mat->un_dual + (0);
954 continue;
955 }
956 if( offi == 0 && offj == 1 && prev->state == UNMATCHED ) {
957 pau->score = mat->un_single + (0);
958 continue;
959 }
960 if( offi == 1 && offj == 0 && prev->state == UNMATCHED ) {
961 pau->score = mat->un_single + (0);
962 continue;
963 }
964 warn("In recaluclating PackAln with state UNMATCHED, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
965 break;
966 case (START+4) :
967 warn("In recaluclating PackAln with state START, got a bad source state. Error!");
968 break;
969 case (END+4) :
970 if( offj == 0 && prev->state == MATCH ) {
971 /* i here comes from the previous state ;) - not the real one */
972 i = prev->i;
973 pau->score = 0 + (0);
974 continue;
975 }
976 if( offj == 0 && prev->state == UNMATCHED ) {
977 /* i here comes from the previous state ;) - not the real one */
978 i = prev->i;
979 pau->score = 0 + (0);
980 continue;
981 }
982 warn("In recaluclating PackAln with state END, got a bad source state. Error!");
983 break;
984 default :
985 warn("In recaluclating PackAln got a bad recipient state. Error!");
986 }
987 prev = pau;
988 }
989 return;
990 }
991 /* divide and conquor macros are next */
992 #define LargeBlockAligner_HIDDEN_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[(j-hiddenj+1)][(i+1)*4+state])
993 #define LargeBlockAligner_DC_SHADOW_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[((j+2)*8) % 16][(i+1)*4+state])
994 #define LargeBlockAligner_HIDDEN_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state][(j+1)])
995 #define LargeBlockAligner_DC_SHADOW_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state*8][(j+1)])
996 #define LargeBlockAligner_DC_SHADOW_MATRIX_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->matrix[((((j+2)*8)+(shadow+1)) % 16)][(i+1)*4 + state])
997 #define LargeBlockAligner_DC_SHADOW_SPECIAL_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->specmatrix[state*8 +shadow+1][(j+1)])
998 #define LargeBlockAligner_DC_OPT_SHADOW_MATRIX(thismatrix,i,j,state) (score_pointers[(((j+1)% 1) * (leni+1) * 4) + ((i+1) * 4) + (state)])
999 #define LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(thismatrix,i,j,state,shadow) (shadow_pointers[(((j+1)% 1) * (leni+1) * 32) + ((i+1) * 32) + (state * 8) + shadow+1])
1000 #define LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state*8][(j+1)])
1001 /* Function: allocate_Small_LargeBlockAligner(q,t,dm,real_ext,block_open,un_dual,un_single,gap_open,gap_ext)
1002 *
1003 * Descrip: This function allocates the LargeBlockAligner structure
1004 * and the basematrix area for a small memory implementations
1005 * It calls /allocate_LargeBlockAligner_only
1006 *
1007 *
1008 * Arg: q [UNKN ] query data structure [ComplexSequence*]
1009 * Arg: t [UNKN ] target data structure [ComplexSequence*]
1010 * Arg: dm [UNKN ] Resource [DnaMatrix*]
1011 * Arg: real_ext [UNKN ] Resource [Score]
1012 * Arg: block_open [UNKN ] Resource [Score]
1013 * Arg: un_dual [UNKN ] Resource [Score]
1014 * Arg: un_single [UNKN ] Resource [Score]
1015 * Arg: gap_open [UNKN ] Resource [Score]
1016 * Arg: gap_ext [UNKN ] Resource [Score]
1017 *
1018 * Return [UNKN ] Undocumented return value [LargeBlockAligner *]
1019 *
1020 */
1021 #define LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->specmatrix[state*8 +shadow+1][(j+1)])
allocate_Small_LargeBlockAligner(ComplexSequence * q,ComplexSequence * t,DnaMatrix * dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)1022 LargeBlockAligner * allocate_Small_LargeBlockAligner(ComplexSequence* q,ComplexSequence* t ,DnaMatrix* dm,Score real_ext,Score block_open,Score un_dual,Score un_single,Score gap_open,Score gap_ext)
1023 {
1024 LargeBlockAligner * out;
1025
1026
1027 out = allocate_LargeBlockAligner_only(q, t , dm, real_ext, block_open, un_dual, un_single, gap_open, gap_ext);
1028 if( out == NULL )
1029 return NULL;
1030 out->basematrix = BaseMatrix_alloc_matrix_and_specials(16,(out->leni + 1) * 4,16,out->lenj+1);
1031 if(out == NULL) {
1032 warn("Small shadow matrix LargeBlockAligner cannot be allocated, (asking for 2 by %d main cells)",out->leni+2);
1033 free_LargeBlockAligner(out);
1034 return NULL;
1035 }
1036 out->basematrix->type = BASEMATRIX_TYPE_SHADOW;
1037 return out;
1038 }
1039
1040
1041 /* Function: PackAln_calculate_Small_LargeBlockAligner(mat,dpenv)
1042 *
1043 * Descrip: This function calculates an alignment for LargeBlockAligner structure in linear space
1044 * If you want only the start/end points
1045 * use /AlnRangeSet_calculate_Small_LargeBlockAligner
1046 *
1047 * The function basically
1048 * finds start/end points
1049 * foreach start/end point
1050 * calls /full_dc_LargeBlockAligner
1051 *
1052 *
1053 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1054 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
1055 *
1056 * Return [UNKN ] Undocumented return value [PackAln *]
1057 *
1058 */
PackAln_calculate_Small_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)1059 PackAln * PackAln_calculate_Small_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)
1060 {
1061 int endj;
1062 int score;
1063 PackAln * out;
1064 PackAlnUnit * pau;
1065 int starti;
1066 int startj;
1067 int startstate;
1068 int stopi;
1069 int stopj;
1070 int stopstate;
1071 int temp;
1072 int donej; /* This is for reporting, will be passed as a & arg in */
1073 int totalj; /* This also is for reporting, but as is not changed, can be passed by value */
1074
1075
1076 if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW ) {
1077 warn("Could not calculate packaln small for LargeBlockAligner due to wrong type of matrix");
1078 return NULL;
1079 }
1080
1081
1082 out = PackAln_alloc_std();
1083
1084
1085 start_reporting("Find start end points: ");
1086 dc_optimised_start_end_calc_LargeBlockAligner(mat,dpenv);
1087 score = start_end_find_end_LargeBlockAligner(mat,&endj);
1088 out->score = score;
1089 stopstate = END;
1090
1091 /* No special to specials: one matrix alignment: simply remove and get */
1092 starti = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,0);
1093 startj = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,1);
1094 startstate = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,2);
1095 stopi = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,3);
1096 stopj = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,4);
1097 stopstate = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,5);
1098 temp = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,6);
1099 log_full_error(REPORT,0,"[%d,%d][%d,%d] Score %d",starti,startj,stopi,stopj,score);
1100 stop_reporting();
1101 start_reporting("Recovering alignment: ");
1102
1103
1104 /* Figuring how much j we have to align for reporting purposes */
1105 donej = 0;
1106 totalj = stopj - startj;
1107 full_dc_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,out,&donej,totalj,dpenv);
1108
1109
1110 /* Although we have no specials, need to get start. Better to check than assume */
1111
1112
1113 max_matrix_to_special_LargeBlockAligner(mat,starti,startj,startstate,temp,&stopi,&stopj,&stopstate,&temp,NULL);
1114 if( stopi == LargeBlockAligner_READ_OFF_ERROR || stopstate != START ) {
1115 warn("Problem in reading off special state system, hit a non start state (or an internal error) in a single alignment mode");
1116 invert_PackAln(out);
1117 recalculate_PackAln_LargeBlockAligner(out,mat);
1118 return out;
1119 }
1120
1121
1122 /* Ok. Put away start start... */
1123 pau = PackAlnUnit_alloc();
1124 pau->i = stopi;
1125 pau->j = stopj;
1126 pau->state = stopstate + 4;
1127 add_PackAln(out,pau);
1128
1129
1130 log_full_error(REPORT,0,"Alignment recovered");
1131 stop_reporting();
1132 invert_PackAln(out);
1133 recalculate_PackAln_LargeBlockAligner(out,mat);
1134 return out;
1135
1136
1137 }
1138
1139
1140 /* Function: AlnRangeSet_calculate_Small_LargeBlockAligner(mat)
1141 *
1142 * Descrip: This function calculates an alignment for LargeBlockAligner structure in linear space
1143 * If you want the full alignment, use /PackAln_calculate_Small_LargeBlockAligner
1144 * If you have already got the full alignment, but want the range set, use /AlnRangeSet_from_PackAln_LargeBlockAligner
1145 * If you have got the small matrix but not the alignment, use /AlnRangeSet_from_LargeBlockAligner
1146 *
1147 *
1148 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1149 *
1150 * Return [UNKN ] Undocumented return value [AlnRangeSet *]
1151 *
1152 */
AlnRangeSet_calculate_Small_LargeBlockAligner(LargeBlockAligner * mat)1153 AlnRangeSet * AlnRangeSet_calculate_Small_LargeBlockAligner(LargeBlockAligner * mat)
1154 {
1155 AlnRangeSet * out;
1156
1157
1158 start_reporting("Find start end points: ");
1159 dc_optimised_start_end_calc_LargeBlockAligner(mat,NULL);
1160 log_full_error(REPORT,0,"Calculated");
1161
1162
1163 out = AlnRangeSet_from_LargeBlockAligner(mat);
1164 return out;
1165 }
1166
1167
1168 /* Function: AlnRangeSet_from_LargeBlockAligner(mat)
1169 *
1170 * Descrip: This function reads off a start/end structure
1171 * for LargeBlockAligner structure in linear space
1172 * If you want the full alignment use
1173 * /PackAln_calculate_Small_LargeBlockAligner
1174 * If you have not calculated the matrix use
1175 * /AlnRange_calculate_Small_LargeBlockAligner
1176 *
1177 *
1178 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1179 *
1180 * Return [UNKN ] Undocumented return value [AlnRangeSet *]
1181 *
1182 */
AlnRangeSet_from_LargeBlockAligner(LargeBlockAligner * mat)1183 AlnRangeSet * AlnRangeSet_from_LargeBlockAligner(LargeBlockAligner * mat)
1184 {
1185 AlnRangeSet * out;
1186 AlnRange * temp;
1187 int jpos;
1188 int state;
1189
1190
1191 if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
1192 warn("Bad error! - non shadow matrix type in AlnRangeSet_from_LargeBlockAligner");
1193 return NULL;
1194 }
1195
1196
1197 out = AlnRangeSet_alloc_std();
1198 /* Find the end position */
1199 out->score = start_end_find_end_LargeBlockAligner(mat,&jpos);
1200 state = END;
1201
1202
1203 while( (temp = AlnRange_build_LargeBlockAligner(mat,jpos,state,&jpos,&state)) != NULL)
1204 add_AlnRangeSet(out,temp);
1205 return out;
1206 }
1207
1208
1209 /* Function: AlnRange_build_LargeBlockAligner(mat,stopj,stopspecstate,startj,startspecstate)
1210 *
1211 * Descrip: This function calculates a single start/end set in linear space
1212 * Really a sub-routine for /AlnRangeSet_from_PackAln_LargeBlockAligner
1213 *
1214 *
1215 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1216 * Arg: stopj [UNKN ] Undocumented argument [int]
1217 * Arg: stopspecstate [UNKN ] Undocumented argument [int]
1218 * Arg: startj [UNKN ] Undocumented argument [int *]
1219 * Arg: startspecstate [UNKN ] Undocumented argument [int *]
1220 *
1221 * Return [UNKN ] Undocumented return value [AlnRange *]
1222 *
1223 */
AlnRange_build_LargeBlockAligner(LargeBlockAligner * mat,int stopj,int stopspecstate,int * startj,int * startspecstate)1224 AlnRange * AlnRange_build_LargeBlockAligner(LargeBlockAligner * mat,int stopj,int stopspecstate,int * startj,int * startspecstate)
1225 {
1226 AlnRange * out;
1227 int jpos;
1228 int state;
1229
1230
1231 if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
1232 warn("Bad error! - non shadow matrix type in AlnRangeSet_from_LargeBlockAligner");
1233 return NULL;
1234 }
1235
1236
1237 /* Assumme that we have specials (we should!). Read back along the specials till we have the finish point */
1238 if( read_special_strip_LargeBlockAligner(mat,0,stopj,stopspecstate,&jpos,&state,NULL) == FALSE) {
1239 warn("In AlnRanger_build_LargeBlockAligner alignment ending at %d, unable to read back specials. Will (evenutally) return a partial range set... BEWARE!",stopj);
1240 return NULL;
1241 }
1242 if( state == START || jpos <= 0)
1243 return NULL;
1244
1245
1246 out = AlnRange_alloc();
1247
1248
1249 out->starti = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,0);
1250 out->startj = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,1);
1251 out->startstate = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,2);
1252 out->stopi = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,3);
1253 out->stopj = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,4);
1254 out->stopstate = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,5);
1255 out->startscore = LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,6);
1256 out->stopscore = LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,jpos,state);
1257
1258
1259 /* Now, we have to figure out where this state came from in the specials */
1260 max_matrix_to_special_LargeBlockAligner(mat,out->starti,out->startj,out->startstate,out->startscore,&jpos,startj,startspecstate,&state,NULL);
1261 if( jpos == LargeBlockAligner_READ_OFF_ERROR) {
1262 warn("In AlnRange_build_LargeBlockAligner alignment ending at %d, with aln range between %d-%d in j, unable to find source special, returning this range, but this could get tricky!",stopj,out->startj,out->stopj);
1263 return out;
1264 }
1265
1266
1267 /* Put in the correct score for startstate, from the special */
1268 out->startscore = LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,*startj,*startspecstate);
1269 /* The correct j coords have been put into startj, startspecstate... so just return out */
1270 return out;
1271 }
1272
1273
1274 /* Function: read_hidden_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,out)
1275 *
1276 * Descrip: No Description
1277 *
1278 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1279 * Arg: starti [UNKN ] Undocumented argument [int]
1280 * Arg: startj [UNKN ] Undocumented argument [int]
1281 * Arg: startstate [UNKN ] Undocumented argument [int]
1282 * Arg: stopi [UNKN ] Undocumented argument [int]
1283 * Arg: stopj [UNKN ] Undocumented argument [int]
1284 * Arg: stopstate [UNKN ] Undocumented argument [int]
1285 * Arg: out [UNKN ] Undocumented argument [PackAln *]
1286 *
1287 * Return [UNKN ] Undocumented return value [boolean]
1288 *
1289 */
read_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out)1290 boolean read_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out)
1291 {
1292 int i;
1293 int j;
1294 int state;
1295 int cellscore;
1296 int isspecial;
1297 /* We don't need hiddenj here, 'cause matrix access handled by max funcs */
1298 PackAlnUnit * pau;
1299
1300
1301 /* stop position is on the path */
1302 i = stopi;
1303 j = stopj;
1304 state= stopstate;
1305 isspecial = FALSE;
1306
1307
1308 while( i >= starti && j >= startj) {
1309 /* Put away current i,j,state */
1310 pau = PackAlnUnit_alloc();/* Should deal with memory overflow */
1311 pau->i = i;
1312 pau->j = j;
1313 pau->state = state;
1314 add_PackAln(out,pau);
1315
1316
1317 max_hidden_LargeBlockAligner(mat,startj,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore);
1318
1319
1320 if( i == LargeBlockAligner_READ_OFF_ERROR) {
1321 warn("In LargeBlockAligner hidden read off, between %d:%d,%d:%d - at got bad read off. Problem!",starti,startj,stopi,stopj);
1322 return FALSE;
1323 }
1324
1325
1326 if( i == starti && j == startj && state == startstate) {
1327 /* Put away final state (start of this block) */
1328 pau = PackAlnUnit_alloc(); /* Should deal with memory overflow */
1329 pau->i = i;
1330 pau->j = j;
1331 pau->state = state;
1332 add_PackAln(out,pau);
1333 return TRUE;
1334 }
1335 if( i == starti && j == startj) {
1336 warn("In LargeBlockAligner hidden read off, between %d:%d,%d:%d - hit start cell, but not in start state. Can't be good!.",starti,startj,stopi,stopj);
1337 return FALSE;
1338 }
1339 }
1340 warn("In LargeBlockAligner hidden read off, between %d:%d,%d:%d - gone past start cell (now in %d,%d,%d), can't be good news!.",starti,startj,stopi,stopj,i,j,state);
1341 return FALSE;
1342 }
1343
1344
1345 /* Function: max_hidden_LargeBlockAligner(mat,hiddenj,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore)
1346 *
1347 * Descrip: No Description
1348 *
1349 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1350 * Arg: hiddenj [UNKN ] Undocumented argument [int]
1351 * Arg: i [UNKN ] Undocumented argument [int]
1352 * Arg: j [UNKN ] Undocumented argument [int]
1353 * Arg: state [UNKN ] Undocumented argument [int]
1354 * Arg: isspecial [UNKN ] Undocumented argument [boolean]
1355 * Arg: reti [UNKN ] Undocumented argument [int *]
1356 * Arg: retj [UNKN ] Undocumented argument [int *]
1357 * Arg: retstate [UNKN ] Undocumented argument [int *]
1358 * Arg: retspecial [UNKN ] Undocumented argument [boolean *]
1359 * Arg: cellscore [UNKN ] Undocumented argument [int *]
1360 *
1361 * Return [UNKN ] Undocumented return value [int]
1362 *
1363 */
max_hidden_LargeBlockAligner(LargeBlockAligner * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)1364 int max_hidden_LargeBlockAligner(LargeBlockAligner * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
1365 {
1366 register int temp;
1367 register int cscore;
1368
1369
1370 *reti = (*retj) = (*retstate) = LargeBlockAligner_READ_OFF_ERROR;
1371
1372
1373 if( i < 0 || j < 0 || i > mat->q->seq->len || j > mat->t->seq->len) {
1374 warn("In LargeBlockAligner matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state);
1375 return -1;
1376 }
1377
1378
1379 /* Then you have to select the correct switch statement to figure out the readoff */
1380 /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */
1381 cscore = LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,state);
1382 switch(state) { /*Switch state */
1383 case MATCH :
1384 /* Not allowing special sources.. skipping START */
1385 temp = cscore - (mat->block_open) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
1386 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED) ) {
1387 *reti = i - 1;
1388 *retj = j - 1;
1389 *retstate = UNMATCHED;
1390 *retspecial = FALSE;
1391 if( cellscore != NULL) {
1392 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED);
1393 }
1394 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED);
1395 }
1396 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
1397 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,DELETE) ) {
1398 *reti = i - 1;
1399 *retj = j - 1;
1400 *retstate = DELETE;
1401 *retspecial = FALSE;
1402 if( cellscore != NULL) {
1403 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,DELETE);
1404 }
1405 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,DELETE);
1406 }
1407 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
1408 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,INSERT) ) {
1409 *reti = i - 1;
1410 *retj = j - 1;
1411 *retstate = INSERT;
1412 *retspecial = FALSE;
1413 if( cellscore != NULL) {
1414 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,INSERT);
1415 }
1416 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,INSERT);
1417 }
1418 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
1419 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH) ) {
1420 *reti = i - 1;
1421 *retj = j - 1;
1422 *retstate = MATCH;
1423 *retspecial = FALSE;
1424 if( cellscore != NULL) {
1425 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,MATCH);
1426 }
1427 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH);
1428 }
1429 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1430 return (-1);
1431 case INSERT :
1432 temp = cscore - (mat->gap_ext) - (0);
1433 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,INSERT) ) {
1434 *reti = i - 0;
1435 *retj = j - 1;
1436 *retstate = INSERT;
1437 *retspecial = FALSE;
1438 if( cellscore != NULL) {
1439 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,INSERT);
1440 }
1441 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,INSERT);
1442 }
1443 temp = cscore - (mat->gap_open) - (0);
1444 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH) ) {
1445 *reti = i - 0;
1446 *retj = j - 1;
1447 *retstate = MATCH;
1448 *retspecial = FALSE;
1449 if( cellscore != NULL) {
1450 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,MATCH);
1451 }
1452 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH);
1453 }
1454 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1455 return (-1);
1456 case DELETE :
1457 temp = cscore - (mat->gap_ext) - (0);
1458 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,DELETE) ) {
1459 *reti = i - 1;
1460 *retj = j - 0;
1461 *retstate = DELETE;
1462 *retspecial = FALSE;
1463 if( cellscore != NULL) {
1464 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,DELETE);
1465 }
1466 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,DELETE);
1467 }
1468 temp = cscore - (mat->gap_open) - (0);
1469 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH) ) {
1470 *reti = i - 1;
1471 *retj = j - 0;
1472 *retstate = MATCH;
1473 *retspecial = FALSE;
1474 if( cellscore != NULL) {
1475 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,MATCH);
1476 }
1477 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH);
1478 }
1479 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1480 return (-1);
1481 case UNMATCHED :
1482 temp = cscore - (mat->un_single) - (0);
1483 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,UNMATCHED) ) {
1484 *reti = i - 1;
1485 *retj = j - 0;
1486 *retstate = UNMATCHED;
1487 *retspecial = FALSE;
1488 if( cellscore != NULL) {
1489 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,UNMATCHED);
1490 }
1491 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 0,UNMATCHED);
1492 }
1493 temp = cscore - (mat->un_single) - (0);
1494 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED) ) {
1495 *reti = i - 0;
1496 *retj = j - 1;
1497 *retstate = UNMATCHED;
1498 *retspecial = FALSE;
1499 if( cellscore != NULL) {
1500 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED);
1501 }
1502 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED);
1503 }
1504 temp = cscore - (mat->un_dual) - (0);
1505 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED) ) {
1506 *reti = i - 1;
1507 *retj = j - 1;
1508 *retstate = UNMATCHED;
1509 *retspecial = FALSE;
1510 if( cellscore != NULL) {
1511 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED);
1512 }
1513 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED);
1514 }
1515 /* Not allowing special sources.. skipping START */
1516 temp = cscore - (mat->un_dual) - (0);
1517 if( temp == LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH) ) {
1518 *reti = i - 1;
1519 *retj = j - 1;
1520 *retstate = MATCH;
1521 *retspecial = FALSE;
1522 if( cellscore != NULL) {
1523 *cellscore = cscore - LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,MATCH);
1524 }
1525 return LargeBlockAligner_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH);
1526 }
1527 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1528 return (-1);
1529 default:
1530 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1531 return (-1);
1532 } /* end of Switch state */
1533 }
1534
1535
1536 /* Function: read_special_strip_LargeBlockAligner(mat,stopi,stopj,stopstate,startj,startstate,out)
1537 *
1538 * Descrip: No Description
1539 *
1540 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1541 * Arg: stopi [UNKN ] Undocumented argument [int]
1542 * Arg: stopj [UNKN ] Undocumented argument [int]
1543 * Arg: stopstate [UNKN ] Undocumented argument [int]
1544 * Arg: startj [UNKN ] Undocumented argument [int *]
1545 * Arg: startstate [UNKN ] Undocumented argument [int *]
1546 * Arg: out [UNKN ] Undocumented argument [PackAln *]
1547 *
1548 * Return [UNKN ] Undocumented return value [boolean]
1549 *
1550 */
read_special_strip_LargeBlockAligner(LargeBlockAligner * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out)1551 boolean read_special_strip_LargeBlockAligner(LargeBlockAligner * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out)
1552 {
1553 int i;
1554 int j;
1555 int state;
1556 int cellscore;
1557 int isspecial;
1558 PackAlnUnit * pau;
1559
1560
1561 /* stop position is on the path */
1562 i = stopi;
1563 j = stopj;
1564 state= stopstate;
1565 isspecial = TRUE;
1566
1567
1568 /* Loop until state has the same j as its stop in shadow pointers */
1569 /* This will be the state is came out from, OR it has hit !start */
1570 /* We may not want to get the alignment, in which case out will be NULL */
1571 while( j > LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4) && state != START) { /*while more specials to eat up*/
1572 /* Put away current state, if we should */
1573 if(out != NULL) {
1574 pau = PackAlnUnit_alloc(); /* Should deal with memory overflow */
1575 pau->i = i;
1576 pau->j = j;
1577 pau->state = state + 4;
1578 add_PackAln(out,pau);
1579 }
1580
1581
1582 max_special_strip_LargeBlockAligner(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore);
1583 if( i == LargeBlockAligner_READ_OFF_ERROR) {
1584 warn("In special strip read LargeBlockAligner, got a bad read off error. Sorry!");
1585 return FALSE;
1586 }
1587 } /* end of while more specials to eat up */
1588
1589
1590 /* check to see we have not gone too far! */
1591 if( state != START && j < LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4)) {
1592 warn("In special strip read LargeBlockAligner, at special [%d] state [%d] overshot!",j,state);
1593 return FALSE;
1594 }
1595 /* Put away last state */
1596 if(out != NULL) {
1597 pau = PackAlnUnit_alloc();/* Should deal with memory overflow */
1598 pau->i = i;
1599 pau->j = j;
1600 pau->state = state + 4;
1601 add_PackAln(out,pau);
1602 }
1603
1604
1605 /* Put away where we are in startj and startstate */
1606 *startj = j;
1607 *startstate = state;
1608 return TRUE;
1609 }
1610
1611
1612 /* Function: max_special_strip_LargeBlockAligner(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore)
1613 *
1614 * Descrip: A pretty intense internal function. Deals with read-off only in specials
1615 *
1616 *
1617 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1618 * Arg: i [UNKN ] Undocumented argument [int]
1619 * Arg: j [UNKN ] Undocumented argument [int]
1620 * Arg: state [UNKN ] Undocumented argument [int]
1621 * Arg: isspecial [UNKN ] Undocumented argument [boolean]
1622 * Arg: reti [UNKN ] Undocumented argument [int *]
1623 * Arg: retj [UNKN ] Undocumented argument [int *]
1624 * Arg: retstate [UNKN ] Undocumented argument [int *]
1625 * Arg: retspecial [UNKN ] Undocumented argument [boolean *]
1626 * Arg: cellscore [UNKN ] Undocumented argument [int *]
1627 *
1628 * Return [UNKN ] Undocumented return value [int]
1629 *
1630 */
max_special_strip_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)1631 int max_special_strip_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
1632 {
1633 int temp;
1634 int cscore;
1635
1636
1637 *reti = (*retj) = (*retstate) = LargeBlockAligner_READ_OFF_ERROR;
1638 if( isspecial == FALSE ) {
1639 warn("In special strip max function for LargeBlockAligner, got a non special start point. Problem! (bad!)");
1640 return (-1);
1641 }
1642
1643
1644 if( j < 0 || j > mat->t->seq->len) {
1645 warn("In LargeBlockAligner matrix special read off - out of bounds on matrix [j is %d in special]",j);
1646 return -1;
1647 }
1648
1649
1650 cscore = LargeBlockAligner_DC_SHADOW_SPECIAL(mat,i,j,state);
1651 switch(state) { /*switch on special states*/
1652 case START :
1653 case END :
1654 /* Source UNMATCHED is not a special */
1655 /* Source MATCH is not a special */
1656 default:
1657 warn("Major problem (!) - in LargeBlockAligner special strip read off, position %d,%d state %d no source found dropped into default on source switch!",i,j,state);
1658 return (-1);
1659 } /* end of switch on special states */
1660 }
1661
1662
1663 /* Function: max_matrix_to_special_LargeBlockAligner(mat,i,j,state,cscore,reti,retj,retstate,retspecial,cellscore)
1664 *
1665 * Descrip: No Description
1666 *
1667 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1668 * Arg: i [UNKN ] Undocumented argument [int]
1669 * Arg: j [UNKN ] Undocumented argument [int]
1670 * Arg: state [UNKN ] Undocumented argument [int]
1671 * Arg: cscore [UNKN ] Undocumented argument [int]
1672 * Arg: reti [UNKN ] Undocumented argument [int *]
1673 * Arg: retj [UNKN ] Undocumented argument [int *]
1674 * Arg: retstate [UNKN ] Undocumented argument [int *]
1675 * Arg: retspecial [UNKN ] Undocumented argument [boolean *]
1676 * Arg: cellscore [UNKN ] Undocumented argument [int *]
1677 *
1678 * Return [UNKN ] Undocumented return value [int]
1679 *
1680 */
max_matrix_to_special_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)1681 int max_matrix_to_special_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
1682 {
1683 int temp;
1684 *reti = (*retj) = (*retstate) = LargeBlockAligner_READ_OFF_ERROR;
1685
1686
1687 if( j < 0 || j > mat->lenj) {
1688 warn("In LargeBlockAligner matrix to special read off - out of bounds on matrix [j is %d in special]",j);
1689 return -1;
1690 }
1691
1692
1693 switch(state) { /*Switch state */
1694 case MATCH :
1695 temp = cscore - (mat->block_open) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
1696 if( temp == LargeBlockAligner_DC_SHADOW_SPECIAL(mat,i - 1,j - 1,START) ) {
1697 *reti = i - 1;
1698 *retj = j - 1;
1699 *retstate = START;
1700 *retspecial = TRUE;
1701 if( cellscore != NULL) {
1702 *cellscore = cscore - LargeBlockAligner_DC_SHADOW_SPECIAL(mat,i-1,j-1,START);
1703 }
1704 return LargeBlockAligner_DC_SHADOW_MATRIX(mat,i - 1,j - 1,START) ;
1705 }
1706 /* Source UNMATCHED is not a special, should not get here! */
1707 /* Source DELETE is not a special, should not get here! */
1708 /* Source INSERT is not a special, should not get here! */
1709 /* Source MATCH is not a special, should not get here! */
1710 warn("Major problem (!) - in LargeBlockAligner matrix to special read off, position %d,%d state %d no source found!",i,j,state);
1711 return (-1);
1712 case INSERT :
1713 /* Source INSERT is not a special, should not get here! */
1714 /* Source MATCH is not a special, should not get here! */
1715 warn("Major problem (!) - in LargeBlockAligner matrix to special read off, position %d,%d state %d no source found!",i,j,state);
1716 return (-1);
1717 case DELETE :
1718 /* Source DELETE is not a special, should not get here! */
1719 /* Source MATCH is not a special, should not get here! */
1720 warn("Major problem (!) - in LargeBlockAligner matrix to special read off, position %d,%d state %d no source found!",i,j,state);
1721 return (-1);
1722 case UNMATCHED :
1723 /* Source UNMATCHED is not a special, should not get here! */
1724 /* Source UNMATCHED is not a special, should not get here! */
1725 /* Source UNMATCHED is not a special, should not get here! */
1726 temp = cscore - (mat->un_dual) - (0);
1727 if( temp == LargeBlockAligner_DC_SHADOW_SPECIAL(mat,i - 1,j - 1,START) ) {
1728 *reti = i - 1;
1729 *retj = j - 1;
1730 *retstate = START;
1731 *retspecial = TRUE;
1732 if( cellscore != NULL) {
1733 *cellscore = cscore - LargeBlockAligner_DC_SHADOW_SPECIAL(mat,i-1,j-1,START);
1734 }
1735 return LargeBlockAligner_DC_SHADOW_MATRIX(mat,i - 1,j - 1,START) ;
1736 }
1737 /* Source MATCH is not a special, should not get here! */
1738 warn("Major problem (!) - in LargeBlockAligner matrix to special read off, position %d,%d state %d no source found!",i,j,state);
1739 return (-1);
1740 default:
1741 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
1742 return (-1);
1743 } /* end of Switch state */
1744
1745
1746 }
1747
1748
1749 /* Function: calculate_hidden_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv)
1750 *
1751 * Descrip: No Description
1752 *
1753 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1754 * Arg: starti [UNKN ] Undocumented argument [int]
1755 * Arg: startj [UNKN ] Undocumented argument [int]
1756 * Arg: startstate [UNKN ] Undocumented argument [int]
1757 * Arg: stopi [UNKN ] Undocumented argument [int]
1758 * Arg: stopj [UNKN ] Undocumented argument [int]
1759 * Arg: stopstate [UNKN ] Undocumented argument [int]
1760 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
1761 *
1762 */
calculate_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv)1763 void calculate_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv)
1764 {
1765 register int i;
1766 register int j;
1767 register int score;
1768 register int temp;
1769 register int hiddenj;
1770
1771
1772 hiddenj = startj;
1773
1774
1775 init_hidden_LargeBlockAligner(mat,starti,startj,stopi,stopj);
1776
1777
1778 LargeBlockAligner_HIDDEN_MATRIX(mat,starti,startj,startstate) = 0;
1779
1780
1781 for(j=startj;j<=stopj;j++) {
1782 for(i=starti;i<=stopi;i++) {
1783 /* Should *not* do very first cell as this is the one set to zero in one state! */
1784 if( i == starti && j == startj )
1785 continue;
1786 if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { /*Is not in envelope*/
1787 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,MATCH) = NEGI;
1788 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,INSERT) = NEGI;
1789 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,DELETE) = NEGI;
1790 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,UNMATCHED) = NEGI;
1791 continue;
1792 } /* end of Is not in envelope */
1793
1794
1795 /* For state MATCH */
1796 /* setting first movement to score */
1797 score = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,MATCH) + 0;
1798 /* From state INSERT to state MATCH */
1799 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,INSERT) + 0;
1800 if( temp > score ) {
1801 score = temp;
1802 }
1803 /* From state DELETE to state MATCH */
1804 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,DELETE) + 0;
1805 if( temp > score ) {
1806 score = temp;
1807 }
1808 /* From state UNMATCHED to state MATCH */
1809 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
1810 if( temp > score ) {
1811 score = temp;
1812 }
1813
1814
1815 /* Ok - finished max calculation for MATCH */
1816 /* Add any movement independant score and put away */
1817 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
1818 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,MATCH) = score;
1819 /* Finished calculating state MATCH */
1820
1821
1822 /* For state INSERT */
1823 /* setting first movement to score */
1824 score = LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
1825 /* From state INSERT to state INSERT */
1826 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
1827 if( temp > score ) {
1828 score = temp;
1829 }
1830
1831
1832 /* Ok - finished max calculation for INSERT */
1833 /* Add any movement independant score and put away */
1834 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,INSERT) = score;
1835 /* Finished calculating state INSERT */
1836
1837
1838 /* For state DELETE */
1839 /* setting first movement to score */
1840 score = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
1841 /* From state DELETE to state DELETE */
1842 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
1843 if( temp > score ) {
1844 score = temp;
1845 }
1846
1847
1848 /* Ok - finished max calculation for DELETE */
1849 /* Add any movement independant score and put away */
1850 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,DELETE) = score;
1851 /* Finished calculating state DELETE */
1852
1853
1854 /* For state UNMATCHED */
1855 /* setting first movement to score */
1856 score = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
1857 /* From state UNMATCHED to state UNMATCHED */
1858 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
1859 if( temp > score ) {
1860 score = temp;
1861 }
1862 /* From state UNMATCHED to state UNMATCHED */
1863 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
1864 if( temp > score ) {
1865 score = temp;
1866 }
1867 /* From state UNMATCHED to state UNMATCHED */
1868 temp = LargeBlockAligner_HIDDEN_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
1869 if( temp > score ) {
1870 score = temp;
1871 }
1872
1873
1874 /* Ok - finished max calculation for UNMATCHED */
1875 /* Add any movement independant score and put away */
1876 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,UNMATCHED) = score;
1877 /* Finished calculating state UNMATCHED */
1878 }
1879 }
1880
1881
1882 return;
1883 }
1884
1885
1886 /* Function: init_hidden_LargeBlockAligner(mat,starti,startj,stopi,stopj)
1887 *
1888 * Descrip: No Description
1889 *
1890 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
1891 * Arg: starti [UNKN ] Undocumented argument [int]
1892 * Arg: startj [UNKN ] Undocumented argument [int]
1893 * Arg: stopi [UNKN ] Undocumented argument [int]
1894 * Arg: stopj [UNKN ] Undocumented argument [int]
1895 *
1896 */
init_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int stopi,int stopj)1897 void init_hidden_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int stopi,int stopj)
1898 {
1899 register int i;
1900 register int j;
1901 register int hiddenj;
1902
1903
1904 hiddenj = startj;
1905 for(j=(startj-1);j<=stopj;j++) {
1906 for(i=(starti-1);i<=stopi;i++) {
1907 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,MATCH) = NEGI;
1908
1909 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,INSERT) = NEGI;
1910
1911 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,DELETE) = NEGI;
1912
1913 LargeBlockAligner_HIDDEN_MATRIX(mat,i,j,UNMATCHED) = NEGI;
1914
1915 }
1916 }
1917
1918
1919 return;
1920 }
1921
1922
1923 /* Function: full_dc_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,out,donej,totalj,dpenv)
1924 *
1925 * Descrip: The main divide-and-conquor routine. Basically, call /PackAln_calculate_small_LargeBlockAligner
1926 * Not this function, which is pretty hard core.
1927 * Function is given start/end points (in main matrix) for alignment
1928 * It does some checks, decides whether start/end in j is small enough for explicit calc
1929 * - if yes, calculates it, reads off into PackAln (out), adds the j distance to donej and returns TRUE
1930 * - if no, uses /do_dc_single_pass_LargeBlockAligner to get mid-point
1931 * saves midpoint, and calls itself to do right portion then left portion
1932 * right then left ensures PackAln is added the 'right' way, ie, back-to-front
1933 * returns FALSE on any error, with a warning
1934 *
1935 *
1936 * Arg: mat [UNKN ] Matrix with small memory implementation [LargeBlockAligner *]
1937 * Arg: starti [UNKN ] Start position in i [int]
1938 * Arg: startj [UNKN ] Start position in j [int]
1939 * Arg: startstate [UNKN ] Start position state number [int]
1940 * Arg: stopi [UNKN ] Stop position in i [int]
1941 * Arg: stopj [UNKN ] Stop position in j [int]
1942 * Arg: stopstate [UNKN ] Stop position state number [int]
1943 * Arg: out [UNKN ] PackAln structure to put alignment into [PackAln *]
1944 * Arg: donej [UNKN ] pointer to a number with the amount of alignment done [int *]
1945 * Arg: totalj [UNKN ] total amount of alignment to do (in j coordinates) [int]
1946 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
1947 *
1948 * Return [UNKN ] Undocumented return value [boolean]
1949 *
1950 */
full_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv)1951 boolean full_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv)
1952 {
1953 int lstarti;
1954 int lstartj;
1955 int lstate;
1956
1957
1958 if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
1959 warn("*Very* bad error! - non shadow matrix type in full_dc_LargeBlockAligner");
1960 return FALSE;
1961 }
1962
1963
1964 if( starti == -1 || startj == -1 || startstate == -1 || stopi == -1 || stopstate == -1) {
1965 warn("In full dc program, passed bad indices, indices passed were %d:%d[%d] to %d:%d[%d]\n",starti,startj,startstate,stopi,stopj,stopstate);
1966 return FALSE;
1967 }
1968
1969
1970 if( stopj - startj < 5) {
1971 log_full_error(REPORT,0,"[%d,%d][%d,%d] Explicit read off",starti,startj,stopi,stopj);/* Build hidden explicit matrix */
1972 calculate_hidden_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv);
1973 *donej += (stopj - startj); /* Now read it off into out */
1974 if( read_hidden_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,out) == FALSE) {
1975 warn("In full dc, at %d:%d,%d:%d got a bad hidden explicit read off... ",starti,startj,stopi,stopj);
1976 return FALSE;
1977 }
1978 return TRUE;
1979 }
1980
1981
1982 /* In actual divide and conquor */
1983 if( do_dc_single_pass_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,(int)(*donej*100)/totalj) == FALSE) {
1984 warn("In divide and conquor for LargeBlockAligner, at bound %d:%d to %d:%d, unable to calculate midpoint. Problem!",starti,startj,stopi,stopj);
1985 return FALSE;
1986 }
1987
1988
1989 /* Ok... now we have to call on each side of the matrix */
1990 /* We have to retrieve left hand side positions, as they will be vapped by the time we call LHS */
1991 lstarti= LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,0);
1992 lstartj= LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,1);
1993 lstate = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,2);
1994
1995
1996 /* Call on right hand side: this lets us do the correct read off */
1997 if( full_dc_LargeBlockAligner(mat,LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,3),LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,4),LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,5),stopi,stopj,stopstate,out,donej,totalj,dpenv) == FALSE) {
1998 /* Warning already issued, simply chained back up to top */
1999 return FALSE;
2000 }
2001 /* Call on left hand side */
2002 if( full_dc_LargeBlockAligner(mat,starti,startj,startstate,lstarti,lstartj,lstate,out,donej,totalj,dpenv) == FALSE) {
2003 /* Warning already issued, simply chained back up to top */
2004 return FALSE;
2005 }
2006
2007
2008 return TRUE;
2009 }
2010
2011
2012 /* Function: do_dc_single_pass_LargeBlockAligner(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,perc_done)
2013 *
2014 * Descrip: No Description
2015 *
2016 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2017 * Arg: starti [UNKN ] Undocumented argument [int]
2018 * Arg: startj [UNKN ] Undocumented argument [int]
2019 * Arg: startstate [UNKN ] Undocumented argument [int]
2020 * Arg: stopi [UNKN ] Undocumented argument [int]
2021 * Arg: stopj [UNKN ] Undocumented argument [int]
2022 * Arg: stopstate [UNKN ] Undocumented argument [int]
2023 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2024 * Arg: perc_done [UNKN ] Undocumented argument [int]
2025 *
2026 * Return [UNKN ] Undocumented return value [boolean]
2027 *
2028 */
do_dc_single_pass_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done)2029 boolean do_dc_single_pass_LargeBlockAligner(LargeBlockAligner * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done)
2030 {
2031 int halfj;
2032 halfj = startj + ((stopj - startj)/2);
2033
2034
2035 init_dc_LargeBlockAligner(mat);
2036
2037
2038 LargeBlockAligner_DC_SHADOW_MATRIX(mat,starti,startj,startstate) = 0;
2039 run_up_dc_LargeBlockAligner(mat,starti,stopi,startj,halfj-1,dpenv,perc_done);
2040 push_dc_at_merge_LargeBlockAligner(mat,starti,stopi,halfj,&halfj,dpenv);
2041 follow_on_dc_LargeBlockAligner(mat,starti,stopi,halfj,stopj,dpenv,perc_done);
2042 return TRUE;
2043 }
2044
2045
2046 /* Function: push_dc_at_merge_LargeBlockAligner(mat,starti,stopi,startj,stopj,dpenv)
2047 *
2048 * Descrip: No Description
2049 *
2050 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2051 * Arg: starti [UNKN ] Undocumented argument [int]
2052 * Arg: stopi [UNKN ] Undocumented argument [int]
2053 * Arg: startj [UNKN ] Undocumented argument [int]
2054 * Arg: stopj [UNKN ] Undocumented argument [int *]
2055 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2056 *
2057 */
push_dc_at_merge_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv)2058 void push_dc_at_merge_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv)
2059 {
2060 register int i;
2061 register int j;
2062 register int k;
2063 register int count;
2064 register int mergej;/* Sources below this j will be stamped by triples */
2065 register int score;
2066 register int temp;
2067
2068
2069 mergej = startj -1;
2070 for(count=0,j=startj;count<1;count++,j++) {
2071 for(i=starti;i<=stopi;i++) {
2072 if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { /*Is not in envelope*/
2073 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2074 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = (-100);
2075 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = (-100);
2076 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2077 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = (-100);
2078 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = (-100);
2079 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2080 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = (-100);
2081 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = (-100);
2082 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2083 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = (-100);
2084 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,1) = (-100);
2085 continue;
2086 } /* end of Is not in envelope */
2087
2088
2089 /* For state MATCH, pushing when j - offj <= mergej */
2090 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0;
2091 if( j - 1 <= mergej) {
2092 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1;
2093 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1;
2094 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = MATCH;
2095 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i;
2096 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j;
2097 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH;
2098 }
2099 else {
2100 for(k=0;k<7;k++)
2101 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k);
2102 }
2103
2104
2105 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0;
2106 if( temp > score) {
2107 score = temp;
2108
2109
2110 if( j - 1 <= mergej) {
2111 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1;
2112 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1;
2113 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = INSERT;
2114 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i;
2115 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j;
2116 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH;
2117 }
2118 else {
2119 for(k=0;k<7;k++)
2120 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,k);
2121 }
2122 }
2123
2124
2125 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0;
2126 if( temp > score) {
2127 score = temp;
2128
2129
2130 if( j - 1 <= mergej) {
2131 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1;
2132 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1;
2133 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = DELETE;
2134 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i;
2135 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j;
2136 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH;
2137 }
2138 else {
2139 for(k=0;k<7;k++)
2140 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,k);
2141 }
2142 }
2143
2144
2145 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
2146 if( temp > score) {
2147 score = temp;
2148
2149
2150 if( j - 1 <= mergej) {
2151 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = i-1;
2152 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,1) = j-1;
2153 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,2) = UNMATCHED;
2154 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,3) = i;
2155 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,4) = j;
2156 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,5) = MATCH;
2157 }
2158 else {
2159 for(k=0;k<7;k++)
2160 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,k);
2161 }
2162 }
2163 /* Add any movement independant score */
2164 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
2165 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score;
2166 /* Finished with state MATCH */
2167
2168
2169 /* For state INSERT, pushing when j - offj <= mergej */
2170 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
2171 if( j - 1 <= mergej) {
2172 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = i-0;
2173 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = j-1;
2174 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,2) = MATCH;
2175 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,3) = i;
2176 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,4) = j;
2177 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,5) = INSERT;
2178 }
2179 else {
2180 for(k=0;k<7;k++)
2181 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,k);
2182 }
2183
2184
2185 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
2186 if( temp > score) {
2187 score = temp;
2188
2189
2190 if( j - 1 <= mergej) {
2191 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = i-0;
2192 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,1) = j-1;
2193 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,2) = INSERT;
2194 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,3) = i;
2195 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,4) = j;
2196 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,5) = INSERT;
2197 }
2198 else {
2199 for(k=0;k<7;k++)
2200 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,k);
2201 }
2202 }
2203 /* Add any movement independant score */
2204 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score;
2205 /* Finished with state INSERT */
2206
2207
2208 /* For state DELETE, pushing when j - offj <= mergej */
2209 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
2210 if( j - 0 <= mergej) {
2211 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = i-1;
2212 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = j-0;
2213 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,2) = MATCH;
2214 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,3) = i;
2215 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,4) = j;
2216 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,5) = DELETE;
2217 }
2218 else {
2219 for(k=0;k<7;k++)
2220 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,k);
2221 }
2222
2223
2224 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
2225 if( temp > score) {
2226 score = temp;
2227
2228
2229 if( j - 0 <= mergej) {
2230 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = i-1;
2231 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,1) = j-0;
2232 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,2) = DELETE;
2233 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,3) = i;
2234 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,4) = j;
2235 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,5) = DELETE;
2236 }
2237 else {
2238 for(k=0;k<7;k++)
2239 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,k);
2240 }
2241 }
2242 /* Add any movement independant score */
2243 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score;
2244 /* Finished with state DELETE */
2245
2246
2247 /* For state UNMATCHED, pushing when j - offj <= mergej */
2248 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
2249 if( j - 1 <= mergej) {
2250 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = i-1;
2251 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,1) = j-1;
2252 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,2) = MATCH;
2253 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,3) = i;
2254 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,4) = j;
2255 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,5) = UNMATCHED;
2256 }
2257 else {
2258 for(k=0;k<7;k++)
2259 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k);
2260 }
2261
2262
2263 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
2264 if( temp > score) {
2265 score = temp;
2266
2267
2268 if( j - 1 <= mergej) {
2269 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = i-1;
2270 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,1) = j-1;
2271 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,2) = UNMATCHED;
2272 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,3) = i;
2273 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,4) = j;
2274 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,5) = UNMATCHED;
2275 }
2276 else {
2277 for(k=0;k<7;k++)
2278 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,k);
2279 }
2280 }
2281
2282
2283 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
2284 if( temp > score) {
2285 score = temp;
2286
2287
2288 if( j - 1 <= mergej) {
2289 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = i-0;
2290 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,1) = j-1;
2291 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,2) = UNMATCHED;
2292 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,3) = i;
2293 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,4) = j;
2294 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,5) = UNMATCHED;
2295 }
2296 else {
2297 for(k=0;k<7;k++)
2298 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED,k);
2299 }
2300 }
2301
2302
2303 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
2304 if( temp > score) {
2305 score = temp;
2306
2307
2308 if( j - 0 <= mergej) {
2309 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = i-1;
2310 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,1) = j-0;
2311 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,2) = UNMATCHED;
2312 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,3) = i;
2313 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,4) = j;
2314 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,5) = UNMATCHED;
2315 }
2316 else {
2317 for(k=0;k<7;k++)
2318 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED,k);
2319 }
2320 }
2321 /* Add any movement independant score */
2322 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = score;
2323 /* Finished with state UNMATCHED */
2324 }
2325 }
2326 /* Put back j into * stop j so that calling function gets it correct */
2327 if( stopj == NULL)
2328 warn("Bad news... NULL stopj pointer in push dc function. This means that calling function does not know how many cells I have done!");
2329 else
2330 *stopj = j;
2331
2332
2333 return;
2334 }
2335
2336
2337 /* Function: follow_on_dc_LargeBlockAligner(mat,starti,stopi,startj,stopj,dpenv,perc_done)
2338 *
2339 * Descrip: No Description
2340 *
2341 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2342 * Arg: starti [UNKN ] Undocumented argument [int]
2343 * Arg: stopi [UNKN ] Undocumented argument [int]
2344 * Arg: startj [UNKN ] Undocumented argument [int]
2345 * Arg: stopj [UNKN ] Undocumented argument [int]
2346 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2347 * Arg: perc_done [UNKN ] Undocumented argument [int]
2348 *
2349 */
follow_on_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)2350 void follow_on_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)
2351 {
2352 int i;
2353 int j;
2354 int k;
2355 int score;
2356 int temp;
2357 int localshadow[7];
2358 long int total;
2359 long int num;
2360
2361
2362 total = (stopi - starti+1) * (stopj - startj+1);
2363 num = 0;
2364
2365
2366 for(j=startj;j<=stopj;j++) { /*for each valid j column*/
2367 for(i=starti;i<=stopi;i++) { /*this is strip*/
2368 num++;
2369 if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { /*Is not in envelope*/
2370 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2371 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2372 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2373 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2374 continue;
2375 } /* end of Is not in envelope */
2376 if( num % 1000 == 0 )
2377 log_full_error(REPORT,0,"[%d%%%% done]After mid-j %5d Cells done %d%%%%",perc_done,startj,(num*100)/total);
2378
2379
2380 /* For state MATCH */
2381 /* setting first movement to score */
2382 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0;
2383 /* shift first shadow numbers */
2384 for(k=0;k<7;k++)
2385 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k);
2386 /* From state INSERT to state MATCH */
2387 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0;
2388 if( temp > score ) {
2389 score = temp;
2390 for(k=0;k<7;k++)
2391 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,k);
2392 }
2393 /* From state DELETE to state MATCH */
2394 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0;
2395 if( temp > score ) {
2396 score = temp;
2397 for(k=0;k<7;k++)
2398 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,k);
2399 }
2400 /* From state UNMATCHED to state MATCH */
2401 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
2402 if( temp > score ) {
2403 score = temp;
2404 for(k=0;k<7;k++)
2405 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,k);
2406 }
2407
2408
2409 /* Ok - finished max calculation for MATCH */
2410 /* Add any movement independant score and put away */
2411 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
2412 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score;
2413 for(k=0;k<7;k++)
2414 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = localshadow[k];
2415 /* Now figure out if any specials need this score */
2416 /* Finished calculating state MATCH */
2417
2418
2419 /* For state INSERT */
2420 /* setting first movement to score */
2421 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
2422 /* shift first shadow numbers */
2423 for(k=0;k<7;k++)
2424 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,k);
2425 /* From state INSERT to state INSERT */
2426 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
2427 if( temp > score ) {
2428 score = temp;
2429 for(k=0;k<7;k++)
2430 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,k);
2431 }
2432
2433
2434 /* Ok - finished max calculation for INSERT */
2435 /* Add any movement independant score and put away */
2436 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score;
2437 for(k=0;k<7;k++)
2438 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = localshadow[k];
2439 /* Now figure out if any specials need this score */
2440 /* Finished calculating state INSERT */
2441
2442
2443 /* For state DELETE */
2444 /* setting first movement to score */
2445 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
2446 /* shift first shadow numbers */
2447 for(k=0;k<7;k++)
2448 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,k);
2449 /* From state DELETE to state DELETE */
2450 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
2451 if( temp > score ) {
2452 score = temp;
2453 for(k=0;k<7;k++)
2454 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,k);
2455 }
2456
2457
2458 /* Ok - finished max calculation for DELETE */
2459 /* Add any movement independant score and put away */
2460 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score;
2461 for(k=0;k<7;k++)
2462 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = localshadow[k];
2463 /* Now figure out if any specials need this score */
2464 /* Finished calculating state DELETE */
2465
2466
2467 /* For state UNMATCHED */
2468 /* setting first movement to score */
2469 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
2470 /* shift first shadow numbers */
2471 for(k=0;k<7;k++)
2472 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,k);
2473 /* From state UNMATCHED to state UNMATCHED */
2474 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
2475 if( temp > score ) {
2476 score = temp;
2477 for(k=0;k<7;k++)
2478 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,k);
2479 }
2480 /* From state UNMATCHED to state UNMATCHED */
2481 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
2482 if( temp > score ) {
2483 score = temp;
2484 for(k=0;k<7;k++)
2485 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED,k);
2486 }
2487 /* From state UNMATCHED to state UNMATCHED */
2488 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
2489 if( temp > score ) {
2490 score = temp;
2491 for(k=0;k<7;k++)
2492 localshadow[k] = LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED,k);
2493 }
2494
2495
2496 /* Ok - finished max calculation for UNMATCHED */
2497 /* Add any movement independant score and put away */
2498 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = score;
2499 for(k=0;k<7;k++)
2500 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = localshadow[k];
2501 /* Now figure out if any specials need this score */
2502 /* Finished calculating state UNMATCHED */
2503 } /* end of this is strip */
2504 } /* end of for each valid j column */
2505
2506
2507 /* Function: run_up_dc_LargeBlockAligner(mat,starti,stopi,startj,stopj,dpenv,perc_done)
2508 *
2509 * Descrip: No Description
2510 *
2511 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2512 * Arg: starti [UNKN ] Undocumented argument [int]
2513 * Arg: stopi [UNKN ] Undocumented argument [int]
2514 * Arg: startj [UNKN ] Undocumented argument [int]
2515 * Arg: stopj [UNKN ] Undocumented argument [int]
2516 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2517 * Arg: perc_done [UNKN ] Undocumented argument [int]
2518 *
2519 */
2520 }
run_up_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)2521 void run_up_dc_LargeBlockAligner(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)
2522 {
2523 register int i;
2524 register int j;
2525 register int score;
2526 register int temp;
2527 long int total;
2528 long int num;
2529
2530
2531 total = (stopi - starti+1) * (stopj - startj+1);
2532 if( total <= 0 )
2533 total = 1;
2534 num = 0;
2535
2536
2537 for(j=startj;j<=stopj;j++) { /*for each valid j column*/
2538 for(i=starti;i<=stopi;i++) { /*this is strip*/
2539 if( j == startj && i == starti)
2540 continue;
2541 num++;
2542 if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { /*Is not in envelope*/
2543 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2544 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2545 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2546 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2547 continue;
2548 } /* end of Is not in envelope */
2549 if( num % 1000 == 0 )
2550 log_full_error(REPORT,0,"[%d%%%% done]Before mid-j %5d Cells done %d%%%%",perc_done,stopj,(num*100)/total);
2551
2552
2553 /* For state MATCH */
2554 /* setting first movement to score */
2555 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0;
2556 /* From state INSERT to state MATCH */
2557 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0;
2558 if( temp > score ) {
2559 score = temp;
2560 }
2561 /* From state DELETE to state MATCH */
2562 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0;
2563 if( temp > score ) {
2564 score = temp;
2565 }
2566 /* From state UNMATCHED to state MATCH */
2567 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
2568 if( temp > score ) {
2569 score = temp;
2570 }
2571
2572
2573 /* Ok - finished max calculation for MATCH */
2574 /* Add any movement independant score and put away */
2575 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
2576 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = score;
2577 /* Finished calculating state MATCH */
2578
2579
2580 /* For state INSERT */
2581 /* setting first movement to score */
2582 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
2583 /* From state INSERT to state INSERT */
2584 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
2585 if( temp > score ) {
2586 score = temp;
2587 }
2588
2589
2590 /* Ok - finished max calculation for INSERT */
2591 /* Add any movement independant score and put away */
2592 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = score;
2593 /* Finished calculating state INSERT */
2594
2595
2596 /* For state DELETE */
2597 /* setting first movement to score */
2598 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
2599 /* From state DELETE to state DELETE */
2600 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
2601 if( temp > score ) {
2602 score = temp;
2603 }
2604
2605
2606 /* Ok - finished max calculation for DELETE */
2607 /* Add any movement independant score and put away */
2608 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = score;
2609 /* Finished calculating state DELETE */
2610
2611
2612 /* For state UNMATCHED */
2613 /* setting first movement to score */
2614 score = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
2615 /* From state UNMATCHED to state UNMATCHED */
2616 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
2617 if( temp > score ) {
2618 score = temp;
2619 }
2620 /* From state UNMATCHED to state UNMATCHED */
2621 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
2622 if( temp > score ) {
2623 score = temp;
2624 }
2625 /* From state UNMATCHED to state UNMATCHED */
2626 temp = LargeBlockAligner_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
2627 if( temp > score ) {
2628 score = temp;
2629 }
2630
2631
2632 /* Ok - finished max calculation for UNMATCHED */
2633 /* Add any movement independant score and put away */
2634 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = score;
2635 /* Finished calculating state UNMATCHED */
2636 } /* end of this is strip */
2637 } /* end of for each valid j column */
2638
2639
2640 /* Function: init_dc_LargeBlockAligner(mat)
2641 *
2642 * Descrip: No Description
2643 *
2644 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2645 *
2646 */
2647 }
init_dc_LargeBlockAligner(LargeBlockAligner * mat)2648 void init_dc_LargeBlockAligner(LargeBlockAligner * mat)
2649 {
2650 register int i;
2651 register int j;
2652 register int k;
2653
2654
2655 for(j=0;j<3;j++) {
2656 for(i=(-1);i<mat->q->seq->len;i++) {
2657 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2658 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2659 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2660 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2661 for(k=0;k<7;k++) {
2662 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = (-1);
2663 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = (-1);
2664 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = (-1);
2665 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = (-1);
2666 }
2667 }
2668 }
2669
2670
2671 return;
2672 }
2673
2674
2675 /* Function: start_end_find_end_LargeBlockAligner(mat,endj)
2676 *
2677 * Descrip: First function used to find end of the best path in the special state !end
2678 *
2679 *
2680 * Arg: mat [UNKN ] Matrix in small mode [LargeBlockAligner *]
2681 * Arg: endj [WRITE] position of end in j (meaningless in i) [int *]
2682 *
2683 * Return [UNKN ] Undocumented return value [int]
2684 *
2685 */
start_end_find_end_LargeBlockAligner(LargeBlockAligner * mat,int * endj)2686 int start_end_find_end_LargeBlockAligner(LargeBlockAligner * mat,int * endj)
2687 {
2688 register int j;
2689 register int max;
2690 register int maxj;
2691
2692
2693 max = LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,mat->t->seq->len-1,END);
2694 maxj = mat->t->seq->len-1;
2695 for(j= mat->t->seq->len-2 ;j >= 0 ;j--) {
2696 if( LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,j,END) > max ) {
2697 max = LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,j,END);
2698 maxj = j;
2699 }
2700 }
2701
2702
2703 if( endj != NULL)
2704 *endj = maxj;
2705
2706
2707 return max;
2708 }
2709
2710
2711 /* Function: dc_optimised_start_end_calc_LargeBlockAligner(*mat,dpenv)
2712 *
2713 * Descrip: Calculates special strip, leaving start/end/score points in shadow matrix
2714 * Works off specially laid out memory from steve searle
2715 *
2716 *
2717 * Arg: *mat [UNKN ] Undocumented argument [LargeBlockAligner]
2718 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2719 *
2720 * Return [UNKN ] Undocumented return value [boolean]
2721 *
2722 */
dc_optimised_start_end_calc_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)2723 boolean dc_optimised_start_end_calc_LargeBlockAligner(LargeBlockAligner *mat,DPEnvelope * dpenv)
2724 {
2725 int i;
2726 int j;
2727 int k;
2728 int score;
2729 int temp;
2730 int leni;
2731 int lenj;
2732 int localshadow[7];
2733 long int total;
2734 long int num=0;
2735 int * score_pointers;
2736 int * shadow_pointers;
2737 int * localsp;
2738 leni = mat->q->seq->len;
2739 lenj = mat->t->seq->len;
2740 total = leni * lenj;
2741
2742
2743 score_pointers = (int *) calloc (1 * (leni + 1) * 4,sizeof(int));
2744 shadow_pointers = (int *) calloc (1 * (leni + 1) * 4 * 8,sizeof(int));
2745
2746
2747 for(j=0;j<lenj;j++) { /*for each j strip*/
2748 for(i=0;i<leni;i++) { /*for each i position in strip*/
2749 num++;
2750 if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE ) { /*Is not in envelope*/
2751 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2752 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2753 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2754 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2755 continue;
2756 } /* end of Is not in envelope */
2757 if( num%1000 == 0)
2758 log_full_error(REPORT,0,"%6d Cells done [%2d%%%%]",num,num*100/total);
2759
2760
2761
2762
2763 /* For state MATCH */
2764 /* setting first movement to score */
2765 score = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + 0 + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
2766 /* assign local shadown pointer */
2767 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,0));
2768 /* From state INSERT to state MATCH */
2769 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,INSERT) + 0 +((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
2770 if( temp > score ) {
2771 score = temp;
2772 /* assign local shadown pointer */
2773 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,INSERT,0));
2774 }
2775 /* From state DELETE to state MATCH */
2776 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,DELETE) + 0 +((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
2777 if( temp > score ) {
2778 score = temp;
2779 /* assign local shadown pointer */
2780 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,DELETE,0));
2781 }
2782 /* From state UNMATCHED to state MATCH */
2783 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open +((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
2784 if( temp > score ) {
2785 score = temp;
2786 /* assign local shadown pointer */
2787 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,0));
2788 }
2789 /* From state START to state MATCH */
2790 temp = LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i-1,j-1,START) + mat->block_open + ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
2791 if( temp > score ) {
2792 score = temp;
2793 /* This state [START] is a special for MATCH... push top shadow pointers here */
2794 localshadow[0]= i;
2795 localshadow[1]= j;
2796 localshadow[2]= MATCH;
2797 localshadow[3]= (-1);
2798 localshadow[4]= (-1);
2799 localshadow[5]= (-1);
2800 localshadow[6]= score;
2801 localsp = localshadow;
2802 }
2803
2804
2805 /* Ok - finished max calculation for MATCH */
2806 /* Add any movement independant score and put away */
2807 /* Actually, already done inside scores */
2808 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH) = score;
2809 for(k=0;k<7;k++)
2810 LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH,k) = localsp[k];
2811 /* Now figure out if any specials need this score */
2812
2813
2814 /* state MATCH is a source for special END */
2815 temp = score + (0) + (0) ;
2816 if( temp > LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) ) {
2817 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) = temp;
2818 /* Have to push only bottem half of system here */
2819 for(k=0;k<3;k++)
2820 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,k) = LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH,k);
2821 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,6) = LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH,6);
2822 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,3) = i;
2823 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,4) = j;
2824 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,5) = MATCH;
2825 }
2826
2827
2828
2829
2830 /* Finished calculating state MATCH */
2831
2832
2833 /* For state INSERT */
2834 /* setting first movement to score */
2835 score = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open + (0);
2836 /* assign local shadown pointer */
2837 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH,0));
2838 /* From state INSERT to state INSERT */
2839 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext +(0);
2840 if( temp > score ) {
2841 score = temp;
2842 /* assign local shadown pointer */
2843 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,INSERT,0));
2844 }
2845
2846
2847 /* Ok - finished max calculation for INSERT */
2848 /* Add any movement independant score and put away */
2849 /* Actually, already done inside scores */
2850 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,INSERT) = score;
2851 for(k=0;k<7;k++)
2852 LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,INSERT,k) = localsp[k];
2853 /* Now figure out if any specials need this score */
2854
2855
2856 /* Finished calculating state INSERT */
2857
2858
2859 /* For state DELETE */
2860 /* setting first movement to score */
2861 score = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open + (0);
2862 /* assign local shadown pointer */
2863 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH,0));
2864 /* From state DELETE to state DELETE */
2865 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext +(0);
2866 if( temp > score ) {
2867 score = temp;
2868 /* assign local shadown pointer */
2869 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,DELETE,0));
2870 }
2871
2872
2873 /* Ok - finished max calculation for DELETE */
2874 /* Add any movement independant score and put away */
2875 /* Actually, already done inside scores */
2876 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,DELETE) = score;
2877 for(k=0;k<7;k++)
2878 LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,DELETE,k) = localsp[k];
2879 /* Now figure out if any specials need this score */
2880
2881
2882 /* Finished calculating state DELETE */
2883
2884
2885 /* For state UNMATCHED */
2886 /* setting first movement to score */
2887 score = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual + (0);
2888 /* assign local shadown pointer */
2889 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH,0));
2890 /* From state START to state UNMATCHED */
2891 temp = LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i-1,j-1,START) + mat->un_dual + (0);
2892 if( temp > score ) {
2893 score = temp;
2894 /* This state [START] is a special for UNMATCHED... push top shadow pointers here */
2895 localshadow[0]= i;
2896 localshadow[1]= j;
2897 localshadow[2]= UNMATCHED;
2898 localshadow[3]= (-1);
2899 localshadow[4]= (-1);
2900 localshadow[5]= (-1);
2901 localshadow[6]= score;
2902 localsp = localshadow;
2903 }
2904 /* From state UNMATCHED to state UNMATCHED */
2905 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual +(0);
2906 if( temp > score ) {
2907 score = temp;
2908 /* assign local shadown pointer */
2909 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED,0));
2910 }
2911 /* From state UNMATCHED to state UNMATCHED */
2912 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single +(0);
2913 if( temp > score ) {
2914 score = temp;
2915 /* assign local shadown pointer */
2916 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED,0));
2917 }
2918 /* From state UNMATCHED to state UNMATCHED */
2919 temp = LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single +(0);
2920 if( temp > score ) {
2921 score = temp;
2922 /* assign local shadown pointer */
2923 localsp = &(LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED,0));
2924 }
2925
2926
2927 /* Ok - finished max calculation for UNMATCHED */
2928 /* Add any movement independant score and put away */
2929 /* Actually, already done inside scores */
2930 LargeBlockAligner_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED) = score;
2931 for(k=0;k<7;k++)
2932 LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k) = localsp[k];
2933 /* Now figure out if any specials need this score */
2934
2935
2936 /* state UNMATCHED is a source for special END */
2937 temp = score + (0) + (0) ;
2938 if( temp > LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) ) {
2939 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) = temp;
2940 /* Have to push only bottem half of system here */
2941 for(k=0;k<3;k++)
2942 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,k) = LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,k);
2943 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,6) = LargeBlockAligner_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,6);
2944 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,3) = i;
2945 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,4) = j;
2946 LargeBlockAligner_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,5) = UNMATCHED;
2947 }
2948
2949
2950
2951
2952 /* Finished calculating state UNMATCHED */
2953
2954
2955 } /* end of for each i position in strip */
2956 } /* end of for each j strip */
2957 free(score_pointers);
2958 free(shadow_pointers);
2959 return TRUE;
2960 }
2961
2962
2963 /* Function: init_start_end_linear_LargeBlockAligner(mat)
2964 *
2965 * Descrip: No Description
2966 *
2967 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
2968 *
2969 */
init_start_end_linear_LargeBlockAligner(LargeBlockAligner * mat)2970 void init_start_end_linear_LargeBlockAligner(LargeBlockAligner * mat)
2971 {
2972 register int i;
2973 register int j;
2974 for(j=0;j<3;j++) {
2975 for(i=(-1);i<mat->q->seq->len;i++) {
2976 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,MATCH) = NEGI;
2977 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH,0) = (-1);
2978 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,INSERT) = NEGI;
2979 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,INSERT,0) = (-1);
2980 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,DELETE) = NEGI;
2981 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,DELETE,0) = (-1);
2982 LargeBlockAligner_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED) = NEGI;
2983 LargeBlockAligner_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED,0) = (-1);
2984 }
2985 }
2986
2987
2988 for(j=(-1);j<mat->t->seq->len;j++) {
2989 LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,j,START) = 0;
2990 LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,j,START,0) = j;
2991 LargeBlockAligner_DC_SHADOW_SPECIAL(mat,0,j,END) = NEGI;
2992 LargeBlockAligner_DC_SHADOW_SPECIAL_SP(mat,0,j,END,0) = (-1);
2993 }
2994
2995
2996 return;
2997 }
2998
2999
3000 /* Function: convert_PackAln_to_AlnBlock_LargeBlockAligner(pal)
3001 *
3002 * Descrip: Converts a path alignment to a label alignment
3003 * The label alignment is probably much more useful than the path
3004 *
3005 *
3006 * Arg: pal [UNKN ] Undocumented argument [PackAln *]
3007 *
3008 * Return [UNKN ] Undocumented return value [AlnBlock *]
3009 *
3010 */
convert_PackAln_to_AlnBlock_LargeBlockAligner(PackAln * pal)3011 AlnBlock * convert_PackAln_to_AlnBlock_LargeBlockAligner(PackAln * pal)
3012 {
3013 AlnConvertSet * acs;
3014 AlnBlock * alb;
3015
3016
3017 acs = AlnConvertSet_LargeBlockAligner();
3018 alb = AlnBlock_from_PackAln(acs,pal);
3019 free_AlnConvertSet(acs);
3020 return alb;
3021 }
3022
3023
3024 static char * query_label[] = { "SEQUENCE","INSERT","UNMATCHED_SEQUENCE","END" };
3025 /* Function: AlnConvertSet_LargeBlockAligner(void)
3026 *
3027 * Descrip: No Description
3028 *
3029 *
3030 * Return [UNKN ] Undocumented return value [AlnConvertSet *]
3031 *
3032 */
3033 static char * target_label[] = { "SEQUENCE","INSERT","UNMATCHED_SEQUENCE","END" };
AlnConvertSet_LargeBlockAligner(void)3034 AlnConvertSet * AlnConvertSet_LargeBlockAligner(void)
3035 {
3036 AlnConvertUnit * acu;
3037 AlnConvertSet * out;
3038
3039
3040 out = AlnConvertSet_alloc_std();
3041
3042
3043 acu = AlnConvertUnit_alloc();
3044 add_AlnConvertSet(out,acu);
3045 acu->state1 = MATCH;
3046 acu->state2 = MATCH;
3047 acu->offi = 1;
3048 acu->offj = 1;
3049 acu->label1 = query_label[0];
3050 acu->label2 = target_label[0];
3051 acu = AlnConvertUnit_alloc();
3052 add_AlnConvertSet(out,acu);
3053 acu->state1 = INSERT;
3054 acu->state2 = MATCH;
3055 acu->offi = 1;
3056 acu->offj = 1;
3057 acu->label1 = query_label[0];
3058 acu->label2 = target_label[0];
3059 acu = AlnConvertUnit_alloc();
3060 add_AlnConvertSet(out,acu);
3061 acu->state1 = DELETE;
3062 acu->state2 = MATCH;
3063 acu->offi = 1;
3064 acu->offj = 1;
3065 acu->label1 = query_label[0];
3066 acu->label2 = target_label[0];
3067 acu = AlnConvertUnit_alloc();
3068 add_AlnConvertSet(out,acu);
3069 acu->state1 = UNMATCHED;
3070 acu->state2 = MATCH;
3071 acu->offi = 1;
3072 acu->offj = 1;
3073 acu->label1 = query_label[0];
3074 acu->label2 = target_label[0];
3075 acu = AlnConvertUnit_alloc();
3076 add_AlnConvertSet(out,acu);
3077 acu->state1 = START + 4;
3078 acu->is_from_special = TRUE;
3079 acu->state2 = MATCH;
3080 acu->offi = (-1);
3081 acu->offj = 1;
3082 acu->label1 = query_label[0];
3083 acu->label2 = target_label[0];
3084 acu = AlnConvertUnit_alloc();
3085 add_AlnConvertSet(out,acu);
3086 acu->state1 = MATCH;
3087 acu->state2 = INSERT;
3088 acu->offi = 0;
3089 acu->offj = 1;
3090 acu->label1 = query_label[1];
3091 acu->label2 = target_label[0];
3092 acu = AlnConvertUnit_alloc();
3093 add_AlnConvertSet(out,acu);
3094 acu->state1 = INSERT;
3095 acu->state2 = INSERT;
3096 acu->offi = 0;
3097 acu->offj = 1;
3098 acu->label1 = query_label[1];
3099 acu->label2 = target_label[0];
3100 acu = AlnConvertUnit_alloc();
3101 add_AlnConvertSet(out,acu);
3102 acu->state1 = MATCH;
3103 acu->state2 = DELETE;
3104 acu->offi = 1;
3105 acu->offj = 0;
3106 acu->label1 = query_label[0];
3107 acu->label2 = target_label[1];
3108 acu = AlnConvertUnit_alloc();
3109 add_AlnConvertSet(out,acu);
3110 acu->state1 = DELETE;
3111 acu->state2 = DELETE;
3112 acu->offi = 1;
3113 acu->offj = 0;
3114 acu->label1 = query_label[0];
3115 acu->label2 = target_label[1];
3116 acu = AlnConvertUnit_alloc();
3117 add_AlnConvertSet(out,acu);
3118 acu->state1 = MATCH;
3119 acu->state2 = UNMATCHED;
3120 acu->offi = 1;
3121 acu->offj = 1;
3122 acu->label1 = query_label[2];
3123 acu->label2 = target_label[2];
3124 acu = AlnConvertUnit_alloc();
3125 add_AlnConvertSet(out,acu);
3126 acu->state1 = START + 4;
3127 acu->is_from_special = TRUE;
3128 acu->state2 = UNMATCHED;
3129 acu->offi = (-1);
3130 acu->offj = 1;
3131 acu->label1 = query_label[2];
3132 acu->label2 = target_label[2];
3133 acu = AlnConvertUnit_alloc();
3134 add_AlnConvertSet(out,acu);
3135 acu->state1 = UNMATCHED;
3136 acu->state2 = UNMATCHED;
3137 acu->offi = 1;
3138 acu->offj = 1;
3139 acu->label1 = query_label[2];
3140 acu->label2 = target_label[2];
3141 acu = AlnConvertUnit_alloc();
3142 add_AlnConvertSet(out,acu);
3143 acu->state1 = UNMATCHED;
3144 acu->state2 = UNMATCHED;
3145 acu->offi = 0;
3146 acu->offj = 1;
3147 acu->label1 = query_label[1];
3148 acu->label2 = target_label[2];
3149 acu = AlnConvertUnit_alloc();
3150 add_AlnConvertSet(out,acu);
3151 acu->state1 = UNMATCHED;
3152 acu->state2 = UNMATCHED;
3153 acu->offi = 1;
3154 acu->offj = 0;
3155 acu->label1 = query_label[2];
3156 acu->label2 = target_label[1];
3157 acu = AlnConvertUnit_alloc();
3158 add_AlnConvertSet(out,acu);
3159 acu->state1 = MATCH;
3160 acu->state2 = END + 4;
3161 acu->offi = (-1);
3162 acu->offj = 0;
3163 acu->label1 = query_label[3];
3164 acu->label2 = target_label[3];
3165 acu = AlnConvertUnit_alloc();
3166 add_AlnConvertSet(out,acu);
3167 acu->state1 = UNMATCHED;
3168 acu->state2 = END + 4;
3169 acu->offi = (-1);
3170 acu->offj = 0;
3171 acu->label1 = query_label[3];
3172 acu->label2 = target_label[3];
3173 return out;
3174 }
3175
3176
3177 /* Function: PackAln_read_Expl_LargeBlockAligner(mat)
3178 *
3179 * Descrip: Reads off PackAln from explicit matrix structure
3180 *
3181 *
3182 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3183 *
3184 * Return [UNKN ] Undocumented return value [PackAln *]
3185 *
3186 */
PackAln_read_Expl_LargeBlockAligner(LargeBlockAligner * mat)3187 PackAln * PackAln_read_Expl_LargeBlockAligner(LargeBlockAligner * mat)
3188 {
3189 LargeBlockAligner_access_func_holder holder;
3190
3191
3192 holder.access_main = LargeBlockAligner_explicit_access_main;
3193 holder.access_special = LargeBlockAligner_explicit_access_special;
3194 return PackAln_read_generic_LargeBlockAligner(mat,holder);
3195 }
3196
3197
3198 /* Function: LargeBlockAligner_explicit_access_main(mat,i,j,state)
3199 *
3200 * Descrip: No Description
3201 *
3202 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3203 * Arg: i [UNKN ] Undocumented argument [int]
3204 * Arg: j [UNKN ] Undocumented argument [int]
3205 * Arg: state [UNKN ] Undocumented argument [int]
3206 *
3207 * Return [UNKN ] Undocumented return value [int]
3208 *
3209 */
LargeBlockAligner_explicit_access_main(LargeBlockAligner * mat,int i,int j,int state)3210 int LargeBlockAligner_explicit_access_main(LargeBlockAligner * mat,int i,int j,int state)
3211 {
3212 return LargeBlockAligner_EXPL_MATRIX(mat,i,j,state);
3213 }
3214
3215
3216 /* Function: LargeBlockAligner_explicit_access_special(mat,i,j,state)
3217 *
3218 * Descrip: No Description
3219 *
3220 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3221 * Arg: i [UNKN ] Undocumented argument [int]
3222 * Arg: j [UNKN ] Undocumented argument [int]
3223 * Arg: state [UNKN ] Undocumented argument [int]
3224 *
3225 * Return [UNKN ] Undocumented return value [int]
3226 *
3227 */
LargeBlockAligner_explicit_access_special(LargeBlockAligner * mat,int i,int j,int state)3228 int LargeBlockAligner_explicit_access_special(LargeBlockAligner * mat,int i,int j,int state)
3229 {
3230 return LargeBlockAligner_EXPL_SPECIAL(mat,i,j,state);
3231 }
3232
3233
3234 /* Function: PackAln_read_generic_LargeBlockAligner(mat,h)
3235 *
3236 * Descrip: Reads off PackAln from explicit matrix structure
3237 *
3238 *
3239 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3240 * Arg: h [UNKN ] Undocumented argument [LargeBlockAligner_access_func_holder]
3241 *
3242 * Return [UNKN ] Undocumented return value [PackAln *]
3243 *
3244 */
PackAln_read_generic_LargeBlockAligner(LargeBlockAligner * mat,LargeBlockAligner_access_func_holder h)3245 PackAln * PackAln_read_generic_LargeBlockAligner(LargeBlockAligner * mat,LargeBlockAligner_access_func_holder h)
3246 {
3247 register PackAln * out;
3248 int i;
3249 int j;
3250 int state;
3251 int cellscore = (-1);
3252 boolean isspecial;
3253 PackAlnUnit * pau = NULL;
3254 PackAlnUnit * prev = NULL;
3255
3256
3257 assert(mat);
3258 assert(h.access_main);
3259 assert(h.access_special);
3260
3261
3262 out = PackAln_alloc_std();
3263 if( out == NULL )
3264 return NULL;
3265
3266
3267 out->score = find_end_LargeBlockAligner(mat,&i,&j,&state,&isspecial,h);
3268
3269
3270 /* Add final end transition (at the moment we have not got the score! */
3271 if( (pau= PackAlnUnit_alloc()) == NULL || add_PackAln(out,pau) == FALSE ) {
3272 warn("Failed the first PackAlnUnit alloc, %d length of Alignment in LargeBlockAligner_basic_read, returning a mess.(Sorry!)",out->len);
3273 return out;
3274 }
3275
3276
3277 /* Put in positions for end trans. Remember that coordinates in C style */
3278 pau->i = i;
3279 pau->j = j;
3280 if( isspecial != TRUE)
3281 pau->state = state;
3282 else pau->state = state + 4;
3283 prev=pau;
3284 while( state != START || isspecial != TRUE) { /*while state != START*/
3285
3286
3287 if( isspecial == TRUE )
3288 max_calc_special_LargeBlockAligner(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore,h);
3289 else
3290 max_calc_LargeBlockAligner(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore,h);
3291 if(i == LargeBlockAligner_READ_OFF_ERROR || j == LargeBlockAligner_READ_OFF_ERROR || state == LargeBlockAligner_READ_OFF_ERROR ) {
3292 warn("Problem - hit bad read off system, exiting now");
3293 break;
3294 }
3295 if( (pau= PackAlnUnit_alloc()) == NULL || add_PackAln(out,pau) == FALSE ) {
3296 warn("Failed a PackAlnUnit alloc, %d length of Alignment in LargeBlockAligner_basic_read, returning partial alignment",out->len);
3297 break;
3298 }
3299
3300
3301 /* Put in positions for block. Remember that coordinates in C style */
3302 pau->i = i;
3303 pau->j = j;
3304 if( isspecial != TRUE)
3305 pau->state = state;
3306 else pau->state = state + 4;
3307 prev->score = cellscore;
3308 prev = pau;
3309 } /* end of while state != START */
3310
3311
3312 invert_PackAln(out);
3313 return out;
3314 }
3315
3316
3317 /* Function: find_end_LargeBlockAligner(mat,ri,rj,state,isspecial,h)
3318 *
3319 * Descrip: No Description
3320 *
3321 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3322 * Arg: ri [UNKN ] Undocumented argument [int *]
3323 * Arg: rj [UNKN ] Undocumented argument [int *]
3324 * Arg: state [UNKN ] Undocumented argument [int *]
3325 * Arg: isspecial [UNKN ] Undocumented argument [boolean *]
3326 * Arg: h [UNKN ] Undocumented argument [LargeBlockAligner_access_func_holder]
3327 *
3328 * Return [UNKN ] Undocumented return value [int]
3329 *
3330 */
find_end_LargeBlockAligner(LargeBlockAligner * mat,int * ri,int * rj,int * state,boolean * isspecial,LargeBlockAligner_access_func_holder h)3331 int find_end_LargeBlockAligner(LargeBlockAligner * mat,int * ri,int * rj,int * state,boolean * isspecial,LargeBlockAligner_access_func_holder h)
3332 {
3333 int j;
3334 int max;
3335 int maxj;
3336 int temp;
3337
3338
3339 max = (*h.access_special)(mat,0,mat->t->seq->len-1,END);
3340 maxj = mat->t->seq->len-1;
3341 for(j= mat->t->seq->len-2 ;j >= 0 ;j--) {
3342 if( (temp =(*h.access_special)(mat,0,j,END)) > max ) {
3343 max = temp;
3344 maxj = j;
3345 }
3346 }
3347
3348
3349 if( ri != NULL)
3350 *ri = 0;
3351 if( rj != NULL)
3352 *rj = maxj;
3353 if( state != NULL)
3354 *state = END;
3355 if( isspecial != NULL)
3356 *isspecial = TRUE;
3357
3358
3359 return max;
3360 }
3361
3362
3363 /* Function: LargeBlockAligner_debug_show_matrix(mat,starti,stopi,startj,stopj,ofp)
3364 *
3365 * Descrip: No Description
3366 *
3367 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3368 * Arg: starti [UNKN ] Undocumented argument [int]
3369 * Arg: stopi [UNKN ] Undocumented argument [int]
3370 * Arg: startj [UNKN ] Undocumented argument [int]
3371 * Arg: stopj [UNKN ] Undocumented argument [int]
3372 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
3373 *
3374 */
LargeBlockAligner_debug_show_matrix(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,FILE * ofp)3375 void LargeBlockAligner_debug_show_matrix(LargeBlockAligner * mat,int starti,int stopi,int startj,int stopj,FILE * ofp)
3376 {
3377 register int i;
3378 register int j;
3379
3380
3381 for(i=starti;i<stopi && i < mat->q->seq->len;i++) {
3382 for(j=startj;j<stopj && j < mat->t->seq->len;j++) {
3383 fprintf(ofp,"Cell [%d - %d]\n",i,j);
3384 fprintf(ofp,"State MATCH %d\n",LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH));
3385 fprintf(ofp,"State INSERT %d\n",LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT));
3386 fprintf(ofp,"State DELETE %d\n",LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE));
3387 fprintf(ofp,"State UNMATCHED %d\n",LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED));
3388 fprintf(ofp,"\n\n");
3389 }
3390 }
3391
3392
3393 }
3394
3395
3396 /* Function: max_calc_LargeBlockAligner(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore,h)
3397 *
3398 * Descrip: No Description
3399 *
3400 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3401 * Arg: i [UNKN ] Undocumented argument [int]
3402 * Arg: j [UNKN ] Undocumented argument [int]
3403 * Arg: state [UNKN ] Undocumented argument [int]
3404 * Arg: isspecial [UNKN ] Undocumented argument [boolean]
3405 * Arg: reti [UNKN ] Undocumented argument [int *]
3406 * Arg: retj [UNKN ] Undocumented argument [int *]
3407 * Arg: retstate [UNKN ] Undocumented argument [int *]
3408 * Arg: retspecial [UNKN ] Undocumented argument [boolean *]
3409 * Arg: cellscore [UNKN ] Undocumented argument [int *]
3410 * Arg: h [UNKN ] Undocumented argument [LargeBlockAligner_access_func_holder]
3411 *
3412 * Return [UNKN ] Undocumented return value [int]
3413 *
3414 */
max_calc_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,LargeBlockAligner_access_func_holder h)3415 int max_calc_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,LargeBlockAligner_access_func_holder h)
3416 {
3417 register int temp;
3418 register int cscore;
3419
3420
3421 *reti = (*retj) = (*retstate) = LargeBlockAligner_READ_OFF_ERROR;
3422
3423
3424 if( i < 0 || j < 0 || i > mat->q->seq->len || j > mat->t->seq->len) {
3425 warn("In LargeBlockAligner matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state);
3426 return -1;
3427 }
3428
3429
3430 /* Then you have to select the correct switch statement to figure out the readoff */
3431 /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */
3432 cscore = (*h.access_main)(mat,i,j,state);
3433 switch(state) { /*Switch state */
3434 case MATCH :
3435 temp = cscore - (mat->block_open) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
3436 if( temp == (*h.access_special)(mat,i - 1,j - 1,START) ) {
3437 *reti = i - 1;
3438 *retj = j - 1;
3439 *retstate = START;
3440 *retspecial = TRUE;
3441 if( cellscore != NULL) {
3442 *cellscore = cscore - (*h.access_special)(mat,i-1,j-1,START);
3443 }
3444 return (*h.access_main)(mat,i - 1,j - 1,START);
3445 }
3446 temp = cscore - (mat->block_open) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
3447 if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED) ) {
3448 *reti = i - 1;
3449 *retj = j - 1;
3450 *retstate = UNMATCHED;
3451 *retspecial = FALSE;
3452 if( cellscore != NULL) {
3453 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED);
3454 }
3455 return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED);
3456 }
3457 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
3458 if( temp == (*h.access_main)(mat,i - 1,j - 1,DELETE) ) {
3459 *reti = i - 1;
3460 *retj = j - 1;
3461 *retstate = DELETE;
3462 *retspecial = FALSE;
3463 if( cellscore != NULL) {
3464 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,DELETE);
3465 }
3466 return (*h.access_main)(mat,i - 1,j - 1,DELETE);
3467 }
3468 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
3469 if( temp == (*h.access_main)(mat,i - 1,j - 1,INSERT) ) {
3470 *reti = i - 1;
3471 *retj = j - 1;
3472 *retstate = INSERT;
3473 *retspecial = FALSE;
3474 if( cellscore != NULL) {
3475 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,INSERT);
3476 }
3477 return (*h.access_main)(mat,i - 1,j - 1,INSERT);
3478 }
3479 temp = cscore - (0) - ((DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext));
3480 if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH) ) {
3481 *reti = i - 1;
3482 *retj = j - 1;
3483 *retstate = MATCH;
3484 *retspecial = FALSE;
3485 if( cellscore != NULL) {
3486 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH);
3487 }
3488 return (*h.access_main)(mat,i - 1,j - 1,MATCH);
3489 }
3490 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
3491 return (-1);
3492 case INSERT :
3493 temp = cscore - (mat->gap_ext) - (0);
3494 if( temp == (*h.access_main)(mat,i - 0,j - 1,INSERT) ) {
3495 *reti = i - 0;
3496 *retj = j - 1;
3497 *retstate = INSERT;
3498 *retspecial = FALSE;
3499 if( cellscore != NULL) {
3500 *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,INSERT);
3501 }
3502 return (*h.access_main)(mat,i - 0,j - 1,INSERT);
3503 }
3504 temp = cscore - (mat->gap_open) - (0);
3505 if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH) ) {
3506 *reti = i - 0;
3507 *retj = j - 1;
3508 *retstate = MATCH;
3509 *retspecial = FALSE;
3510 if( cellscore != NULL) {
3511 *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH);
3512 }
3513 return (*h.access_main)(mat,i - 0,j - 1,MATCH);
3514 }
3515 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
3516 return (-1);
3517 case DELETE :
3518 temp = cscore - (mat->gap_ext) - (0);
3519 if( temp == (*h.access_main)(mat,i - 1,j - 0,DELETE) ) {
3520 *reti = i - 1;
3521 *retj = j - 0;
3522 *retstate = DELETE;
3523 *retspecial = FALSE;
3524 if( cellscore != NULL) {
3525 *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,DELETE);
3526 }
3527 return (*h.access_main)(mat,i - 1,j - 0,DELETE);
3528 }
3529 temp = cscore - (mat->gap_open) - (0);
3530 if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH) ) {
3531 *reti = i - 1;
3532 *retj = j - 0;
3533 *retstate = MATCH;
3534 *retspecial = FALSE;
3535 if( cellscore != NULL) {
3536 *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH);
3537 }
3538 return (*h.access_main)(mat,i - 1,j - 0,MATCH);
3539 }
3540 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
3541 return (-1);
3542 case UNMATCHED :
3543 temp = cscore - (mat->un_single) - (0);
3544 if( temp == (*h.access_main)(mat,i - 1,j - 0,UNMATCHED) ) {
3545 *reti = i - 1;
3546 *retj = j - 0;
3547 *retstate = UNMATCHED;
3548 *retspecial = FALSE;
3549 if( cellscore != NULL) {
3550 *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,UNMATCHED);
3551 }
3552 return (*h.access_main)(mat,i - 1,j - 0,UNMATCHED);
3553 }
3554 temp = cscore - (mat->un_single) - (0);
3555 if( temp == (*h.access_main)(mat,i - 0,j - 1,UNMATCHED) ) {
3556 *reti = i - 0;
3557 *retj = j - 1;
3558 *retstate = UNMATCHED;
3559 *retspecial = FALSE;
3560 if( cellscore != NULL) {
3561 *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,UNMATCHED);
3562 }
3563 return (*h.access_main)(mat,i - 0,j - 1,UNMATCHED);
3564 }
3565 temp = cscore - (mat->un_dual) - (0);
3566 if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED) ) {
3567 *reti = i - 1;
3568 *retj = j - 1;
3569 *retstate = UNMATCHED;
3570 *retspecial = FALSE;
3571 if( cellscore != NULL) {
3572 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED);
3573 }
3574 return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED);
3575 }
3576 temp = cscore - (mat->un_dual) - (0);
3577 if( temp == (*h.access_special)(mat,i - 1,j - 1,START) ) {
3578 *reti = i - 1;
3579 *retj = j - 1;
3580 *retstate = START;
3581 *retspecial = TRUE;
3582 if( cellscore != NULL) {
3583 *cellscore = cscore - (*h.access_special)(mat,i-1,j-1,START);
3584 }
3585 return (*h.access_main)(mat,i - 1,j - 1,START);
3586 }
3587 temp = cscore - (mat->un_dual) - (0);
3588 if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH) ) {
3589 *reti = i - 1;
3590 *retj = j - 1;
3591 *retstate = MATCH;
3592 *retspecial = FALSE;
3593 if( cellscore != NULL) {
3594 *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH);
3595 }
3596 return (*h.access_main)(mat,i - 1,j - 1,MATCH);
3597 }
3598 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
3599 return (-1);
3600 default:
3601 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found!",i,j,state);
3602 return (-1);
3603 } /* end of Switch state */
3604 }
3605
3606
3607 /* Function: max_calc_special_LargeBlockAligner(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore,h)
3608 *
3609 * Descrip: No Description
3610 *
3611 * Arg: mat [UNKN ] Undocumented argument [LargeBlockAligner *]
3612 * Arg: i [UNKN ] Undocumented argument [int]
3613 * Arg: j [UNKN ] Undocumented argument [int]
3614 * Arg: state [UNKN ] Undocumented argument [int]
3615 * Arg: isspecial [UNKN ] Undocumented argument [boolean]
3616 * Arg: reti [UNKN ] Undocumented argument [int *]
3617 * Arg: retj [UNKN ] Undocumented argument [int *]
3618 * Arg: retstate [UNKN ] Undocumented argument [int *]
3619 * Arg: retspecial [UNKN ] Undocumented argument [boolean *]
3620 * Arg: cellscore [UNKN ] Undocumented argument [int *]
3621 * Arg: h [UNKN ] Undocumented argument [LargeBlockAligner_access_func_holder]
3622 *
3623 * Return [UNKN ] Undocumented return value [int]
3624 *
3625 */
max_calc_special_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,LargeBlockAligner_access_func_holder h)3626 int max_calc_special_LargeBlockAligner(LargeBlockAligner * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,LargeBlockAligner_access_func_holder h)
3627 {
3628 register int temp;
3629 register int cscore;
3630
3631
3632 *reti = (*retj) = (*retstate) = LargeBlockAligner_READ_OFF_ERROR;
3633
3634
3635 if( j < 0 || j > mat->t->seq->len) {
3636 warn("In LargeBlockAligner matrix special read off - out of bounds on matrix [j is %d in special]",j);
3637 return -1;
3638 }
3639
3640
3641 cscore = (*h.access_special)(mat,i,j,state);
3642 switch(state) { /*switch on special states*/
3643 case START :
3644 case END :
3645 /* source UNMATCHED is from main matrix */
3646 for(i= mat->q->seq->len-1;i >= 0 ;i--) { /*for i >= 0*/
3647 temp = cscore - (0) - (0);
3648 if( temp == (*h.access_main)(mat,i - 0,j - 0,UNMATCHED) ) {
3649 *reti = i - 0;
3650 *retj = j - 0;
3651 *retstate = UNMATCHED;
3652 *retspecial = FALSE;
3653 if( cellscore != NULL) {
3654 *cellscore = cscore - (*h.access_main)(mat,i-0,j-0,UNMATCHED);
3655 }
3656 return (*h.access_main)(mat,i - 0,j - 0,UNMATCHED) ;
3657 }
3658 } /* end of for i >= 0 */
3659 /* source MATCH is from main matrix */
3660 for(i= mat->q->seq->len-1;i >= 0 ;i--) { /*for i >= 0*/
3661 temp = cscore - (0) - (0);
3662 if( temp == (*h.access_main)(mat,i - 0,j - 0,MATCH) ) {
3663 *reti = i - 0;
3664 *retj = j - 0;
3665 *retstate = MATCH;
3666 *retspecial = FALSE;
3667 if( cellscore != NULL) {
3668 *cellscore = cscore - (*h.access_main)(mat,i-0,j-0,MATCH);
3669 }
3670 return (*h.access_main)(mat,i - 0,j - 0,MATCH) ;
3671 }
3672 } /* end of for i >= 0 */
3673 default:
3674 warn("Major problem (!) - in LargeBlockAligner read off, position %d,%d state %d no source found dropped into default on source switch!",i,j,state);
3675 return (-1);
3676 } /* end of switch on special states */
3677 }
3678
3679
3680 /* Function: calculate_LargeBlockAligner(mat)
3681 *
3682 * Descrip: This function calculates the LargeBlockAligner matrix when in explicit mode
3683 * To allocate the matrix use /allocate_Expl_LargeBlockAligner
3684 *
3685 *
3686 * Arg: mat [UNKN ] LargeBlockAligner which contains explicit basematrix memory [LargeBlockAligner *]
3687 *
3688 * Return [UNKN ] Undocumented return value [boolean]
3689 *
3690 */
calculate_LargeBlockAligner(LargeBlockAligner * mat)3691 boolean calculate_LargeBlockAligner(LargeBlockAligner * mat)
3692 {
3693 int i;
3694 int j;
3695 int leni;
3696 int lenj;
3697 int tot;
3698 int num;
3699
3700
3701 if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT ) {
3702 warn("in calculate_LargeBlockAligner, passed a non Explicit matrix type, cannot calculate!");
3703 return FALSE;
3704 }
3705
3706
3707 leni = mat->leni;
3708 lenj = mat->lenj;
3709 tot = leni * lenj;
3710 num = 0;
3711
3712
3713 start_reporting("LargeBlockAligner Matrix calculation: ");
3714 for(j=0;j<lenj;j++) {
3715 auto int score;
3716 auto int temp;
3717 for(i=0;i<leni;i++) {
3718 if( num%1000 == 0 )
3719 log_full_error(REPORT,0,"[%7d] Cells %2d%%%%",num,num*100/tot);
3720 num++;
3721
3722
3723 /* For state MATCH */
3724 /* setting first movement to score */
3725 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,MATCH) + 0;
3726 /* From state INSERT to state MATCH */
3727 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,INSERT) + 0;
3728 if( temp > score ) {
3729 score = temp;
3730 }
3731 /* From state DELETE to state MATCH */
3732 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,DELETE) + 0;
3733 if( temp > score ) {
3734 score = temp;
3735 }
3736 /* From state UNMATCHED to state MATCH */
3737 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
3738 if( temp > score ) {
3739 score = temp;
3740 }
3741 /* From state START to state MATCH */
3742 temp = LargeBlockAligner_EXPL_SPECIAL(mat,i-1,j-1,START) + mat->block_open;
3743 if( temp > score ) {
3744 score = temp;
3745 }
3746
3747
3748 /* Ok - finished max calculation for MATCH */
3749 /* Add any movement independant score and put away */
3750 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
3751 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = score;
3752
3753
3754 /* state MATCH is a source for special END */
3755 temp = score + (0) + (0) ;
3756 if( temp > LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) ) {
3757 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = temp;
3758 }
3759
3760
3761
3762
3763 /* Finished calculating state MATCH */
3764
3765
3766 /* For state INSERT */
3767 /* setting first movement to score */
3768 score = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
3769 /* From state INSERT to state INSERT */
3770 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
3771 if( temp > score ) {
3772 score = temp;
3773 }
3774
3775
3776 /* Ok - finished max calculation for INSERT */
3777 /* Add any movement independant score and put away */
3778 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = score;
3779
3780
3781 /* Finished calculating state INSERT */
3782
3783
3784 /* For state DELETE */
3785 /* setting first movement to score */
3786 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
3787 /* From state DELETE to state DELETE */
3788 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
3789 if( temp > score ) {
3790 score = temp;
3791 }
3792
3793
3794 /* Ok - finished max calculation for DELETE */
3795 /* Add any movement independant score and put away */
3796 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = score;
3797
3798
3799 /* Finished calculating state DELETE */
3800
3801
3802 /* For state UNMATCHED */
3803 /* setting first movement to score */
3804 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
3805 /* From state START to state UNMATCHED */
3806 temp = LargeBlockAligner_EXPL_SPECIAL(mat,i-1,j-1,START) + mat->un_dual;
3807 if( temp > score ) {
3808 score = temp;
3809 }
3810 /* From state UNMATCHED to state UNMATCHED */
3811 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
3812 if( temp > score ) {
3813 score = temp;
3814 }
3815 /* From state UNMATCHED to state UNMATCHED */
3816 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
3817 if( temp > score ) {
3818 score = temp;
3819 }
3820 /* From state UNMATCHED to state UNMATCHED */
3821 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
3822 if( temp > score ) {
3823 score = temp;
3824 }
3825
3826
3827 /* Ok - finished max calculation for UNMATCHED */
3828 /* Add any movement independant score and put away */
3829 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = score;
3830
3831
3832 /* state UNMATCHED is a source for special END */
3833 temp = score + (0) + (0) ;
3834 if( temp > LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) ) {
3835 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = temp;
3836 }
3837
3838
3839
3840
3841 /* Finished calculating state UNMATCHED */
3842 }
3843
3844
3845 /* Special state START has no special to special movements */
3846
3847
3848 /* Special state END has no special to special movements */
3849 }
3850 stop_reporting();
3851 return TRUE;
3852 }
3853
3854
3855 /* Function: calculate_dpenv_LargeBlockAligner(mat,dpenv)
3856 *
3857 * Descrip: This function calculates the LargeBlockAligner matrix when in explicit mode, subject to the envelope
3858 *
3859 *
3860 * Arg: mat [UNKN ] LargeBlockAligner which contains explicit basematrix memory [LargeBlockAligner *]
3861 * Arg: dpenv [UNKN ] Undocumented argument [DPEnvelope *]
3862 *
3863 * Return [UNKN ] Undocumented return value [boolean]
3864 *
3865 */
calculate_dpenv_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)3866 boolean calculate_dpenv_LargeBlockAligner(LargeBlockAligner * mat,DPEnvelope * dpenv)
3867 {
3868 int i;
3869 int j;
3870 int k;
3871 int starti;
3872 int startj;
3873 int endi;
3874 int endj;
3875 int tot;
3876 int num;
3877 int should_calc;
3878
3879
3880 if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT ) {
3881 warn("in calculate_LargeBlockAligner, passed a non Explicit matrix type, cannot calculate!");
3882 return FALSE;
3883 }
3884
3885
3886 prepare_DPEnvelope(dpenv);
3887 starti = dpenv->starti;
3888 if( starti < 0 )
3889 starti = 0;
3890 startj = dpenv->startj;
3891 if( startj < 0 )
3892 startj = 0;
3893 endi = dpenv->endi;
3894 if( endi > mat->leni )
3895 endi = mat->leni;
3896 endj = dpenv->endj;
3897 if( endj > mat->lenj )
3898 endj = mat->lenj;
3899 tot = (endi-starti) * (endj-startj);
3900 num = 0;
3901
3902
3903 for(j=startj-1;j<endj;j++) {
3904 for(i=1;i<mat->leni;i++) {
3905 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = NEGI;
3906 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = NEGI;
3907 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = NEGI;
3908 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = NEGI;
3909 }
3910 }
3911 for(j=-1;j<mat->lenj;j++) {
3912 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,START) = 0;
3913 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = NEGI;
3914 }
3915
3916
3917 start_reporting("LargeBlockAligner Matrix calculation: ");
3918 for(j=startj;j<endj;j++) {
3919 auto int score;
3920 auto int temp;
3921 for(i=starti;i<endi;i++) {
3922 /* Check if is in envelope - code identical to is_in_DPEnvelope, but aggressively inlined here for speed */
3923 should_calc = 0;
3924 for(k=0;k<dpenv->len;k++) {
3925 auto DPUnit * u;
3926 u = dpenv->dpu[k];
3927 switch(u->type) {
3928 case DPENV_RECT :
3929 if( i >= u->starti && j >= u->startj && i <= (u->starti+u->height) && j <= (u->startj+u->length))
3930 should_calc = 1;
3931 break;
3932 case DPENV_DIAG :
3933 if( abs( (i-j) - (u->starti-u->startj)) <= u->height && i+j >= u->starti+u->startj && i+j+u->length >= u->starti+u->startj)
3934 should_calc = 1;
3935 break;
3936 }
3937 if( should_calc == 1 )
3938 break;
3939 }
3940 if( should_calc == 0) {
3941 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = NEGI;
3942 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = NEGI;
3943 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = NEGI;
3944 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = NEGI;
3945 continue;
3946 }
3947
3948
3949 if( num%1000 == 0 )
3950 log_full_error(REPORT,0,"[%7d] Cells %2d%%%%",num,num*100/tot);
3951 num++;
3952
3953
3954 /* For state MATCH */
3955 /* setting first movement to score */
3956 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,MATCH) + 0;
3957 /* From state INSERT to state MATCH */
3958 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,INSERT) + 0;
3959 if( temp > score ) {
3960 score = temp;
3961 }
3962 /* From state DELETE to state MATCH */
3963 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,DELETE) + 0;
3964 if( temp > score ) {
3965 score = temp;
3966 }
3967 /* From state UNMATCHED to state MATCH */
3968 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->block_open;
3969 if( temp > score ) {
3970 score = temp;
3971 }
3972 /* From state START to state MATCH */
3973 temp = LargeBlockAligner_EXPL_SPECIAL(mat,i-1,j-1,START) + mat->block_open;
3974 if( temp > score ) {
3975 score = temp;
3976 }
3977
3978
3979 /* Ok - finished max calculation for MATCH */
3980 /* Add any movement independant score and put away */
3981 score += (DnaMatrix_MATCH(mat->dm,CSEQ_DNA_BASE(mat->q,i),CSEQ_DNA_BASE(mat->t,j))+mat->real_ext);
3982 LargeBlockAligner_EXPL_MATRIX(mat,i,j,MATCH) = score;
3983
3984
3985 /* state MATCH is a source for special END */
3986 temp = score + (0) + (0) ;
3987 if( temp > LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) ) {
3988 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = temp;
3989 }
3990
3991
3992
3993
3994 /* Finished calculating state MATCH */
3995
3996
3997 /* For state INSERT */
3998 /* setting first movement to score */
3999 score = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,MATCH) + mat->gap_open;
4000 /* From state INSERT to state INSERT */
4001 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,INSERT) + mat->gap_ext;
4002 if( temp > score ) {
4003 score = temp;
4004 }
4005
4006
4007 /* Ok - finished max calculation for INSERT */
4008 /* Add any movement independant score and put away */
4009 LargeBlockAligner_EXPL_MATRIX(mat,i,j,INSERT) = score;
4010
4011
4012 /* Finished calculating state INSERT */
4013
4014
4015 /* For state DELETE */
4016 /* setting first movement to score */
4017 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,MATCH) + mat->gap_open;
4018 /* From state DELETE to state DELETE */
4019 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,DELETE) + mat->gap_ext;
4020 if( temp > score ) {
4021 score = temp;
4022 }
4023
4024
4025 /* Ok - finished max calculation for DELETE */
4026 /* Add any movement independant score and put away */
4027 LargeBlockAligner_EXPL_MATRIX(mat,i,j,DELETE) = score;
4028
4029
4030 /* Finished calculating state DELETE */
4031
4032
4033 /* For state UNMATCHED */
4034 /* setting first movement to score */
4035 score = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,MATCH) + mat->un_dual;
4036 /* From state START to state UNMATCHED */
4037 temp = LargeBlockAligner_EXPL_SPECIAL(mat,i-1,j-1,START) + mat->un_dual;
4038 if( temp > score ) {
4039 score = temp;
4040 }
4041 /* From state UNMATCHED to state UNMATCHED */
4042 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED) + mat->un_dual;
4043 if( temp > score ) {
4044 score = temp;
4045 }
4046 /* From state UNMATCHED to state UNMATCHED */
4047 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED) + mat->un_single;
4048 if( temp > score ) {
4049 score = temp;
4050 }
4051 /* From state UNMATCHED to state UNMATCHED */
4052 temp = LargeBlockAligner_EXPL_MATRIX(mat,i-1,j-0,UNMATCHED) + mat->un_single;
4053 if( temp > score ) {
4054 score = temp;
4055 }
4056
4057
4058 /* Ok - finished max calculation for UNMATCHED */
4059 /* Add any movement independant score and put away */
4060 LargeBlockAligner_EXPL_MATRIX(mat,i,j,UNMATCHED) = score;
4061
4062
4063 /* state UNMATCHED is a source for special END */
4064 temp = score + (0) + (0) ;
4065 if( temp > LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) ) {
4066 LargeBlockAligner_EXPL_SPECIAL(mat,i,j,END) = temp;
4067 }
4068
4069
4070
4071
4072 /* Finished calculating state UNMATCHED */
4073 }
4074
4075
4076 /* Special state START has no special to special movements */
4077
4078
4079 /* Special state END has no special to special movements */
4080 }
4081 stop_reporting();
4082 return TRUE;
4083 }
4084
4085
4086 /* Function: LargeBlockAligner_alloc(void)
4087 *
4088 * Descrip: Allocates structure: assigns defaults if given
4089 *
4090 *
4091 *
4092 * Return [UNKN ] Undocumented return value [LargeBlockAligner *]
4093 *
4094 */
LargeBlockAligner_alloc(void)4095 LargeBlockAligner * LargeBlockAligner_alloc(void)
4096 {
4097 LargeBlockAligner * out;/* out is exported at end of function */
4098
4099
4100 /* call ckalloc and see if NULL */
4101 if((out=(LargeBlockAligner *) ckalloc (sizeof(LargeBlockAligner))) == NULL) {
4102 warn("LargeBlockAligner_alloc failed ");
4103 return NULL; /* calling function should respond! */
4104 }
4105 out->dynamite_hard_link = 1;
4106 #ifdef PTHREAD
4107 pthread_mutex_init(&(out->dynamite_mutex),NULL);
4108 #endif
4109 out->basematrix = NULL;
4110 out->shatter = NULL;
4111 out->leni = 0;
4112 out->lenj = 0;
4113
4114
4115 return out;
4116 }
4117
4118
4119 /* Function: free_LargeBlockAligner(obj)
4120 *
4121 * Descrip: Free Function: removes the memory held by obj
4122 * Will chain up to owned members and clear all lists
4123 *
4124 *
4125 * Arg: obj [UNKN ] Object that is free'd [LargeBlockAligner *]
4126 *
4127 * Return [UNKN ] Undocumented return value [LargeBlockAligner *]
4128 *
4129 */
free_LargeBlockAligner(LargeBlockAligner * obj)4130 LargeBlockAligner * free_LargeBlockAligner(LargeBlockAligner * obj)
4131 {
4132 int return_early = 0;
4133
4134
4135 if( obj == NULL) {
4136 warn("Attempting to free a NULL pointer to a LargeBlockAligner obj. Should be trappable");
4137 return NULL;
4138 }
4139
4140
4141 #ifdef PTHREAD
4142 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
4143 #endif
4144 if( obj->dynamite_hard_link > 1) {
4145 return_early = 1;
4146 obj->dynamite_hard_link--;
4147 }
4148 #ifdef PTHREAD
4149 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
4150 #endif
4151 if( return_early == 1)
4152 return NULL;
4153 if( obj->basematrix != NULL)
4154 free_BaseMatrix(obj->basematrix);
4155 if( obj->shatter != NULL)
4156 free_ShatterMatrix(obj->shatter);
4157 /* obj->q is linked in */
4158 /* obj->t is linked in */
4159 /* obj->dm is linked in */
4160 /* obj->real_ext is linked in */
4161 /* obj->block_open is linked in */
4162 /* obj->un_dual is linked in */
4163 /* obj->un_single is linked in */
4164 /* obj->gap_open is linked in */
4165 /* obj->gap_ext is linked in */
4166
4167
4168 ckfree(obj);
4169 return NULL;
4170 }
4171
4172
4173
4174
4175
4176 #ifdef _cplusplus
4177 }
4178 #endif
4179