1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "bigdba.h"
5 
6 # line 5 "bigdba.c"
7 
8 
9   /*****************   C functions  ****************/
10   /*             Written using dynamite            */
11   /*            Sat Sep  8 09:05:31 2007           */
12   /*            email birney@sanger.ac.uk          */
13   /* http://www.sanger.ac.uk/Users/birney/dynamite */
14   /*************************************************/
15 
16 
17   /* Please report any problems or bugs to         */
18   /* Ewan Birney, birney@sanger.ac.uk              */
19 
20 
21 /* basic set of macros to map states to numbers */
22 #define MATCH55 0
23 #define MATCH65 1
24 #define MATCH75 2
25 #define MATCH85 3
26 #define MATCH95 4
27 #define UNMATCHED_QUERY 5
28 #define UNMATCHED_TARGET 6
29 
30 
31 #define START 0
32 #define END 1
33 
34 
35 #define BigDnaMatchBlock_EXPL_MATRIX(this_matrix,i,j,STATE) this_matrix->basematrix->matrix[((j+1)*7)+STATE][i+1]
36 #define BigDnaMatchBlock_EXPL_SPECIAL(matrix,i,j,STATE) matrix->basematrix->specmatrix[STATE][j+1]
37 #define BigDnaMatchBlock_READ_OFF_ERROR -3
38 
39 
40 
41 #define BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,STATE) mat->basematrix->matrix[(j+2)%2][((i+1)*7)+STATE]
42 #define BigDnaMatchBlock_VSMALL_SPECIAL(mat,i,j,STATE) mat->basematrix->specmatrix[(j+2)%2][STATE]
43 
44 
45 
46 
47 #define BigDnaMatchBlock_SHATTER_SPECIAL(matrix,i,j,STATE) matrix->shatter->special[STATE][j]
48 #define BigDnaMatchBlock_SHATTER_MATRIX(matrix,i,j,STATE)  fetch_cell_value_ShatterMatrix(mat->shatter,i,j,STATE)
49 
50 
51 /* Function:  PackAln_read_Shatter_BigDnaMatchBlock(mat)
52  *
53  * Descrip:    Reads off PackAln from shatter matrix structure
54  *
55  *
56  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
57  *
58  * Return [UNKN ]  Undocumented return value [PackAln *]
59  *
60  */
PackAln_read_Shatter_BigDnaMatchBlock(BigDnaMatchBlock * mat)61 PackAln * PackAln_read_Shatter_BigDnaMatchBlock(BigDnaMatchBlock * mat)
62 {
63     BigDnaMatchBlock_access_func_holder holder;
64 
65 
66     holder.access_main    = BigDnaMatchBlock_shatter_access_main;
67     holder.access_special = BigDnaMatchBlock_shatter_access_special;
68     assert(mat);
69     assert(mat->shatter);
70     return PackAln_read_generic_BigDnaMatchBlock(mat,holder);
71 }
72 
73 
74 /* Function:  BigDnaMatchBlock_shatter_access_main(mat,i,j,state)
75  *
76  * Descrip: No Description
77  *
78  * Arg:          mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
79  * Arg:            i [UNKN ] Undocumented argument [int]
80  * Arg:            j [UNKN ] Undocumented argument [int]
81  * Arg:        state [UNKN ] Undocumented argument [int]
82  *
83  * Return [UNKN ]  Undocumented return value [int]
84  *
85  */
BigDnaMatchBlock_shatter_access_main(BigDnaMatchBlock * mat,int i,int j,int state)86 int BigDnaMatchBlock_shatter_access_main(BigDnaMatchBlock * mat,int i,int j,int state)
87 {
88     return BigDnaMatchBlock_SHATTER_MATRIX(mat,i,j,state);
89 }
90 
91 
92 /* Function:  BigDnaMatchBlock_shatter_access_special(mat,i,j,state)
93  *
94  * Descrip: No Description
95  *
96  * Arg:          mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
97  * Arg:            i [UNKN ] Undocumented argument [int]
98  * Arg:            j [UNKN ] Undocumented argument [int]
99  * Arg:        state [UNKN ] Undocumented argument [int]
100  *
101  * Return [UNKN ]  Undocumented return value [int]
102  *
103  */
BigDnaMatchBlock_shatter_access_special(BigDnaMatchBlock * mat,int i,int j,int state)104 int BigDnaMatchBlock_shatter_access_special(BigDnaMatchBlock * mat,int i,int j,int state)
105 {
106     return BigDnaMatchBlock_SHATTER_SPECIAL(mat,i,j,state);
107 }
108 
109 
110 /* Function:  calculate_shatter_BigDnaMatchBlock(mat,dpenv)
111  *
112  * Descrip:    This function calculates the BigDnaMatchBlock matrix when in shatter mode
113  *
114  *
115  * Arg:          mat [UNKN ] (null) [BigDnaMatchBlock *]
116  * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
117  *
118  * Return [UNKN ]  Undocumented return value [boolean]
119  *
120  */
calculate_shatter_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)121 boolean calculate_shatter_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)
122 {
123     int i;
124     int j;
125     int k;
126     int should_calc;
127     int leni;
128     int lenj;
129     int tot;
130     int num;
131     int starti;
132     int startj;
133     int endi;
134     int endj;
135 
136 
137     int * SIG_0_0;
138     int * SIG_1_1;
139     int * SIG_0_1;
140     int * SIG_1_0;
141 
142 
143     leni = mat->leni;
144     lenj = mat->lenj;
145 
146 
147     mat->shatter = new_ShatterMatrix(dpenv,7,lenj,2);
148     prepare_DPEnvelope(dpenv);
149     starti = dpenv->starti;
150     if( starti < 0 )
151       starti = 0;
152     startj = dpenv->startj;
153     if( startj < 0 )
154       startj = 0;
155     endi = dpenv->endi;
156     if( endi > mat->leni )
157       endi = mat->leni;
158     endj = dpenv->endj;
159     if( endj > mat->lenj )
160       endj = mat->lenj;
161     tot = (endi-starti) * (endj-startj);
162     num = 0;
163 
164 
165     start_reporting("BigDnaMatchBlock Matrix calculation: ");
166     for(j=startj;j<endj;j++) {
167       auto int score;
168       auto int temp;
169       for(i=starti;i<endi;i++)   {
170         /* Check if is in envelope - code identical to is_in_DPEnvelope, but aggressively inlined here for speed */
171         should_calc = 0;
172         for(k=0;k<dpenv->len;k++)    {
173           auto DPUnit * u;
174           u = dpenv->dpu[k];
175           switch(u->type)    {
176             case DPENV_RECT :
177               if( i >= u->starti && j >= u->startj && i < (u->starti+u->height) && j < (u->startj+u->length))
178                 should_calc = 1;
179               break;
180             case DPENV_DIAG :
181               if(  abs( (i-j) - (u->starti-u->startj)) <= u->height && i+j >= u->starti+u->startj && i+j+u->length >= u->starti+u->startj)
182                 should_calc = 1;
183               break;
184             }
185           if( should_calc == 1 )
186             break;
187           }
188         if( should_calc == 0)
189           continue;
190 
191 
192         SIG_0_0 = fetch_cell_from_ShatterMatrix(mat->shatter,i,j);
193         SIG_1_1 = fetch_cell_from_ShatterMatrix(mat->shatter,i-1,j-1);
194         SIG_0_1 = fetch_cell_from_ShatterMatrix(mat->shatter,i-0,j-1);
195         SIG_1_0 = fetch_cell_from_ShatterMatrix(mat->shatter,i-1,j-0);
196 
197 
198 
199 
200         /* For state MATCH55 */
201         /* setting first movement to score */
202         score = SIG_1_1[MATCH55] + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
203         /* From state MATCH55 to state MATCH55 */
204         temp = SIG_0_1[MATCH55] + mat->g55;
205         if( temp  > score )  {
206           score = temp;
207           }
208         /* From state MATCH55 to state MATCH55 */
209         temp = SIG_1_0[MATCH55] + mat->g55;
210         if( temp  > score )  {
211           score = temp;
212           }
213         /* From state UNMATCHED_TARGET to state MATCH55 */
214         temp = SIG_1_1[UNMATCHED_TARGET] + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
215         if( temp  > score )  {
216           score = temp;
217           }
218 
219 
220         /* Ok - finished max calculation for MATCH55 */
221         /* Add any movement independant score and put away */
222          SIG_0_0[MATCH55] = score;
223 
224 
225         /* Finished calculating state MATCH55 */
226 
227 
228         /* For state MATCH65 */
229         /* setting first movement to score */
230         score = SIG_1_1[MATCH65] + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
231         /* From state MATCH65 to state MATCH65 */
232         temp = SIG_0_1[MATCH65] + mat->g65;
233         if( temp  > score )  {
234           score = temp;
235           }
236         /* From state MATCH65 to state MATCH65 */
237         temp = SIG_1_0[MATCH65] + mat->g65;
238         if( temp  > score )  {
239           score = temp;
240           }
241         /* From state UNMATCHED_TARGET to state MATCH65 */
242         temp = SIG_1_1[UNMATCHED_TARGET] + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
243         if( temp  > score )  {
244           score = temp;
245           }
246 
247 
248         /* Ok - finished max calculation for MATCH65 */
249         /* Add any movement independant score and put away */
250          SIG_0_0[MATCH65] = score;
251 
252 
253         /* Finished calculating state MATCH65 */
254 
255 
256         /* For state MATCH75 */
257         /* setting first movement to score */
258         score = SIG_1_1[MATCH75] + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
259         /* From state MATCH75 to state MATCH75 */
260         temp = SIG_0_1[MATCH75] + mat->g;
261         if( temp  > score )  {
262           score = temp;
263           }
264         /* From state MATCH75 to state MATCH75 */
265         temp = SIG_1_0[MATCH75] + mat->g;
266         if( temp  > score )  {
267           score = temp;
268           }
269         /* From state UNMATCHED_TARGET to state MATCH75 */
270         temp = SIG_1_1[UNMATCHED_TARGET] + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
271         if( temp  > score )  {
272           score = temp;
273           }
274 
275 
276         /* Ok - finished max calculation for MATCH75 */
277         /* Add any movement independant score and put away */
278          SIG_0_0[MATCH75] = score;
279 
280 
281         /* Finished calculating state MATCH75 */
282 
283 
284         /* For state MATCH85 */
285         /* setting first movement to score */
286         score = SIG_1_1[MATCH85] + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
287         /* From state MATCH85 to state MATCH85 */
288         temp = SIG_0_1[MATCH85] + mat->g;
289         if( temp  > score )  {
290           score = temp;
291           }
292         /* From state MATCH85 to state MATCH85 */
293         temp = SIG_1_0[MATCH85] + mat->g;
294         if( temp  > score )  {
295           score = temp;
296           }
297         /* From state UNMATCHED_TARGET to state MATCH85 */
298         temp = SIG_1_1[UNMATCHED_TARGET] + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
299         if( temp  > score )  {
300           score = temp;
301           }
302 
303 
304         /* Ok - finished max calculation for MATCH85 */
305         /* Add any movement independant score and put away */
306          SIG_0_0[MATCH85] = score;
307 
308 
309         /* Finished calculating state MATCH85 */
310 
311 
312         /* For state MATCH95 */
313         /* setting first movement to score */
314         score = SIG_1_1[MATCH95] + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
315         /* From state MATCH95 to state MATCH95 */
316         temp = SIG_0_1[MATCH95] + mat->g;
317         if( temp  > score )  {
318           score = temp;
319           }
320         /* From state MATCH95 to state MATCH95 */
321         temp = SIG_1_0[MATCH95] + mat->g;
322         if( temp  > score )  {
323           score = temp;
324           }
325         /* From state UNMATCHED_TARGET to state MATCH95 */
326         temp = SIG_1_1[UNMATCHED_TARGET] + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
327         if( temp  > score )  {
328           score = temp;
329           }
330 
331 
332         /* Ok - finished max calculation for MATCH95 */
333         /* Add any movement independant score and put away */
334          SIG_0_0[MATCH95] = score;
335 
336 
337         /* Finished calculating state MATCH95 */
338 
339 
340         /* For state UNMATCHED_QUERY */
341         /* setting first movement to score */
342         score = SIG_1_0[MATCH55] + mat->b;
343         /* From state MATCH65 to state UNMATCHED_QUERY */
344         temp = SIG_1_0[MATCH65] + mat->b;
345         if( temp  > score )  {
346           score = temp;
347           }
348         /* From state MATCH75 to state UNMATCHED_QUERY */
349         temp = SIG_1_0[MATCH75] + mat->b;
350         if( temp  > score )  {
351           score = temp;
352           }
353         /* From state MATCH85 to state UNMATCHED_QUERY */
354         temp = SIG_1_0[MATCH85] + mat->b;
355         if( temp  > score )  {
356           score = temp;
357           }
358         /* From state MATCH95 to state UNMATCHED_QUERY */
359         temp = SIG_1_0[MATCH95] + mat->b;
360         if( temp  > score )  {
361           score = temp;
362           }
363         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
364         temp = SIG_1_0[UNMATCHED_QUERY] + mat->u;
365         if( temp  > score )  {
366           score = temp;
367           }
368         /* Has restricted position */
369         if( (i-1) == 0 && (j-0) == 0 )   {
370           /* From state START to state UNMATCHED_QUERY */
371           temp = BigDnaMatchBlock_SHATTER_SPECIAL(mat,i-1,j-0,START) + 0;
372           if( temp  > score )    {
373             score = temp;
374             }
375           }
376 
377 
378         /* Ok - finished max calculation for UNMATCHED_QUERY */
379         /* Add any movement independant score and put away */
380          SIG_0_0[UNMATCHED_QUERY] = score;
381 
382 
383         /* Finished calculating state UNMATCHED_QUERY */
384 
385 
386         /* For state UNMATCHED_TARGET */
387         /* setting first movement to score */
388         score = SIG_0_1[UNMATCHED_QUERY] + mat->v;
389         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
390         temp = SIG_0_1[UNMATCHED_TARGET] + mat->u;
391         if( temp  > score )  {
392           score = temp;
393           }
394 
395 
396         /* Ok - finished max calculation for UNMATCHED_TARGET */
397         /* Add any movement independant score and put away */
398          SIG_0_0[UNMATCHED_TARGET] = score;
399 
400 
401         /* state UNMATCHED_TARGET is a source for special END */
402         /* Has restricted position */
403         if( i == mat->leni-1 && j == mat->lenj-1 )   {
404           temp = score + (0) + (0) ;
405           if( temp > BigDnaMatchBlock_SHATTER_SPECIAL(mat,i,j,END) )     {
406             BigDnaMatchBlock_SHATTER_SPECIAL(mat,i,j,END) = temp;
407             }
408 
409 
410           }
411 
412 
413         /* Finished calculating state UNMATCHED_TARGET */
414         }
415 
416 
417       /* Special state START has no special to special movements */
418 
419 
420       /* Special state END has no special to special movements */
421       }
422     stop_reporting();
423     return TRUE;
424 }
425 
426 
427 /* Function:  search_BigDnaMatchBlock(dbsi,out,query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b)
428  *
429  * Descrip:    This function makes a database search of BigDnaMatchBlock
430  *             It uses the dbsi structure to choose which implementation
431  *             to use of the database searching. This way at run time you
432  *             can switch between single threaded/multi-threaded or hardware
433  *
434  *
435  * Arg:          dbsi [UNKN ] Undocumented argument [DBSearchImpl *]
436  * Arg:           out [UNKN ] Undocumented argument [Hscore *]
437  * Arg:         query [UNKN ] Undocumented argument [ComplexSequence*]
438  * Arg:        target [UNKN ] Undocumented argument [ComplexSequence*]
439  * Arg:        comp55 [UNKN ] Undocumented argument [DnaMatrix*]
440  * Arg:        comp65 [UNKN ] Undocumented argument [DnaMatrix*]
441  * Arg:        comp75 [UNKN ] Undocumented argument [DnaMatrix*]
442  * Arg:        comp85 [UNKN ] Undocumented argument [DnaMatrix*]
443  * Arg:        comp95 [UNKN ] Undocumented argument [DnaMatrix*]
444  * Arg:             g [UNKN ] Undocumented argument [Score]
445  * Arg:           g65 [UNKN ] Undocumented argument [Score]
446  * Arg:           g55 [UNKN ] Undocumented argument [Score]
447  * Arg:             u [UNKN ] Undocumented argument [Score]
448  * Arg:             v [UNKN ] Undocumented argument [Score]
449  * Arg:             s [UNKN ] Undocumented argument [Score]
450  * Arg:             b [UNKN ] Undocumented argument [Score]
451  *
452  * Return [UNKN ]  Undocumented return value [Search_Return_Type]
453  *
454  */
search_BigDnaMatchBlock(DBSearchImpl * dbsi,Hscore * out,ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)455 Search_Return_Type search_BigDnaMatchBlock(DBSearchImpl * dbsi,Hscore * out,ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)
456 {
457     if( out == NULL )    {
458       warn("Passed in a null Hscore object into search_BigDnaMatchBlock. Can't process results!");
459       return SEARCH_ERROR;
460       }
461     if( dbsi == NULL )   {
462       warn("Passed in a null DBSearchImpl object into search_BigDnaMatchBlock. Can't process results!");
463       return SEARCH_ERROR;
464       }
465     if( dbsi->trace_level > 5 )
466       warn("Asking for trace level of %d in database search for BigDnaMatchBlock, but it was compiled with a trace level of -2139062144. Not all trace statements can be shown",dbsi->trace_level);
467     switch(dbsi->type)   { /*switch on implementation*/
468       case DBSearchImpl_Serial :
469         return serial_search_BigDnaMatchBlock(out,query,target ,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b);
470       case DBSearchImpl_Pthreads :
471         warn("This matrix BigDnaMatchBlock was not dyc compiled with thread support");
472         return SEARCH_ERROR;
473       default :
474         warn("database search implementation %s was not provided in the compiled dynamite file from BigDnaMatchBlock",impl_string_DBSearchImpl(dbsi));
475         return SEARCH_ERROR;
476       } /* end of switch on implementation */
477 
478 
479 }
480 
481 
482 /* Function:  serial_search_BigDnaMatchBlock(out,query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b)
483  *
484  * Descrip:    This function makes a database search of BigDnaMatchBlock
485  *             It is a single processor implementation
486  *
487  *
488  * Arg:           out [UNKN ] Undocumented argument [Hscore *]
489  * Arg:         query [UNKN ] Undocumented argument [ComplexSequence*]
490  * Arg:        target [UNKN ] Undocumented argument [ComplexSequence*]
491  * Arg:        comp55 [UNKN ] Undocumented argument [DnaMatrix*]
492  * Arg:        comp65 [UNKN ] Undocumented argument [DnaMatrix*]
493  * Arg:        comp75 [UNKN ] Undocumented argument [DnaMatrix*]
494  * Arg:        comp85 [UNKN ] Undocumented argument [DnaMatrix*]
495  * Arg:        comp95 [UNKN ] Undocumented argument [DnaMatrix*]
496  * Arg:             g [UNKN ] Undocumented argument [Score]
497  * Arg:           g65 [UNKN ] Undocumented argument [Score]
498  * Arg:           g55 [UNKN ] Undocumented argument [Score]
499  * Arg:             u [UNKN ] Undocumented argument [Score]
500  * Arg:             v [UNKN ] Undocumented argument [Score]
501  * Arg:             s [UNKN ] Undocumented argument [Score]
502  * Arg:             b [UNKN ] Undocumented argument [Score]
503  *
504  * Return [UNKN ]  Undocumented return value [Search_Return_Type]
505  *
506  */
serial_search_BigDnaMatchBlock(Hscore * out,ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)507 Search_Return_Type serial_search_BigDnaMatchBlock(Hscore * out,ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)
508 {
509     int db_status;
510     int score;
511     int query_pos = 0;
512     int target_pos = 0;
513     DataScore * ds;
514 
515 
516     push_errormsg_stack("Before any actual search in db searching");
517 
518 
519     target_pos = 0;
520 
521 
522 
523 
524     /* No maximum length - allocated on-the-fly */
525     score = score_only_BigDnaMatchBlock(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b);
526     if( should_store_Hscore(out,score) == TRUE )     { /*if storing datascore*/
527       ds = new_DataScore_from_storage(out);
528       if( ds == NULL )   {
529         warn("BigDnaMatchBlock search had a memory error in allocating a new_DataScore (?a leak somewhere - DataScore is a very small datastructure");
530         return SEARCH_ERROR;
531         }
532       /* Now: add query/target information to the entry */
533       ds->score = score;
534       add_Hscore(out,ds);
535       } /* end of if storing datascore */
536     pop_errormsg_stack();
537     push_errormsg_stack("DB searching: just finished [Query Pos: %d] [Target Pos: %d]",query_pos,target_pos);
538 
539 
540     pop_errormsg_stack();
541     return SEARCH_OK;
542 }
543 
544 
545 /* Function:  score_only_BigDnaMatchBlock(query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b)
546  *
547  * Descrip:    This function just calculates the score for the matrix
548  *             I am pretty sure we can do this better, but hey, for the moment...
549  *             It calls /allocate_BigDnaMatchBlock_only
550  *
551  *
552  * Arg:         query [UNKN ] query data structure [ComplexSequence*]
553  * Arg:        target [UNKN ] target data structure [ComplexSequence*]
554  * Arg:        comp55 [UNKN ] Resource [DnaMatrix*]
555  * Arg:        comp65 [UNKN ] Resource [DnaMatrix*]
556  * Arg:        comp75 [UNKN ] Resource [DnaMatrix*]
557  * Arg:        comp85 [UNKN ] Resource [DnaMatrix*]
558  * Arg:        comp95 [UNKN ] Resource [DnaMatrix*]
559  * Arg:             g [UNKN ] Resource [Score]
560  * Arg:           g65 [UNKN ] Resource [Score]
561  * Arg:           g55 [UNKN ] Resource [Score]
562  * Arg:             u [UNKN ] Resource [Score]
563  * Arg:             v [UNKN ] Resource [Score]
564  * Arg:             s [UNKN ] Resource [Score]
565  * Arg:             b [UNKN ] Resource [Score]
566  *
567  * Return [UNKN ]  Undocumented return value [int]
568  *
569  */
score_only_BigDnaMatchBlock(ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)570 int score_only_BigDnaMatchBlock(ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)
571 {
572     int bestscore = NEGI;
573     int i;
574     int j;
575     int k;
576     BigDnaMatchBlock * mat;
577 
578 
579     mat = allocate_BigDnaMatchBlock_only(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b);
580     if( mat == NULL )    {
581       warn("Memory allocation error in the db search - unable to communicate to calling function. this spells DIASTER!");
582       return NEGI;
583       }
584     if((mat->basematrix = BaseMatrix_alloc_matrix_and_specials(2,(mat->leni + 1) * 7,2,2)) == NULL)  {
585       warn("Score only matrix for BigDnaMatchBlock cannot be allocated, (asking for 1  by %d  cells)",mat->leni*7);
586       mat = free_BigDnaMatchBlock(mat);
587       return 0;
588       }
589     mat->basematrix->type = BASEMATRIX_TYPE_VERYSMALL;
590 
591 
592     /* Now, initiate matrix */
593     for(j=0;j<3;j++) {
594       for(i=(-1);i<mat->leni;i++)    {
595         for(k=0;k<7;k++)
596           BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,k) = NEGI;
597         }
598       BigDnaMatchBlock_VSMALL_SPECIAL(mat,i,j,START) = 0;
599       BigDnaMatchBlock_VSMALL_SPECIAL(mat,i,j,END) = NEGI;
600       }
601 
602 
603     /* Ok, lets do-o-o-o-o it */
604 
605 
606     for(j=0;j<mat->lenj;j++) { /*for all target positions*/
607       auto int score;
608       auto int temp;
609       for(i=0;i<mat->leni;i++)   { /*for all query positions*/
610 
611 
612         /* For state MATCH55 */
613         /* setting first movement to score */
614         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
615         /* From state MATCH55 to state MATCH55 */
616         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
617         if( temp  > score )  {
618           score = temp;
619           }
620         /* From state MATCH55 to state MATCH55 */
621         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
622         if( temp  > score )  {
623           score = temp;
624           }
625         /* From state UNMATCHED_TARGET to state MATCH55 */
626         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
627         if( temp  > score )  {
628           score = temp;
629           }
630 
631 
632         /* Ok - finished max calculation for MATCH55 */
633         /* Add any movement independant score and put away */
634          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,MATCH55) = score;
635 
636 
637         /* Finished calculating state MATCH55 */
638 
639 
640         /* For state MATCH65 */
641         /* setting first movement to score */
642         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
643         /* From state MATCH65 to state MATCH65 */
644         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
645         if( temp  > score )  {
646           score = temp;
647           }
648         /* From state MATCH65 to state MATCH65 */
649         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
650         if( temp  > score )  {
651           score = temp;
652           }
653         /* From state UNMATCHED_TARGET to state MATCH65 */
654         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
655         if( temp  > score )  {
656           score = temp;
657           }
658 
659 
660         /* Ok - finished max calculation for MATCH65 */
661         /* Add any movement independant score and put away */
662          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,MATCH65) = score;
663 
664 
665         /* Finished calculating state MATCH65 */
666 
667 
668         /* For state MATCH75 */
669         /* setting first movement to score */
670         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
671         /* From state MATCH75 to state MATCH75 */
672         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
673         if( temp  > score )  {
674           score = temp;
675           }
676         /* From state MATCH75 to state MATCH75 */
677         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
678         if( temp  > score )  {
679           score = temp;
680           }
681         /* From state UNMATCHED_TARGET to state MATCH75 */
682         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
683         if( temp  > score )  {
684           score = temp;
685           }
686 
687 
688         /* Ok - finished max calculation for MATCH75 */
689         /* Add any movement independant score and put away */
690          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,MATCH75) = score;
691 
692 
693         /* Finished calculating state MATCH75 */
694 
695 
696         /* For state MATCH85 */
697         /* setting first movement to score */
698         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
699         /* From state MATCH85 to state MATCH85 */
700         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
701         if( temp  > score )  {
702           score = temp;
703           }
704         /* From state MATCH85 to state MATCH85 */
705         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
706         if( temp  > score )  {
707           score = temp;
708           }
709         /* From state UNMATCHED_TARGET to state MATCH85 */
710         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
711         if( temp  > score )  {
712           score = temp;
713           }
714 
715 
716         /* Ok - finished max calculation for MATCH85 */
717         /* Add any movement independant score and put away */
718          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,MATCH85) = score;
719 
720 
721         /* Finished calculating state MATCH85 */
722 
723 
724         /* For state MATCH95 */
725         /* setting first movement to score */
726         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
727         /* From state MATCH95 to state MATCH95 */
728         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
729         if( temp  > score )  {
730           score = temp;
731           }
732         /* From state MATCH95 to state MATCH95 */
733         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
734         if( temp  > score )  {
735           score = temp;
736           }
737         /* From state UNMATCHED_TARGET to state MATCH95 */
738         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
739         if( temp  > score )  {
740           score = temp;
741           }
742 
743 
744         /* Ok - finished max calculation for MATCH95 */
745         /* Add any movement independant score and put away */
746          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,MATCH95) = score;
747 
748 
749         /* Finished calculating state MATCH95 */
750 
751 
752         /* For state UNMATCHED_QUERY */
753         /* setting first movement to score */
754         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
755         /* From state MATCH65 to state UNMATCHED_QUERY */
756         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
757         if( temp  > score )  {
758           score = temp;
759           }
760         /* From state MATCH75 to state UNMATCHED_QUERY */
761         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
762         if( temp  > score )  {
763           score = temp;
764           }
765         /* From state MATCH85 to state UNMATCHED_QUERY */
766         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
767         if( temp  > score )  {
768           score = temp;
769           }
770         /* From state MATCH95 to state UNMATCHED_QUERY */
771         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
772         if( temp  > score )  {
773           score = temp;
774           }
775         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
776         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
777         if( temp  > score )  {
778           score = temp;
779           }
780         /* Has restricted position */
781         if( (i-1) == 0 && (j-0) == 0 )   {
782           /* From state START to state UNMATCHED_QUERY */
783           temp = BigDnaMatchBlock_VSMALL_SPECIAL(mat,i-1,j-0,START) + 0;
784           if( temp  > score )    {
785             score = temp;
786             }
787           }
788 
789 
790         /* Ok - finished max calculation for UNMATCHED_QUERY */
791         /* Add any movement independant score and put away */
792          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
793 
794 
795         /* Finished calculating state UNMATCHED_QUERY */
796 
797 
798         /* For state UNMATCHED_TARGET */
799         /* setting first movement to score */
800         score = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
801         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
802         temp = BigDnaMatchBlock_VSMALL_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
803         if( temp  > score )  {
804           score = temp;
805           }
806 
807 
808         /* Ok - finished max calculation for UNMATCHED_TARGET */
809         /* Add any movement independant score and put away */
810          BigDnaMatchBlock_VSMALL_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
811 
812 
813         /* state UNMATCHED_TARGET is a source for special END */
814         /* Has restricted position */
815         if( i == mat->leni-1 && j == mat->lenj-1 )   {
816           temp = score + (0) + (0) ;
817           if( temp > BigDnaMatchBlock_VSMALL_SPECIAL(mat,i,j,END) )  {
818             BigDnaMatchBlock_VSMALL_SPECIAL(mat,i,j,END) = temp;
819             }
820 
821 
822           }
823 
824 
825         /* Finished calculating state UNMATCHED_TARGET */
826         } /* end of for all query positions */
827 
828 
829 
830 
831       /* Special state START has no special to special movements */
832 
833 
834       /* Special state END has no special to special movements */
835       if( bestscore < BigDnaMatchBlock_VSMALL_SPECIAL(mat,0,j,END) )
836         bestscore = BigDnaMatchBlock_VSMALL_SPECIAL(mat,0,j,END);
837       } /* end of for all target positions */
838 
839 
840     mat = free_BigDnaMatchBlock(mat);
841     return bestscore;
842 }
843 
844 
845 /* Function:  PackAln_bestmemory_BigDnaMatchBlock(query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b,dpenv,dpri)
846  *
847  * Descrip:    This function chooses the best memory set-up for the alignment
848  *             using calls to basematrix, and then implements either a large
849  *             or small memory model.
850  *
851  *             It is the best function to use if you just want an alignment
852  *
853  *             If you want a label alignment, you will need
854  *             /convert_PackAln_to_AlnBlock_BigDnaMatchBlock
855  *
856  *
857  * Arg:         query [UNKN ] query data structure [ComplexSequence*]
858  * Arg:        target [UNKN ] target data structure [ComplexSequence*]
859  * Arg:        comp55 [UNKN ] Resource [DnaMatrix*]
860  * Arg:        comp65 [UNKN ] Resource [DnaMatrix*]
861  * Arg:        comp75 [UNKN ] Resource [DnaMatrix*]
862  * Arg:        comp85 [UNKN ] Resource [DnaMatrix*]
863  * Arg:        comp95 [UNKN ] Resource [DnaMatrix*]
864  * Arg:             g [UNKN ] Resource [Score]
865  * Arg:           g65 [UNKN ] Resource [Score]
866  * Arg:           g55 [UNKN ] Resource [Score]
867  * Arg:             u [UNKN ] Resource [Score]
868  * Arg:             v [UNKN ] Resource [Score]
869  * Arg:             s [UNKN ] Resource [Score]
870  * Arg:             b [UNKN ] Resource [Score]
871  * Arg:         dpenv [UNKN ] Undocumented argument [DPEnvelope *]
872  * Arg:          dpri [UNKN ] Undocumented argument [DPRunImpl *]
873  *
874  * Return [UNKN ]  Undocumented return value [PackAln *]
875  *
876  */
PackAln_bestmemory_BigDnaMatchBlock(ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b,DPEnvelope * dpenv,DPRunImpl * dpri)877 PackAln * PackAln_bestmemory_BigDnaMatchBlock(ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b,DPEnvelope * dpenv,DPRunImpl * dpri)
878 {
879     long long total;
880     BigDnaMatchBlock * mat;
881     PackAln * out;
882     DebugMatrix * de;
883     DPRunImplMemory strategy;
884     assert(dpri);
885 
886 
887     total = query->seq->len * target->seq->len;
888     if( dpri->memory == DPIM_Default )   {
889       if( (total * 7 * sizeof(int)) > 1000*dpri->kbyte_size) {
890         strategy = DPIM_Linear;
891         }
892       else   {
893         strategy = DPIM_Explicit;
894         }
895       }
896     else {
897       strategy = dpri->memory;
898       }
899 
900 
901     if( dpenv != NULL )  {
902       if( strategy == DPIM_Explicit) {
903         if( (mat=allocate_Expl_BigDnaMatchBlock(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b,dpri)) == NULL ) {
904           warn("Unable to allocate large BigDnaMatchBlock version");
905           return NULL;
906           }
907         calculate_dpenv_BigDnaMatchBlock(mat,dpenv);
908         out =  PackAln_read_Expl_BigDnaMatchBlock(mat);
909         }
910       else   {
911         mat = allocate_BigDnaMatchBlock_only(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b);
912         calculate_shatter_BigDnaMatchBlock(mat,dpenv);
913         out = PackAln_read_Shatter_BigDnaMatchBlock(mat);
914         }
915       }
916     else {
917       if( strategy == DPIM_Linear )  {
918         /* use small implementation */
919         if( (mat=allocate_Small_BigDnaMatchBlock(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b)) == NULL ) {
920           warn("Unable to allocate small BigDnaMatchBlock version");
921           return NULL;
922           }
923         out = PackAln_calculate_Small_BigDnaMatchBlock(mat,dpenv);
924         }
925       else   {
926         /* use Large implementation */
927         if( (mat=allocate_Expl_BigDnaMatchBlock(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b,dpri)) == NULL ) {
928           warn("Unable to allocate large BigDnaMatchBlock version");
929           return NULL;
930           }
931         if( dpri->debug == TRUE) {
932           fatal("Asked for dydebug, but dynamite file not compiled with -g. Need to recompile dynamite source");
933           }
934         else {
935           calculate_BigDnaMatchBlock(mat);
936           out =  PackAln_read_Expl_BigDnaMatchBlock(mat);
937           }
938         }
939       }
940 
941 
942     mat = free_BigDnaMatchBlock(mat);
943     return out;
944 }
945 
946 
947 /* Function:  allocate_BigDnaMatchBlock_only(query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b)
948  *
949  * Descrip:    This function only allocates the BigDnaMatchBlock structure
950  *             checks types where possible and determines leni and lenj
951  *             The basematrix area is delt with elsewhere
952  *
953  *
954  * Arg:         query [UNKN ] query data structure [ComplexSequence*]
955  * Arg:        target [UNKN ] target data structure [ComplexSequence*]
956  * Arg:        comp55 [UNKN ] Resource [DnaMatrix*]
957  * Arg:        comp65 [UNKN ] Resource [DnaMatrix*]
958  * Arg:        comp75 [UNKN ] Resource [DnaMatrix*]
959  * Arg:        comp85 [UNKN ] Resource [DnaMatrix*]
960  * Arg:        comp95 [UNKN ] Resource [DnaMatrix*]
961  * Arg:             g [UNKN ] Resource [Score]
962  * Arg:           g65 [UNKN ] Resource [Score]
963  * Arg:           g55 [UNKN ] Resource [Score]
964  * Arg:             u [UNKN ] Resource [Score]
965  * Arg:             v [UNKN ] Resource [Score]
966  * Arg:             s [UNKN ] Resource [Score]
967  * Arg:             b [UNKN ] Resource [Score]
968  *
969  * Return [UNKN ]  Undocumented return value [BigDnaMatchBlock *]
970  *
971  */
allocate_BigDnaMatchBlock_only(ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)972 BigDnaMatchBlock * allocate_BigDnaMatchBlock_only(ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)
973 {
974     BigDnaMatchBlock * out;
975 
976 
977     if((out= BigDnaMatchBlock_alloc()) == NULL)  {
978       warn("Allocation of basic BigDnaMatchBlock structure failed...");
979       return NULL;
980       }
981 
982 
983     out->query = query;
984     out->target = target;
985     out->comp55 = comp55;
986     out->comp65 = comp65;
987     out->comp75 = comp75;
988     out->comp85 = comp85;
989     out->comp95 = comp95;
990     out->g = g;
991     out->g65 = g65;
992     out->g55 = g55;
993     out->u = u;
994     out->v = v;
995     out->s = s;
996     out->b = b;
997     out->leni = query->seq->len;
998     out->lenj = target->seq->len;
999     return out;
1000 }
1001 
1002 
1003 /* Function:  allocate_Expl_BigDnaMatchBlock(query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b,dpri)
1004  *
1005  * Descrip:    This function allocates the BigDnaMatchBlock structure
1006  *             and the basematrix area for explicit memory implementations
1007  *             It calls /allocate_BigDnaMatchBlock_only
1008  *
1009  *
1010  * Arg:         query [UNKN ] query data structure [ComplexSequence*]
1011  * Arg:        target [UNKN ] target data structure [ComplexSequence*]
1012  * Arg:        comp55 [UNKN ] Resource [DnaMatrix*]
1013  * Arg:        comp65 [UNKN ] Resource [DnaMatrix*]
1014  * Arg:        comp75 [UNKN ] Resource [DnaMatrix*]
1015  * Arg:        comp85 [UNKN ] Resource [DnaMatrix*]
1016  * Arg:        comp95 [UNKN ] Resource [DnaMatrix*]
1017  * Arg:             g [UNKN ] Resource [Score]
1018  * Arg:           g65 [UNKN ] Resource [Score]
1019  * Arg:           g55 [UNKN ] Resource [Score]
1020  * Arg:             u [UNKN ] Resource [Score]
1021  * Arg:             v [UNKN ] Resource [Score]
1022  * Arg:             s [UNKN ] Resource [Score]
1023  * Arg:             b [UNKN ] Resource [Score]
1024  * Arg:          dpri [UNKN ] Undocumented argument [DPRunImpl *]
1025  *
1026  * Return [UNKN ]  Undocumented return value [BigDnaMatchBlock *]
1027  *
1028  */
allocate_Expl_BigDnaMatchBlock(ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b,DPRunImpl * dpri)1029 BigDnaMatchBlock * allocate_Expl_BigDnaMatchBlock(ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b,DPRunImpl * dpri)
1030 {
1031     BigDnaMatchBlock * out;
1032 
1033 
1034     out = allocate_BigDnaMatchBlock_only(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b);
1035     if( out == NULL )
1036       return NULL;
1037     if( dpri->should_cache == TRUE ) {
1038       if( dpri->cache != NULL )  {
1039         if( dpri->cache->maxleni >= (out->lenj+1)*7 && dpri->cache->maxlenj >= (out->leni+1))
1040           out->basematrix = hard_link_BaseMatrix(dpri->cache);
1041         else
1042           dpri->cache = free_BaseMatrix(dpri->cache);
1043         }
1044       }
1045     if( out->basematrix == NULL )    {
1046       if( (out->basematrix = BaseMatrix_alloc_matrix_and_specials((out->lenj+1)*7,(out->leni+1),2,out->lenj+1)) == NULL) {
1047         warn("Explicit matrix BigDnaMatchBlock cannot be allocated, (asking for %d by %d main cells)",out->leni,out->lenj);
1048         free_BigDnaMatchBlock(out);
1049         return NULL;
1050         }
1051       }
1052     if( dpri->should_cache == TRUE && dpri->cache == NULL)
1053       dpri->cache = hard_link_BaseMatrix(out->basematrix);
1054     out->basematrix->type = BASEMATRIX_TYPE_EXPLICIT;
1055     init_BigDnaMatchBlock(out);
1056     return out;
1057 }
1058 
1059 
1060 /* Function:  init_BigDnaMatchBlock(mat)
1061  *
1062  * Descrip:    This function initates BigDnaMatchBlock matrix when in explicit mode
1063  *             Called in /allocate_Expl_BigDnaMatchBlock
1064  *
1065  *
1066  * Arg:        mat [UNKN ] BigDnaMatchBlock which contains explicit basematrix memory [BigDnaMatchBlock *]
1067  *
1068  */
init_BigDnaMatchBlock(BigDnaMatchBlock * mat)1069 void init_BigDnaMatchBlock(BigDnaMatchBlock * mat)
1070 {
1071     register int i;
1072     register int j;
1073     if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT)   {
1074       warn("Cannot iniate matrix, is not an explicit memory type and you have assummed that");
1075       return;
1076       }
1077 
1078 
1079     for(i= (-1);i<mat->query->seq->len;i++)  {
1080       for(j= (-1);j<2;j++)   {
1081         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = NEGI;
1082         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = NEGI;
1083         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = NEGI;
1084         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = NEGI;
1085         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = NEGI;
1086         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
1087         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
1088         }
1089       }
1090     for(j= (-1);j<mat->target->seq->len;j++) {
1091       for(i= (-1);i<2;i++)   {
1092         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = NEGI;
1093         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = NEGI;
1094         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = NEGI;
1095         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = NEGI;
1096         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = NEGI;
1097         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
1098         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
1099         }
1100       BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,START) = 0;
1101       BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) = NEGI;
1102       }
1103     return;
1104 }
1105 
1106 
1107 /* Function:  recalculate_PackAln_BigDnaMatchBlock(pal,mat)
1108  *
1109  * Descrip:    This function recalculates the PackAln structure produced by BigDnaMatchBlock
1110  *             For example, in linear space methods this is used to score them
1111  *
1112  *
1113  * Arg:        pal [UNKN ] Undocumented argument [PackAln *]
1114  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1115  *
1116  */
recalculate_PackAln_BigDnaMatchBlock(PackAln * pal,BigDnaMatchBlock * mat)1117 void recalculate_PackAln_BigDnaMatchBlock(PackAln * pal,BigDnaMatchBlock * mat)
1118 {
1119     int i,j,k,offi,offj;
1120     PackAlnUnit * prev;
1121     PackAlnUnit * pau;
1122 
1123 
1124     for(k=1,prev=pal->pau[0];k < pal->len;k++,prev=pau)  {
1125       pau = pal->pau[k];
1126       i = pau->i;
1127       j = pau->j;
1128       offi = pau->i - prev->i;
1129       offj = pau->j - prev->j;
1130       switch(pau->state) {
1131         case MATCH55 :
1132           if( offi == 1 && offj == 1 && prev->state == MATCH55 ) {
1133             pau->score = (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
1134             continue;
1135             }
1136           if( offi == 0 && offj == 1 && prev->state == MATCH55 ) {
1137             pau->score = mat->g55 + (0);
1138             continue;
1139             }
1140           if( offi == 1 && offj == 0 && prev->state == MATCH55 ) {
1141             pau->score = mat->g55 + (0);
1142             continue;
1143             }
1144           if( offi == 1 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1145             pau->score = (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) + (0);
1146             continue;
1147             }
1148           warn("In recaluclating PackAln with state MATCH55, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1149           break;
1150         case MATCH65 :
1151           if( offi == 1 && offj == 1 && prev->state == MATCH65 ) {
1152             pau->score = (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
1153             continue;
1154             }
1155           if( offi == 0 && offj == 1 && prev->state == MATCH65 ) {
1156             pau->score = mat->g65 + (0);
1157             continue;
1158             }
1159           if( offi == 1 && offj == 0 && prev->state == MATCH65 ) {
1160             pau->score = mat->g65 + (0);
1161             continue;
1162             }
1163           if( offi == 1 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1164             pau->score = (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) + (0);
1165             continue;
1166             }
1167           warn("In recaluclating PackAln with state MATCH65, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1168           break;
1169         case MATCH75 :
1170           if( offi == 1 && offj == 1 && prev->state == MATCH75 ) {
1171             pau->score = (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
1172             continue;
1173             }
1174           if( offi == 0 && offj == 1 && prev->state == MATCH75 ) {
1175             pau->score = mat->g + (0);
1176             continue;
1177             }
1178           if( offi == 1 && offj == 0 && prev->state == MATCH75 ) {
1179             pau->score = mat->g + (0);
1180             continue;
1181             }
1182           if( offi == 1 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1183             pau->score = (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) + (0);
1184             continue;
1185             }
1186           warn("In recaluclating PackAln with state MATCH75, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1187           break;
1188         case MATCH85 :
1189           if( offi == 1 && offj == 1 && prev->state == MATCH85 ) {
1190             pau->score = (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
1191             continue;
1192             }
1193           if( offi == 0 && offj == 1 && prev->state == MATCH85 ) {
1194             pau->score = mat->g + (0);
1195             continue;
1196             }
1197           if( offi == 1 && offj == 0 && prev->state == MATCH85 ) {
1198             pau->score = mat->g + (0);
1199             continue;
1200             }
1201           if( offi == 1 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1202             pau->score = (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) + (0);
1203             continue;
1204             }
1205           warn("In recaluclating PackAln with state MATCH85, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1206           break;
1207         case MATCH95 :
1208           if( offi == 1 && offj == 1 && prev->state == MATCH95 ) {
1209             pau->score = (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
1210             continue;
1211             }
1212           if( offi == 0 && offj == 1 && prev->state == MATCH95 ) {
1213             pau->score = mat->g + (0);
1214             continue;
1215             }
1216           if( offi == 1 && offj == 0 && prev->state == MATCH95 ) {
1217             pau->score = mat->g + (0);
1218             continue;
1219             }
1220           if( offi == 1 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1221             pau->score = (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) + (0);
1222             continue;
1223             }
1224           warn("In recaluclating PackAln with state MATCH95, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1225           break;
1226         case UNMATCHED_QUERY :
1227           if( offi == 1 && offj == 0 && prev->state == MATCH55 ) {
1228             pau->score = mat->b + (0);
1229             continue;
1230             }
1231           if( offi == 1 && offj == 0 && prev->state == MATCH65 ) {
1232             pau->score = mat->b + (0);
1233             continue;
1234             }
1235           if( offi == 1 && offj == 0 && prev->state == MATCH75 ) {
1236             pau->score = mat->b + (0);
1237             continue;
1238             }
1239           if( offi == 1 && offj == 0 && prev->state == MATCH85 ) {
1240             pau->score = mat->b + (0);
1241             continue;
1242             }
1243           if( offi == 1 && offj == 0 && prev->state == MATCH95 ) {
1244             pau->score = mat->b + (0);
1245             continue;
1246             }
1247           if( offi == 1 && offj == 0 && prev->state == UNMATCHED_QUERY ) {
1248             pau->score = mat->u + (0);
1249             continue;
1250             }
1251           if( offj == 0 && prev->state == (START+7) )    {
1252             pau->score = 0 + (0);
1253             continue;
1254             }
1255           warn("In recaluclating PackAln with state UNMATCHED_QUERY, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1256           break;
1257         case UNMATCHED_TARGET :
1258           if( offi == 0 && offj == 1 && prev->state == UNMATCHED_QUERY ) {
1259             pau->score = mat->v + (0);
1260             continue;
1261             }
1262           if( offi == 0 && offj == 1 && prev->state == UNMATCHED_TARGET )    {
1263             pau->score = mat->u + (0);
1264             continue;
1265             }
1266           warn("In recaluclating PackAln with state UNMATCHED_TARGET, from [%d,%d,%d], got a bad source state. Error!",offi,offj,prev->state);
1267           break;
1268         case (START+7) :
1269           warn("In recaluclating PackAln with state START, got a bad source state. Error!");
1270           break;
1271         case (END+7) :
1272           if( offj == 0 && prev->state == UNMATCHED_TARGET ) {
1273             /* i here comes from the previous state ;) - not the real one */
1274             i = prev->i;
1275             pau->score = 0 + (0);
1276             continue;
1277             }
1278           warn("In recaluclating PackAln with state END, got a bad source state. Error!");
1279           break;
1280         default :
1281           warn("In recaluclating PackAln got a bad recipient state. Error!");
1282         }
1283       prev = pau;
1284       }
1285     return;
1286 }
1287 /* divide and conquor macros are next */
1288 #define BigDnaMatchBlock_HIDDEN_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[(j-hiddenj+1)][(i+1)*7+state])
1289 #define BigDnaMatchBlock_DC_SHADOW_MATRIX(thismatrix,i,j,state) (thismatrix->basematrix->matrix[((j+2)*8) % 16][(i+1)*7+state])
1290 #define BigDnaMatchBlock_HIDDEN_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state][(j+1)])
1291 #define BigDnaMatchBlock_DC_SHADOW_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state*8][(j+1)])
1292 #define BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->matrix[((((j+2)*8)+(shadow+1)) % 16)][(i+1)*7 + state])
1293 #define BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->specmatrix[state*8 +shadow+1][(j+1)])
1294 #define BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(thismatrix,i,j,state) (score_pointers[(((j+1)% 1) * (leni+1) * 7) + ((i+1) * 7) + (state)])
1295 #define BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(thismatrix,i,j,state,shadow) (shadow_pointers[(((j+1)% 1) * (leni+1) * 56) + ((i+1) * 56) + (state * 8) + shadow+1])
1296 #define BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL(thismatrix,i,j,state) (thismatrix->basematrix->specmatrix[state*8][(j+1)])
1297 /* Function:  allocate_Small_BigDnaMatchBlock(query,target,comp55,comp65,comp75,comp85,comp95,g,g65,g55,u,v,s,b)
1298  *
1299  * Descrip:    This function allocates the BigDnaMatchBlock structure
1300  *             and the basematrix area for a small memory implementations
1301  *             It calls /allocate_BigDnaMatchBlock_only
1302  *
1303  *
1304  * Arg:         query [UNKN ] query data structure [ComplexSequence*]
1305  * Arg:        target [UNKN ] target data structure [ComplexSequence*]
1306  * Arg:        comp55 [UNKN ] Resource [DnaMatrix*]
1307  * Arg:        comp65 [UNKN ] Resource [DnaMatrix*]
1308  * Arg:        comp75 [UNKN ] Resource [DnaMatrix*]
1309  * Arg:        comp85 [UNKN ] Resource [DnaMatrix*]
1310  * Arg:        comp95 [UNKN ] Resource [DnaMatrix*]
1311  * Arg:             g [UNKN ] Resource [Score]
1312  * Arg:           g65 [UNKN ] Resource [Score]
1313  * Arg:           g55 [UNKN ] Resource [Score]
1314  * Arg:             u [UNKN ] Resource [Score]
1315  * Arg:             v [UNKN ] Resource [Score]
1316  * Arg:             s [UNKN ] Resource [Score]
1317  * Arg:             b [UNKN ] Resource [Score]
1318  *
1319  * Return [UNKN ]  Undocumented return value [BigDnaMatchBlock *]
1320  *
1321  */
1322 #define BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(thismatrix,i,j,state,shadow) (thismatrix->basematrix->specmatrix[state*8 +shadow+1][(j+1)])
allocate_Small_BigDnaMatchBlock(ComplexSequence * query,ComplexSequence * target,DnaMatrix * comp55,DnaMatrix * comp65,DnaMatrix * comp75,DnaMatrix * comp85,DnaMatrix * comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)1323 BigDnaMatchBlock * allocate_Small_BigDnaMatchBlock(ComplexSequence* query,ComplexSequence* target ,DnaMatrix* comp55,DnaMatrix* comp65,DnaMatrix* comp75,DnaMatrix* comp85,DnaMatrix* comp95,Score g,Score g65,Score g55,Score u,Score v,Score s,Score b)
1324 {
1325     BigDnaMatchBlock * out;
1326 
1327 
1328     out = allocate_BigDnaMatchBlock_only(query, target , comp55, comp65, comp75, comp85, comp95, g, g65, g55, u, v, s, b);
1329     if( out == NULL )
1330       return NULL;
1331     out->basematrix = BaseMatrix_alloc_matrix_and_specials(16,(out->leni + 1) * 7,16,out->lenj+1);
1332     if(out == NULL)  {
1333       warn("Small shadow matrix BigDnaMatchBlock cannot be allocated, (asking for 2 by %d main cells)",out->leni+2);
1334       free_BigDnaMatchBlock(out);
1335       return NULL;
1336       }
1337     out->basematrix->type = BASEMATRIX_TYPE_SHADOW;
1338     return out;
1339 }
1340 
1341 
1342 /* Function:  PackAln_calculate_Small_BigDnaMatchBlock(mat,dpenv)
1343  *
1344  * Descrip:    This function calculates an alignment for BigDnaMatchBlock structure in linear space
1345  *             If you want only the start/end points
1346  *             use /AlnRangeSet_calculate_Small_BigDnaMatchBlock
1347  *
1348  *             The function basically
1349  *               finds start/end points
1350  *               foreach start/end point
1351  *                 calls /full_dc_BigDnaMatchBlock
1352  *
1353  *
1354  * Arg:          mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1355  * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
1356  *
1357  * Return [UNKN ]  Undocumented return value [PackAln *]
1358  *
1359  */
PackAln_calculate_Small_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)1360 PackAln * PackAln_calculate_Small_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)
1361 {
1362     int endj;
1363     int score;
1364     PackAln * out;
1365     PackAlnUnit * pau;
1366     int starti;
1367     int startj;
1368     int startstate;
1369     int stopi;
1370     int stopj;
1371     int stopstate;
1372     int temp;
1373     int donej;  /* This is for reporting, will be passed as a & arg in */
1374     int totalj; /* This also is for reporting, but as is not changed, can be passed by value */
1375 
1376 
1377     if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW )    {
1378       warn("Could not calculate packaln small for BigDnaMatchBlock due to wrong type of matrix");
1379       return NULL;
1380       }
1381 
1382 
1383     out = PackAln_alloc_std();
1384 
1385 
1386     start_reporting("Find start end points: ");
1387     dc_optimised_start_end_calc_BigDnaMatchBlock(mat,dpenv);
1388     score = start_end_find_end_BigDnaMatchBlock(mat,&endj);
1389     out->score = score;
1390     stopstate = END;
1391 
1392     /* No special to specials: one matrix alignment: simply remove and get */
1393     starti = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,0);
1394     startj = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,1);
1395     startstate = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,2);
1396     stopi = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,3);
1397     stopj = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,4);
1398     stopstate = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,5);
1399     temp = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,endj,END,6);
1400     log_full_error(REPORT,0,"[%d,%d][%d,%d] Score %d",starti,startj,stopi,stopj,score);
1401     stop_reporting();
1402     start_reporting("Recovering alignment: ");
1403 
1404 
1405     /* Figuring how much j we have to align for reporting purposes */
1406     donej = 0;
1407     totalj = stopj - startj;
1408     full_dc_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,out,&donej,totalj,dpenv);
1409 
1410 
1411     /* Although we have no specials, need to get start. Better to check than assume */
1412 
1413 
1414     max_matrix_to_special_BigDnaMatchBlock(mat,starti,startj,startstate,temp,&stopi,&stopj,&stopstate,&temp,NULL);
1415     if( stopi == BigDnaMatchBlock_READ_OFF_ERROR || stopstate != START ) {
1416       warn("Problem in reading off special state system, hit a non start state (or an internal error) in a single alignment mode");
1417       invert_PackAln(out);
1418       recalculate_PackAln_BigDnaMatchBlock(out,mat);
1419       return out;
1420       }
1421 
1422 
1423     /* Ok. Put away start start... */
1424     pau = PackAlnUnit_alloc();
1425     pau->i = stopi;
1426     pau->j = stopj;
1427     pau->state = stopstate + 7;
1428     add_PackAln(out,pau);
1429 
1430 
1431     log_full_error(REPORT,0,"Alignment recovered");
1432     stop_reporting();
1433     invert_PackAln(out);
1434     recalculate_PackAln_BigDnaMatchBlock(out,mat);
1435     return out;
1436 
1437 
1438 }
1439 
1440 
1441 /* Function:  AlnRangeSet_calculate_Small_BigDnaMatchBlock(mat)
1442  *
1443  * Descrip:    This function calculates an alignment for BigDnaMatchBlock structure in linear space
1444  *             If you want the full alignment, use /PackAln_calculate_Small_BigDnaMatchBlock
1445  *             If you have already got the full alignment, but want the range set, use /AlnRangeSet_from_PackAln_BigDnaMatchBlock
1446  *             If you have got the small matrix but not the alignment, use /AlnRangeSet_from_BigDnaMatchBlock
1447  *
1448  *
1449  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1450  *
1451  * Return [UNKN ]  Undocumented return value [AlnRangeSet *]
1452  *
1453  */
AlnRangeSet_calculate_Small_BigDnaMatchBlock(BigDnaMatchBlock * mat)1454 AlnRangeSet * AlnRangeSet_calculate_Small_BigDnaMatchBlock(BigDnaMatchBlock * mat)
1455 {
1456     AlnRangeSet * out;
1457 
1458 
1459     start_reporting("Find start end points: ");
1460     dc_optimised_start_end_calc_BigDnaMatchBlock(mat,NULL);
1461     log_full_error(REPORT,0,"Calculated");
1462 
1463 
1464     out = AlnRangeSet_from_BigDnaMatchBlock(mat);
1465     return out;
1466 }
1467 
1468 
1469 /* Function:  AlnRangeSet_from_BigDnaMatchBlock(mat)
1470  *
1471  * Descrip:    This function reads off a start/end structure
1472  *             for BigDnaMatchBlock structure in linear space
1473  *             If you want the full alignment use
1474  *             /PackAln_calculate_Small_BigDnaMatchBlock
1475  *             If you have not calculated the matrix use
1476  *             /AlnRange_calculate_Small_BigDnaMatchBlock
1477  *
1478  *
1479  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1480  *
1481  * Return [UNKN ]  Undocumented return value [AlnRangeSet *]
1482  *
1483  */
AlnRangeSet_from_BigDnaMatchBlock(BigDnaMatchBlock * mat)1484 AlnRangeSet * AlnRangeSet_from_BigDnaMatchBlock(BigDnaMatchBlock * mat)
1485 {
1486     AlnRangeSet * out;
1487     AlnRange * temp;
1488     int jpos;
1489     int state;
1490 
1491 
1492     if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
1493       warn("Bad error! - non shadow matrix type in AlnRangeSet_from_BigDnaMatchBlock");
1494       return NULL;
1495       }
1496 
1497 
1498     out = AlnRangeSet_alloc_std();
1499     /* Find the end position */
1500     out->score = start_end_find_end_BigDnaMatchBlock(mat,&jpos);
1501     state = END;
1502 
1503 
1504     while( (temp = AlnRange_build_BigDnaMatchBlock(mat,jpos,state,&jpos,&state)) != NULL)
1505       add_AlnRangeSet(out,temp);
1506     return out;
1507 }
1508 
1509 
1510 /* Function:  AlnRange_build_BigDnaMatchBlock(mat,stopj,stopspecstate,startj,startspecstate)
1511  *
1512  * Descrip:    This function calculates a single start/end set in linear space
1513  *             Really a sub-routine for /AlnRangeSet_from_PackAln_BigDnaMatchBlock
1514  *
1515  *
1516  * Arg:                   mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1517  * Arg:                 stopj [UNKN ] Undocumented argument [int]
1518  * Arg:         stopspecstate [UNKN ] Undocumented argument [int]
1519  * Arg:                startj [UNKN ] Undocumented argument [int *]
1520  * Arg:        startspecstate [UNKN ] Undocumented argument [int *]
1521  *
1522  * Return [UNKN ]  Undocumented return value [AlnRange *]
1523  *
1524  */
AlnRange_build_BigDnaMatchBlock(BigDnaMatchBlock * mat,int stopj,int stopspecstate,int * startj,int * startspecstate)1525 AlnRange * AlnRange_build_BigDnaMatchBlock(BigDnaMatchBlock * mat,int stopj,int stopspecstate,int * startj,int * startspecstate)
1526 {
1527     AlnRange * out;
1528     int jpos;
1529     int state;
1530 
1531 
1532     if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
1533       warn("Bad error! - non shadow matrix type in AlnRangeSet_from_BigDnaMatchBlock");
1534       return NULL;
1535       }
1536 
1537 
1538     /* Assumme that we have specials (we should!). Read back along the specials till we have the finish point */
1539     if( read_special_strip_BigDnaMatchBlock(mat,0,stopj,stopspecstate,&jpos,&state,NULL) == FALSE)   {
1540       warn("In AlnRanger_build_BigDnaMatchBlock alignment ending at %d, unable to read back specials. Will (evenutally) return a partial range set... BEWARE!",stopj);
1541       return NULL;
1542       }
1543     if( state == START || jpos <= 0)
1544       return NULL;
1545 
1546 
1547     out = AlnRange_alloc();
1548 
1549 
1550     out->starti = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,0);
1551     out->startj = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,1);
1552     out->startstate = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,2);
1553     out->stopi = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,3);
1554     out->stopj = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,4);
1555     out->stopstate = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,5);
1556     out->startscore = BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,jpos,state,6);
1557     out->stopscore = BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,jpos,state);
1558 
1559 
1560     /* Now, we have to figure out where this state came from in the specials */
1561     max_matrix_to_special_BigDnaMatchBlock(mat,out->starti,out->startj,out->startstate,out->startscore,&jpos,startj,startspecstate,&state,NULL);
1562     if( jpos == BigDnaMatchBlock_READ_OFF_ERROR) {
1563       warn("In AlnRange_build_BigDnaMatchBlock 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);
1564       return out;
1565       }
1566 
1567 
1568     /* Put in the correct score for startstate, from the special */
1569     out->startscore = BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,*startj,*startspecstate);
1570     /* The correct j coords have been put into startj, startspecstate... so just return out */
1571     return out;
1572 }
1573 
1574 
1575 /* Function:  read_hidden_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,out)
1576  *
1577  * Descrip: No Description
1578  *
1579  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1580  * Arg:            starti [UNKN ] Undocumented argument [int]
1581  * Arg:            startj [UNKN ] Undocumented argument [int]
1582  * Arg:        startstate [UNKN ] Undocumented argument [int]
1583  * Arg:             stopi [UNKN ] Undocumented argument [int]
1584  * Arg:             stopj [UNKN ] Undocumented argument [int]
1585  * Arg:         stopstate [UNKN ] Undocumented argument [int]
1586  * Arg:               out [UNKN ] Undocumented argument [PackAln *]
1587  *
1588  * Return [UNKN ]  Undocumented return value [boolean]
1589  *
1590  */
read_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out)1591 boolean read_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out)
1592 {
1593     int i;
1594     int j;
1595     int state;
1596     int cellscore;
1597     int isspecial;
1598     /* We don't need hiddenj here, 'cause matrix access handled by max funcs */
1599     PackAlnUnit * pau;
1600 
1601 
1602     /* stop position is on the path */
1603     i = stopi;
1604     j = stopj;
1605     state= stopstate;
1606     isspecial = FALSE;
1607 
1608 
1609     while( i >= starti && j >= startj)   {
1610       /* Put away current i,j,state */
1611       pau = PackAlnUnit_alloc();/* Should deal with memory overflow */
1612       pau->i = i;
1613       pau->j = j;
1614       pau->state =  state;
1615       add_PackAln(out,pau);
1616 
1617 
1618       max_hidden_BigDnaMatchBlock(mat,startj,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore);
1619 
1620 
1621       if( i == BigDnaMatchBlock_READ_OFF_ERROR)  {
1622         warn("In BigDnaMatchBlock hidden read off, between %d:%d,%d:%d - at got bad read off. Problem!",starti,startj,stopi,stopj);
1623         return FALSE;
1624         }
1625 
1626 
1627       if( i == starti && j == startj && state == startstate) {
1628 /* Put away final state (start of this block) */
1629         pau = PackAlnUnit_alloc();  /* Should deal with memory overflow */
1630         pau->i = i;
1631         pau->j = j;
1632         pau->state =  state;
1633         add_PackAln(out,pau);
1634           return TRUE;
1635         }
1636       if( i == starti && j == startj)    {
1637         warn("In BigDnaMatchBlock hidden read off, between %d:%d,%d:%d - hit start cell, but not in start state. Can't be good!.",starti,startj,stopi,stopj);
1638         return FALSE;
1639         }
1640       }
1641     warn("In BigDnaMatchBlock 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);
1642     return FALSE;
1643 }
1644 
1645 
1646 /* Function:  max_hidden_BigDnaMatchBlock(mat,hiddenj,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore)
1647  *
1648  * Descrip: No Description
1649  *
1650  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
1651  * Arg:           hiddenj [UNKN ] Undocumented argument [int]
1652  * Arg:                 i [UNKN ] Undocumented argument [int]
1653  * Arg:                 j [UNKN ] Undocumented argument [int]
1654  * Arg:             state [UNKN ] Undocumented argument [int]
1655  * Arg:         isspecial [UNKN ] Undocumented argument [boolean]
1656  * Arg:              reti [UNKN ] Undocumented argument [int *]
1657  * Arg:              retj [UNKN ] Undocumented argument [int *]
1658  * Arg:          retstate [UNKN ] Undocumented argument [int *]
1659  * Arg:        retspecial [UNKN ] Undocumented argument [boolean *]
1660  * Arg:         cellscore [UNKN ] Undocumented argument [int *]
1661  *
1662  * Return [UNKN ]  Undocumented return value [int]
1663  *
1664  */
max_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)1665 int max_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int hiddenj,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
1666 {
1667     register int temp;
1668     register int cscore;
1669 
1670 
1671     *reti = (*retj) = (*retstate) = BigDnaMatchBlock_READ_OFF_ERROR;
1672 
1673 
1674     if( i < 0 || j < 0 || i > mat->query->seq->len || j > mat->target->seq->len) {
1675       warn("In BigDnaMatchBlock matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state);
1676       return -1;
1677       }
1678 
1679 
1680     /* Then you have to select the correct switch statement to figure out the readoff      */
1681     /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */
1682     cscore = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,state);
1683     switch(state)    { /*Switch state */
1684       case MATCH55 :
1685         temp = cscore - ((mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
1686         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET) )   {
1687           *reti = i - 1;
1688           *retj = j - 1;
1689           *retstate = UNMATCHED_TARGET;
1690           *retspecial = FALSE;
1691           if( cellscore != NULL) {
1692             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET);
1693             }
1694           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET);
1695           }
1696         temp = cscore - (mat->g55) -  (0);
1697         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH55) )    {
1698           *reti = i - 1;
1699           *retj = j - 0;
1700           *retstate = MATCH55;
1701           *retspecial = FALSE;
1702           if( cellscore != NULL) {
1703             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH55);
1704             }
1705           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH55);
1706           }
1707         temp = cscore - (mat->g55) -  (0);
1708         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH55) )    {
1709           *reti = i - 0;
1710           *retj = j - 1;
1711           *retstate = MATCH55;
1712           *retspecial = FALSE;
1713           if( cellscore != NULL) {
1714             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH55);
1715             }
1716           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH55);
1717           }
1718         temp = cscore - ((mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
1719         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH55) )    {
1720           *reti = i - 1;
1721           *retj = j - 1;
1722           *retstate = MATCH55;
1723           *retspecial = FALSE;
1724           if( cellscore != NULL) {
1725             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH55);
1726             }
1727           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH55);
1728           }
1729         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1730         return (-1);
1731       case MATCH65 :
1732         temp = cscore - ((mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
1733         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET) )   {
1734           *reti = i - 1;
1735           *retj = j - 1;
1736           *retstate = UNMATCHED_TARGET;
1737           *retspecial = FALSE;
1738           if( cellscore != NULL) {
1739             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET);
1740             }
1741           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET);
1742           }
1743         temp = cscore - (mat->g65) -  (0);
1744         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH65) )    {
1745           *reti = i - 1;
1746           *retj = j - 0;
1747           *retstate = MATCH65;
1748           *retspecial = FALSE;
1749           if( cellscore != NULL) {
1750             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH65);
1751             }
1752           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH65);
1753           }
1754         temp = cscore - (mat->g65) -  (0);
1755         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH65) )    {
1756           *reti = i - 0;
1757           *retj = j - 1;
1758           *retstate = MATCH65;
1759           *retspecial = FALSE;
1760           if( cellscore != NULL) {
1761             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH65);
1762             }
1763           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH65);
1764           }
1765         temp = cscore - ((mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
1766         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH65) )    {
1767           *reti = i - 1;
1768           *retj = j - 1;
1769           *retstate = MATCH65;
1770           *retspecial = FALSE;
1771           if( cellscore != NULL) {
1772             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH65);
1773             }
1774           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH65);
1775           }
1776         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1777         return (-1);
1778       case MATCH75 :
1779         temp = cscore - ((mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
1780         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET) )   {
1781           *reti = i - 1;
1782           *retj = j - 1;
1783           *retstate = UNMATCHED_TARGET;
1784           *retspecial = FALSE;
1785           if( cellscore != NULL) {
1786             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET);
1787             }
1788           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET);
1789           }
1790         temp = cscore - (mat->g) -  (0);
1791         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH75) )    {
1792           *reti = i - 1;
1793           *retj = j - 0;
1794           *retstate = MATCH75;
1795           *retspecial = FALSE;
1796           if( cellscore != NULL) {
1797             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH75);
1798             }
1799           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH75);
1800           }
1801         temp = cscore - (mat->g) -  (0);
1802         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH75) )    {
1803           *reti = i - 0;
1804           *retj = j - 1;
1805           *retstate = MATCH75;
1806           *retspecial = FALSE;
1807           if( cellscore != NULL) {
1808             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH75);
1809             }
1810           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH75);
1811           }
1812         temp = cscore - ((mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
1813         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH75) )    {
1814           *reti = i - 1;
1815           *retj = j - 1;
1816           *retstate = MATCH75;
1817           *retspecial = FALSE;
1818           if( cellscore != NULL) {
1819             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH75);
1820             }
1821           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH75);
1822           }
1823         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1824         return (-1);
1825       case MATCH85 :
1826         temp = cscore - ((mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
1827         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET) )   {
1828           *reti = i - 1;
1829           *retj = j - 1;
1830           *retstate = UNMATCHED_TARGET;
1831           *retspecial = FALSE;
1832           if( cellscore != NULL) {
1833             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET);
1834             }
1835           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET);
1836           }
1837         temp = cscore - (mat->g) -  (0);
1838         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH85) )    {
1839           *reti = i - 1;
1840           *retj = j - 0;
1841           *retstate = MATCH85;
1842           *retspecial = FALSE;
1843           if( cellscore != NULL) {
1844             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH85);
1845             }
1846           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH85);
1847           }
1848         temp = cscore - (mat->g) -  (0);
1849         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH85) )    {
1850           *reti = i - 0;
1851           *retj = j - 1;
1852           *retstate = MATCH85;
1853           *retspecial = FALSE;
1854           if( cellscore != NULL) {
1855             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH85);
1856             }
1857           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH85);
1858           }
1859         temp = cscore - ((mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
1860         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH85) )    {
1861           *reti = i - 1;
1862           *retj = j - 1;
1863           *retstate = MATCH85;
1864           *retspecial = FALSE;
1865           if( cellscore != NULL) {
1866             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH85);
1867             }
1868           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH85);
1869           }
1870         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1871         return (-1);
1872       case MATCH95 :
1873         temp = cscore - ((mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
1874         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET) )   {
1875           *reti = i - 1;
1876           *retj = j - 1;
1877           *retstate = UNMATCHED_TARGET;
1878           *retspecial = FALSE;
1879           if( cellscore != NULL) {
1880             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET);
1881             }
1882           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,UNMATCHED_TARGET);
1883           }
1884         temp = cscore - (mat->g) -  (0);
1885         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH95) )    {
1886           *reti = i - 1;
1887           *retj = j - 0;
1888           *retstate = MATCH95;
1889           *retspecial = FALSE;
1890           if( cellscore != NULL) {
1891             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH95);
1892             }
1893           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH95);
1894           }
1895         temp = cscore - (mat->g) -  (0);
1896         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH95) )    {
1897           *reti = i - 0;
1898           *retj = j - 1;
1899           *retstate = MATCH95;
1900           *retspecial = FALSE;
1901           if( cellscore != NULL) {
1902             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH95);
1903             }
1904           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,MATCH95);
1905           }
1906         temp = cscore - ((mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
1907         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH95) )    {
1908           *reti = i - 1;
1909           *retj = j - 1;
1910           *retstate = MATCH95;
1911           *retspecial = FALSE;
1912           if( cellscore != NULL) {
1913             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH95);
1914             }
1915           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 1,MATCH95);
1916           }
1917         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1918         return (-1);
1919       case UNMATCHED_QUERY :
1920         /* Not allowing special sources.. skipping START */
1921         temp = cscore - (mat->u) -  (0);
1922         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,UNMATCHED_QUERY) )    {
1923           *reti = i - 1;
1924           *retj = j - 0;
1925           *retstate = UNMATCHED_QUERY;
1926           *retspecial = FALSE;
1927           if( cellscore != NULL) {
1928             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY);
1929             }
1930           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,UNMATCHED_QUERY);
1931           }
1932         temp = cscore - (mat->b) -  (0);
1933         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH95) )    {
1934           *reti = i - 1;
1935           *retj = j - 0;
1936           *retstate = MATCH95;
1937           *retspecial = FALSE;
1938           if( cellscore != NULL) {
1939             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH95);
1940             }
1941           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH95);
1942           }
1943         temp = cscore - (mat->b) -  (0);
1944         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH85) )    {
1945           *reti = i - 1;
1946           *retj = j - 0;
1947           *retstate = MATCH85;
1948           *retspecial = FALSE;
1949           if( cellscore != NULL) {
1950             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH85);
1951             }
1952           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH85);
1953           }
1954         temp = cscore - (mat->b) -  (0);
1955         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH75) )    {
1956           *reti = i - 1;
1957           *retj = j - 0;
1958           *retstate = MATCH75;
1959           *retspecial = FALSE;
1960           if( cellscore != NULL) {
1961             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH75);
1962             }
1963           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH75);
1964           }
1965         temp = cscore - (mat->b) -  (0);
1966         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH65) )    {
1967           *reti = i - 1;
1968           *retj = j - 0;
1969           *retstate = MATCH65;
1970           *retspecial = FALSE;
1971           if( cellscore != NULL) {
1972             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH65);
1973             }
1974           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH65);
1975           }
1976         temp = cscore - (mat->b) -  (0);
1977         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH55) )    {
1978           *reti = i - 1;
1979           *retj = j - 0;
1980           *retstate = MATCH55;
1981           *retspecial = FALSE;
1982           if( cellscore != NULL) {
1983             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH55);
1984             }
1985           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 1,j - 0,MATCH55);
1986           }
1987         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
1988         return (-1);
1989       case UNMATCHED_TARGET :
1990         temp = cscore - (mat->u) -  (0);
1991         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED_TARGET) )   {
1992           *reti = i - 0;
1993           *retj = j - 1;
1994           *retstate = UNMATCHED_TARGET;
1995           *retspecial = FALSE;
1996           if( cellscore != NULL) {
1997             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET);
1998             }
1999           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED_TARGET);
2000           }
2001         temp = cscore - (mat->v) -  (0);
2002         if( temp == BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED_QUERY) )    {
2003           *reti = i - 0;
2004           *retj = j - 1;
2005           *retstate = UNMATCHED_QUERY;
2006           *retspecial = FALSE;
2007           if( cellscore != NULL) {
2008             *cellscore = cscore - BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY);
2009             }
2010           return BigDnaMatchBlock_HIDDEN_MATRIX(mat,i - 0,j - 1,UNMATCHED_QUERY);
2011           }
2012         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
2013         return (-1);
2014       default:
2015         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
2016         return (-1);
2017       } /* end of Switch state  */
2018 }
2019 
2020 
2021 /* Function:  read_special_strip_BigDnaMatchBlock(mat,stopi,stopj,stopstate,startj,startstate,out)
2022  *
2023  * Descrip: No Description
2024  *
2025  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2026  * Arg:             stopi [UNKN ] Undocumented argument [int]
2027  * Arg:             stopj [UNKN ] Undocumented argument [int]
2028  * Arg:         stopstate [UNKN ] Undocumented argument [int]
2029  * Arg:            startj [UNKN ] Undocumented argument [int *]
2030  * Arg:        startstate [UNKN ] Undocumented argument [int *]
2031  * Arg:               out [UNKN ] Undocumented argument [PackAln *]
2032  *
2033  * Return [UNKN ]  Undocumented return value [boolean]
2034  *
2035  */
read_special_strip_BigDnaMatchBlock(BigDnaMatchBlock * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out)2036 boolean read_special_strip_BigDnaMatchBlock(BigDnaMatchBlock * mat,int stopi,int stopj,int stopstate,int * startj,int * startstate,PackAln * out)
2037 {
2038     int i;
2039     int j;
2040     int state;
2041     int cellscore;
2042     int isspecial;
2043     PackAlnUnit * pau;
2044 
2045 
2046     /* stop position is on the path */
2047     i = stopi;
2048     j = stopj;
2049     state= stopstate;
2050     isspecial = TRUE;
2051 
2052 
2053     /* Loop until state has the same j as its stop in shadow pointers */
2054     /* This will be the state is came out from, OR it has hit !start */
2055     /* We may not want to get the alignment, in which case out will be NULL */
2056     while( j > BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4) && state != START) { /*while more specials to eat up*/
2057       /* Put away current state, if we should */
2058       if(out != NULL)    {
2059         pau = PackAlnUnit_alloc();  /* Should deal with memory overflow */
2060         pau->i = i;
2061         pau->j = j;
2062         pau->state =  state + 7;
2063         add_PackAln(out,pau);
2064         }
2065 
2066 
2067       max_special_strip_BigDnaMatchBlock(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore);
2068       if( i == BigDnaMatchBlock_READ_OFF_ERROR)  {
2069         warn("In special strip read BigDnaMatchBlock, got a bad read off error. Sorry!");
2070         return FALSE;
2071         }
2072       } /* end of while more specials to eat up */
2073 
2074 
2075     /* check to see we have not gone too far! */
2076     if( state != START && j < BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,i,j,state,4))    {
2077       warn("In special strip read BigDnaMatchBlock, at special [%d] state [%d] overshot!",j,state);
2078       return FALSE;
2079       }
2080     /* Put away last state */
2081     if(out != NULL)  {
2082       pau = PackAlnUnit_alloc();/* Should deal with memory overflow */
2083       pau->i = i;
2084       pau->j = j;
2085       pau->state =  state + 7;
2086       add_PackAln(out,pau);
2087       }
2088 
2089 
2090     /* Put away where we are in startj and startstate */
2091     *startj = j;
2092     *startstate = state;
2093     return TRUE;
2094 }
2095 
2096 
2097 /* Function:  max_special_strip_BigDnaMatchBlock(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore)
2098  *
2099  * Descrip:    A pretty intense internal function. Deals with read-off only in specials
2100  *
2101  *
2102  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2103  * Arg:                 i [UNKN ] Undocumented argument [int]
2104  * Arg:                 j [UNKN ] Undocumented argument [int]
2105  * Arg:             state [UNKN ] Undocumented argument [int]
2106  * Arg:         isspecial [UNKN ] Undocumented argument [boolean]
2107  * Arg:              reti [UNKN ] Undocumented argument [int *]
2108  * Arg:              retj [UNKN ] Undocumented argument [int *]
2109  * Arg:          retstate [UNKN ] Undocumented argument [int *]
2110  * Arg:        retspecial [UNKN ] Undocumented argument [boolean *]
2111  * Arg:         cellscore [UNKN ] Undocumented argument [int *]
2112  *
2113  * Return [UNKN ]  Undocumented return value [int]
2114  *
2115  */
max_special_strip_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)2116 int max_special_strip_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
2117 {
2118     int temp;
2119     int cscore;
2120 
2121 
2122     *reti = (*retj) = (*retstate) = BigDnaMatchBlock_READ_OFF_ERROR;
2123     if( isspecial == FALSE ) {
2124       warn("In special strip max function for BigDnaMatchBlock, got a non special start point. Problem! (bad!)");
2125       return (-1);
2126       }
2127 
2128 
2129     if( j < 0 || j > mat->target->seq->len)  {
2130       warn("In BigDnaMatchBlock matrix special read off - out of bounds on matrix [j is %d in special]",j);
2131       return -1;
2132       }
2133 
2134 
2135     cscore = BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,i,j,state);
2136     switch(state)    { /*switch on special states*/
2137       case START :
2138       case END :
2139         /* Source UNMATCHED_TARGET is not a special */
2140       default:
2141         warn("Major problem (!) - in BigDnaMatchBlock special strip read off, position %d,%d state %d no source found  dropped into default on source switch!",i,j,state);
2142         return (-1);
2143       } /* end of switch on special states */
2144 }
2145 
2146 
2147 /* Function:  max_matrix_to_special_BigDnaMatchBlock(mat,i,j,state,cscore,reti,retj,retstate,retspecial,cellscore)
2148  *
2149  * Descrip: No Description
2150  *
2151  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2152  * Arg:                 i [UNKN ] Undocumented argument [int]
2153  * Arg:                 j [UNKN ] Undocumented argument [int]
2154  * Arg:             state [UNKN ] Undocumented argument [int]
2155  * Arg:            cscore [UNKN ] Undocumented argument [int]
2156  * Arg:              reti [UNKN ] Undocumented argument [int *]
2157  * Arg:              retj [UNKN ] Undocumented argument [int *]
2158  * Arg:          retstate [UNKN ] Undocumented argument [int *]
2159  * Arg:        retspecial [UNKN ] Undocumented argument [boolean *]
2160  * Arg:         cellscore [UNKN ] Undocumented argument [int *]
2161  *
2162  * Return [UNKN ]  Undocumented return value [int]
2163  *
2164  */
max_matrix_to_special_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)2165 int max_matrix_to_special_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,int cscore,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore)
2166 {
2167     int temp;
2168     *reti = (*retj) = (*retstate) = BigDnaMatchBlock_READ_OFF_ERROR;
2169 
2170 
2171     if( j < 0 || j > mat->lenj)  {
2172       warn("In BigDnaMatchBlock matrix to special read off - out of bounds on matrix [j is %d in special]",j);
2173       return -1;
2174       }
2175 
2176 
2177     switch(state)    { /*Switch state */
2178       case MATCH55 :
2179         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2180         /* Source MATCH55 is not a special, should not get here! */
2181         /* Source MATCH55 is not a special, should not get here! */
2182         /* Source MATCH55 is not a special, should not get here! */
2183         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2184         return (-1);
2185       case MATCH65 :
2186         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2187         /* Source MATCH65 is not a special, should not get here! */
2188         /* Source MATCH65 is not a special, should not get here! */
2189         /* Source MATCH65 is not a special, should not get here! */
2190         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2191         return (-1);
2192       case MATCH75 :
2193         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2194         /* Source MATCH75 is not a special, should not get here! */
2195         /* Source MATCH75 is not a special, should not get here! */
2196         /* Source MATCH75 is not a special, should not get here! */
2197         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2198         return (-1);
2199       case MATCH85 :
2200         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2201         /* Source MATCH85 is not a special, should not get here! */
2202         /* Source MATCH85 is not a special, should not get here! */
2203         /* Source MATCH85 is not a special, should not get here! */
2204         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2205         return (-1);
2206       case MATCH95 :
2207         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2208         /* Source MATCH95 is not a special, should not get here! */
2209         /* Source MATCH95 is not a special, should not get here! */
2210         /* Source MATCH95 is not a special, should not get here! */
2211         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2212         return (-1);
2213       case UNMATCHED_QUERY :
2214         temp = cscore - (0) -  (0);
2215         if( temp == BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,i - 1,j - 0,START) )  {
2216           *reti = i - 1;
2217           *retj = j - 0;
2218           *retstate = START;
2219           *retspecial = TRUE;
2220           if( cellscore != NULL) {
2221             *cellscore = cscore - BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,i-1,j-0,START);
2222             }
2223           return BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i - 1,j - 0,START) ;
2224           }
2225         /* Source UNMATCHED_QUERY is not a special, should not get here! */
2226         /* Source MATCH95 is not a special, should not get here! */
2227         /* Source MATCH85 is not a special, should not get here! */
2228         /* Source MATCH75 is not a special, should not get here! */
2229         /* Source MATCH65 is not a special, should not get here! */
2230         /* Source MATCH55 is not a special, should not get here! */
2231         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2232         return (-1);
2233       case UNMATCHED_TARGET :
2234         /* Source UNMATCHED_TARGET is not a special, should not get here! */
2235         /* Source UNMATCHED_QUERY is not a special, should not get here! */
2236         warn("Major problem (!) - in BigDnaMatchBlock matrix to special read off, position %d,%d state %d no source found!",i,j,state);
2237         return (-1);
2238       default:
2239         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
2240         return (-1);
2241       } /* end of Switch state  */
2242 
2243 
2244 }
2245 
2246 
2247 /* Function:  calculate_hidden_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv)
2248  *
2249  * Descrip: No Description
2250  *
2251  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2252  * Arg:            starti [UNKN ] Undocumented argument [int]
2253  * Arg:            startj [UNKN ] Undocumented argument [int]
2254  * Arg:        startstate [UNKN ] Undocumented argument [int]
2255  * Arg:             stopi [UNKN ] Undocumented argument [int]
2256  * Arg:             stopj [UNKN ] Undocumented argument [int]
2257  * Arg:         stopstate [UNKN ] Undocumented argument [int]
2258  * Arg:             dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2259  *
2260  */
calculate_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv)2261 void calculate_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv)
2262 {
2263     register int i;
2264     register int j;
2265     register int score;
2266     register int temp;
2267     register int hiddenj;
2268 
2269 
2270     hiddenj = startj;
2271 
2272 
2273     init_hidden_BigDnaMatchBlock(mat,starti,startj,stopi,stopj);
2274 
2275 
2276     BigDnaMatchBlock_HIDDEN_MATRIX(mat,starti,startj,startstate) = 0;
2277 
2278 
2279     for(j=startj;j<=stopj;j++)   {
2280       for(i=starti;i<=stopi;i++) {
2281         /* Should *not* do very first cell as this is the one set to zero in one state! */
2282         if( i == starti && j == startj )
2283           continue;
2284         if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE )  { /*Is not in envelope*/
2285           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH55) = NEGI;
2286           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH65) = NEGI;
2287           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH75) = NEGI;
2288           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH85) = NEGI;
2289           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH95) = NEGI;
2290           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
2291           BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
2292           continue;
2293           } /* end of Is not in envelope */
2294 
2295 
2296         /* For state MATCH55 */
2297         /* setting first movement to score */
2298         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2299         /* From state MATCH55 to state MATCH55 */
2300         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
2301         if( temp  > score )  {
2302           score = temp;
2303           }
2304         /* From state MATCH55 to state MATCH55 */
2305         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
2306         if( temp  > score )  {
2307           score = temp;
2308           }
2309         /* From state UNMATCHED_TARGET to state MATCH55 */
2310         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2311         if( temp  > score )  {
2312           score = temp;
2313           }
2314 
2315 
2316         /* Ok - finished max calculation for MATCH55 */
2317         /* Add any movement independant score and put away */
2318          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH55) = score;
2319         /* Finished calculating state MATCH55 */
2320 
2321 
2322         /* For state MATCH65 */
2323         /* setting first movement to score */
2324         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2325         /* From state MATCH65 to state MATCH65 */
2326         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
2327         if( temp  > score )  {
2328           score = temp;
2329           }
2330         /* From state MATCH65 to state MATCH65 */
2331         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
2332         if( temp  > score )  {
2333           score = temp;
2334           }
2335         /* From state UNMATCHED_TARGET to state MATCH65 */
2336         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2337         if( temp  > score )  {
2338           score = temp;
2339           }
2340 
2341 
2342         /* Ok - finished max calculation for MATCH65 */
2343         /* Add any movement independant score and put away */
2344          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH65) = score;
2345         /* Finished calculating state MATCH65 */
2346 
2347 
2348         /* For state MATCH75 */
2349         /* setting first movement to score */
2350         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2351         /* From state MATCH75 to state MATCH75 */
2352         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
2353         if( temp  > score )  {
2354           score = temp;
2355           }
2356         /* From state MATCH75 to state MATCH75 */
2357         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
2358         if( temp  > score )  {
2359           score = temp;
2360           }
2361         /* From state UNMATCHED_TARGET to state MATCH75 */
2362         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2363         if( temp  > score )  {
2364           score = temp;
2365           }
2366 
2367 
2368         /* Ok - finished max calculation for MATCH75 */
2369         /* Add any movement independant score and put away */
2370          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH75) = score;
2371         /* Finished calculating state MATCH75 */
2372 
2373 
2374         /* For state MATCH85 */
2375         /* setting first movement to score */
2376         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2377         /* From state MATCH85 to state MATCH85 */
2378         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
2379         if( temp  > score )  {
2380           score = temp;
2381           }
2382         /* From state MATCH85 to state MATCH85 */
2383         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
2384         if( temp  > score )  {
2385           score = temp;
2386           }
2387         /* From state UNMATCHED_TARGET to state MATCH85 */
2388         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2389         if( temp  > score )  {
2390           score = temp;
2391           }
2392 
2393 
2394         /* Ok - finished max calculation for MATCH85 */
2395         /* Add any movement independant score and put away */
2396          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH85) = score;
2397         /* Finished calculating state MATCH85 */
2398 
2399 
2400         /* For state MATCH95 */
2401         /* setting first movement to score */
2402         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2403         /* From state MATCH95 to state MATCH95 */
2404         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
2405         if( temp  > score )  {
2406           score = temp;
2407           }
2408         /* From state MATCH95 to state MATCH95 */
2409         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
2410         if( temp  > score )  {
2411           score = temp;
2412           }
2413         /* From state UNMATCHED_TARGET to state MATCH95 */
2414         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2415         if( temp  > score )  {
2416           score = temp;
2417           }
2418 
2419 
2420         /* Ok - finished max calculation for MATCH95 */
2421         /* Add any movement independant score and put away */
2422          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH95) = score;
2423         /* Finished calculating state MATCH95 */
2424 
2425 
2426         /* For state UNMATCHED_QUERY */
2427         /* setting first movement to score */
2428         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
2429         /* From state MATCH65 to state UNMATCHED_QUERY */
2430         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
2431         if( temp  > score )  {
2432           score = temp;
2433           }
2434         /* From state MATCH75 to state UNMATCHED_QUERY */
2435         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
2436         if( temp  > score )  {
2437           score = temp;
2438           }
2439         /* From state MATCH85 to state UNMATCHED_QUERY */
2440         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
2441         if( temp  > score )  {
2442           score = temp;
2443           }
2444         /* From state MATCH95 to state UNMATCHED_QUERY */
2445         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
2446         if( temp  > score )  {
2447           score = temp;
2448           }
2449         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
2450         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
2451         if( temp  > score )  {
2452           score = temp;
2453           }
2454 
2455 
2456         /* Ok - finished max calculation for UNMATCHED_QUERY */
2457         /* Add any movement independant score and put away */
2458          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
2459         /* Finished calculating state UNMATCHED_QUERY */
2460 
2461 
2462         /* For state UNMATCHED_TARGET */
2463         /* setting first movement to score */
2464         score = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
2465         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
2466         temp = BigDnaMatchBlock_HIDDEN_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
2467         if( temp  > score )  {
2468           score = temp;
2469           }
2470 
2471 
2472         /* Ok - finished max calculation for UNMATCHED_TARGET */
2473         /* Add any movement independant score and put away */
2474          BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
2475         /* Finished calculating state UNMATCHED_TARGET */
2476         }
2477       }
2478 
2479 
2480     return;
2481 }
2482 
2483 
2484 /* Function:  init_hidden_BigDnaMatchBlock(mat,starti,startj,stopi,stopj)
2485  *
2486  * Descrip: No Description
2487  *
2488  * Arg:           mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2489  * Arg:        starti [UNKN ] Undocumented argument [int]
2490  * Arg:        startj [UNKN ] Undocumented argument [int]
2491  * Arg:         stopi [UNKN ] Undocumented argument [int]
2492  * Arg:         stopj [UNKN ] Undocumented argument [int]
2493  *
2494  */
init_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int stopi,int stopj)2495 void init_hidden_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int stopi,int stopj)
2496 {
2497     register int i;
2498     register int j;
2499     register int hiddenj;
2500 
2501 
2502     hiddenj = startj;
2503     for(j=(startj-1);j<=stopj;j++)   {
2504       for(i=(starti-1);i<=stopi;i++) {
2505         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH55) = NEGI;
2506 
2507         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH65) = NEGI;
2508 
2509         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH75) = NEGI;
2510 
2511         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH85) = NEGI;
2512 
2513         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,MATCH95) = NEGI;
2514 
2515         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
2516 
2517         BigDnaMatchBlock_HIDDEN_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
2518 
2519         }
2520       }
2521 
2522 
2523     return;
2524 }
2525 
2526 
2527 /* Function:  full_dc_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,out,donej,totalj,dpenv)
2528  *
2529  * Descrip:    The main divide-and-conquor routine. Basically, call /PackAln_calculate_small_BigDnaMatchBlock
2530  *             Not this function, which is pretty hard core.
2531  *             Function is given start/end points (in main matrix) for alignment
2532  *             It does some checks, decides whether start/end in j is small enough for explicit calc
2533  *               - if yes, calculates it, reads off into PackAln (out), adds the j distance to donej and returns TRUE
2534  *               - if no,  uses /do_dc_single_pass_BigDnaMatchBlock to get mid-point
2535  *                          saves midpoint, and calls itself to do right portion then left portion
2536  *             right then left ensures PackAln is added the 'right' way, ie, back-to-front
2537  *             returns FALSE on any error, with a warning
2538  *
2539  *
2540  * Arg:               mat [UNKN ] Matrix with small memory implementation [BigDnaMatchBlock *]
2541  * Arg:            starti [UNKN ] Start position in i [int]
2542  * Arg:            startj [UNKN ] Start position in j [int]
2543  * Arg:        startstate [UNKN ] Start position state number [int]
2544  * Arg:             stopi [UNKN ] Stop position in i [int]
2545  * Arg:             stopj [UNKN ] Stop position in j [int]
2546  * Arg:         stopstate [UNKN ] Stop position state number [int]
2547  * Arg:               out [UNKN ] PackAln structure to put alignment into [PackAln *]
2548  * Arg:             donej [UNKN ] pointer to a number with the amount of alignment done [int *]
2549  * Arg:            totalj [UNKN ] total amount of alignment to do (in j coordinates) [int]
2550  * Arg:             dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2551  *
2552  * Return [UNKN ]  Undocumented return value [boolean]
2553  *
2554  */
full_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv)2555 boolean full_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,PackAln * out,int * donej,int totalj,DPEnvelope * dpenv)
2556 {
2557     int lstarti;
2558     int lstartj;
2559     int lstate;
2560 
2561 
2562     if( mat->basematrix->type != BASEMATRIX_TYPE_SHADOW) {
2563       warn("*Very* bad error! - non shadow matrix type in full_dc_BigDnaMatchBlock");
2564       return FALSE;
2565       }
2566 
2567 
2568     if( starti == -1 || startj == -1 || startstate == -1 || stopi == -1 || stopstate == -1)  {
2569       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);
2570       return FALSE;
2571       }
2572 
2573 
2574     if( stopj - startj < 5)  {
2575       log_full_error(REPORT,0,"[%d,%d][%d,%d] Explicit read off",starti,startj,stopi,stopj);/* Build hidden explicit matrix */
2576       calculate_hidden_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv);
2577       *donej += (stopj - startj);   /* Now read it off into out */
2578       if( read_hidden_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,out) == FALSE) {
2579         warn("In full dc, at %d:%d,%d:%d got a bad hidden explicit read off... ",starti,startj,stopi,stopj);
2580         return FALSE;
2581         }
2582       return TRUE;
2583       }
2584 
2585 
2586 /* In actual divide and conquor */
2587     if( do_dc_single_pass_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,(int)(*donej*100)/totalj) == FALSE)  {
2588       warn("In divide and conquor for BigDnaMatchBlock, at bound %d:%d to %d:%d, unable to calculate midpoint. Problem!",starti,startj,stopi,stopj);
2589       return FALSE;
2590       }
2591 
2592 
2593 /* Ok... now we have to call on each side of the matrix */
2594 /* We have to retrieve left hand side positions, as they will be vapped by the time we call LHS */
2595     lstarti= BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,0);
2596     lstartj= BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,1);
2597     lstate = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,2);
2598 
2599 
2600 /* Call on right hand side: this lets us do the correct read off */
2601     if( full_dc_BigDnaMatchBlock(mat,BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,3),BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,4),BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,stopi,stopj,stopstate,5),stopi,stopj,stopstate,out,donej,totalj,dpenv) == FALSE)   {
2602 /* Warning already issued, simply chained back up to top */
2603       return FALSE;
2604       }
2605 /* Call on left hand side */
2606     if( full_dc_BigDnaMatchBlock(mat,starti,startj,startstate,lstarti,lstartj,lstate,out,donej,totalj,dpenv) == FALSE)   {
2607 /* Warning already issued, simply chained back up to top */
2608       return FALSE;
2609       }
2610 
2611 
2612     return TRUE;
2613 }
2614 
2615 
2616 /* Function:  do_dc_single_pass_BigDnaMatchBlock(mat,starti,startj,startstate,stopi,stopj,stopstate,dpenv,perc_done)
2617  *
2618  * Descrip: No Description
2619  *
2620  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2621  * Arg:            starti [UNKN ] Undocumented argument [int]
2622  * Arg:            startj [UNKN ] Undocumented argument [int]
2623  * Arg:        startstate [UNKN ] Undocumented argument [int]
2624  * Arg:             stopi [UNKN ] Undocumented argument [int]
2625  * Arg:             stopj [UNKN ] Undocumented argument [int]
2626  * Arg:         stopstate [UNKN ] Undocumented argument [int]
2627  * Arg:             dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2628  * Arg:         perc_done [UNKN ] Undocumented argument [int]
2629  *
2630  * Return [UNKN ]  Undocumented return value [boolean]
2631  *
2632  */
do_dc_single_pass_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done)2633 boolean do_dc_single_pass_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int startj,int startstate,int stopi,int stopj,int stopstate,DPEnvelope * dpenv,int perc_done)
2634 {
2635     int halfj;
2636     halfj = startj + ((stopj - startj)/2);
2637 
2638 
2639     init_dc_BigDnaMatchBlock(mat);
2640 
2641 
2642     BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,starti,startj,startstate) = 0;
2643     run_up_dc_BigDnaMatchBlock(mat,starti,stopi,startj,halfj-1,dpenv,perc_done);
2644     push_dc_at_merge_BigDnaMatchBlock(mat,starti,stopi,halfj,&halfj,dpenv);
2645     follow_on_dc_BigDnaMatchBlock(mat,starti,stopi,halfj,stopj,dpenv,perc_done);
2646     return TRUE;
2647 }
2648 
2649 
2650 /* Function:  push_dc_at_merge_BigDnaMatchBlock(mat,starti,stopi,startj,stopj,dpenv)
2651  *
2652  * Descrip: No Description
2653  *
2654  * Arg:           mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
2655  * Arg:        starti [UNKN ] Undocumented argument [int]
2656  * Arg:         stopi [UNKN ] Undocumented argument [int]
2657  * Arg:        startj [UNKN ] Undocumented argument [int]
2658  * Arg:         stopj [UNKN ] Undocumented argument [int *]
2659  * Arg:         dpenv [UNKN ] Undocumented argument [DPEnvelope *]
2660  *
2661  */
push_dc_at_merge_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv)2662 void push_dc_at_merge_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int * stopj,DPEnvelope * dpenv)
2663 {
2664     register int i;
2665     register int j;
2666     register int k;
2667     register int count;
2668     register int mergej;/* Sources below this j will be stamped by triples */
2669     register int score;
2670     register int temp;
2671 
2672 
2673     mergej = startj -1;
2674     for(count=0,j=startj;count<1;count++,j++)    {
2675       for(i=starti;i<=stopi;i++) {
2676         if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE )  { /*Is not in envelope*/
2677           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
2678           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = (-100);
2679           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,1) = (-100);
2680           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
2681           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = (-100);
2682           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,1) = (-100);
2683           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
2684           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = (-100);
2685           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,1) = (-100);
2686           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
2687           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = (-100);
2688           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,1) = (-100);
2689           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
2690           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = (-100);
2691           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,1) = (-100);
2692           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
2693           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = (-100);
2694           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = (-100);
2695           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
2696           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,0) = (-100);
2697           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,1) = (-100);
2698           continue;
2699           } /* end of Is not in envelope */
2700 
2701 
2702         /* For state MATCH55, pushing when j - offj <= mergej */
2703         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2704         if( j - 1 <= mergej) {
2705           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = i-1;
2706           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,1) = j-1;
2707           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,2) = MATCH55;
2708           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,3) = i;
2709           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,4) = j;
2710           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,5) = MATCH55;
2711           }
2712         else {
2713           for(k=0;k<7;k++)
2714             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH55,k);
2715           }
2716 
2717 
2718         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
2719         if( temp > score)    {
2720           score = temp;
2721 
2722 
2723           if( j - 1 <= mergej)   {
2724             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = i-0;
2725             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,1) = j-1;
2726             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,2) = MATCH55;
2727             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,3) = i;
2728             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,4) = j;
2729             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,5) = MATCH55;
2730             }
2731           else   {
2732             for(k=0;k<7;k++)
2733               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH55,k);
2734             }
2735           }
2736 
2737 
2738         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
2739         if( temp > score)    {
2740           score = temp;
2741 
2742 
2743           if( j - 0 <= mergej)   {
2744             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = i-1;
2745             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,1) = j-0;
2746             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,2) = MATCH55;
2747             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,3) = i;
2748             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,4) = j;
2749             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,5) = MATCH55;
2750             }
2751           else   {
2752             for(k=0;k<7;k++)
2753               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,k);
2754             }
2755           }
2756 
2757 
2758         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2759         if( temp > score)    {
2760           score = temp;
2761 
2762 
2763           if( j - 1 <= mergej)   {
2764             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = i-1;
2765             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,1) = j-1;
2766             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,2) = UNMATCHED_TARGET;
2767             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,3) = i;
2768             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,4) = j;
2769             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,5) = MATCH55;
2770             }
2771           else   {
2772             for(k=0;k<7;k++)
2773               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
2774             }
2775           }
2776         /* Add any movement independant score */
2777         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = score;
2778         /* Finished with state MATCH55 */
2779 
2780 
2781         /* For state MATCH65, pushing when j - offj <= mergej */
2782         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2783         if( j - 1 <= mergej) {
2784           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = i-1;
2785           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,1) = j-1;
2786           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,2) = MATCH65;
2787           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,3) = i;
2788           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,4) = j;
2789           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,5) = MATCH65;
2790           }
2791         else {
2792           for(k=0;k<7;k++)
2793             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH65,k);
2794           }
2795 
2796 
2797         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
2798         if( temp > score)    {
2799           score = temp;
2800 
2801 
2802           if( j - 1 <= mergej)   {
2803             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = i-0;
2804             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,1) = j-1;
2805             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,2) = MATCH65;
2806             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,3) = i;
2807             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,4) = j;
2808             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,5) = MATCH65;
2809             }
2810           else   {
2811             for(k=0;k<7;k++)
2812               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH65,k);
2813             }
2814           }
2815 
2816 
2817         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
2818         if( temp > score)    {
2819           score = temp;
2820 
2821 
2822           if( j - 0 <= mergej)   {
2823             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = i-1;
2824             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,1) = j-0;
2825             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,2) = MATCH65;
2826             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,3) = i;
2827             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,4) = j;
2828             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,5) = MATCH65;
2829             }
2830           else   {
2831             for(k=0;k<7;k++)
2832               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,k);
2833             }
2834           }
2835 
2836 
2837         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2838         if( temp > score)    {
2839           score = temp;
2840 
2841 
2842           if( j - 1 <= mergej)   {
2843             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = i-1;
2844             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,1) = j-1;
2845             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,2) = UNMATCHED_TARGET;
2846             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,3) = i;
2847             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,4) = j;
2848             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,5) = MATCH65;
2849             }
2850           else   {
2851             for(k=0;k<7;k++)
2852               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
2853             }
2854           }
2855         /* Add any movement independant score */
2856         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = score;
2857         /* Finished with state MATCH65 */
2858 
2859 
2860         /* For state MATCH75, pushing when j - offj <= mergej */
2861         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2862         if( j - 1 <= mergej) {
2863           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = i-1;
2864           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,1) = j-1;
2865           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,2) = MATCH75;
2866           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,3) = i;
2867           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,4) = j;
2868           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,5) = MATCH75;
2869           }
2870         else {
2871           for(k=0;k<7;k++)
2872             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH75,k);
2873           }
2874 
2875 
2876         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
2877         if( temp > score)    {
2878           score = temp;
2879 
2880 
2881           if( j - 1 <= mergej)   {
2882             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = i-0;
2883             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,1) = j-1;
2884             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,2) = MATCH75;
2885             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,3) = i;
2886             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,4) = j;
2887             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,5) = MATCH75;
2888             }
2889           else   {
2890             for(k=0;k<7;k++)
2891               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH75,k);
2892             }
2893           }
2894 
2895 
2896         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
2897         if( temp > score)    {
2898           score = temp;
2899 
2900 
2901           if( j - 0 <= mergej)   {
2902             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = i-1;
2903             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,1) = j-0;
2904             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,2) = MATCH75;
2905             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,3) = i;
2906             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,4) = j;
2907             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,5) = MATCH75;
2908             }
2909           else   {
2910             for(k=0;k<7;k++)
2911               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,k);
2912             }
2913           }
2914 
2915 
2916         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2917         if( temp > score)    {
2918           score = temp;
2919 
2920 
2921           if( j - 1 <= mergej)   {
2922             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = i-1;
2923             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,1) = j-1;
2924             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,2) = UNMATCHED_TARGET;
2925             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,3) = i;
2926             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,4) = j;
2927             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,5) = MATCH75;
2928             }
2929           else   {
2930             for(k=0;k<7;k++)
2931               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
2932             }
2933           }
2934         /* Add any movement independant score */
2935         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = score;
2936         /* Finished with state MATCH75 */
2937 
2938 
2939         /* For state MATCH85, pushing when j - offj <= mergej */
2940         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
2941         if( j - 1 <= mergej) {
2942           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = i-1;
2943           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,1) = j-1;
2944           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,2) = MATCH85;
2945           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,3) = i;
2946           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,4) = j;
2947           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,5) = MATCH85;
2948           }
2949         else {
2950           for(k=0;k<7;k++)
2951             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH85,k);
2952           }
2953 
2954 
2955         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
2956         if( temp > score)    {
2957           score = temp;
2958 
2959 
2960           if( j - 1 <= mergej)   {
2961             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = i-0;
2962             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,1) = j-1;
2963             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,2) = MATCH85;
2964             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,3) = i;
2965             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,4) = j;
2966             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,5) = MATCH85;
2967             }
2968           else   {
2969             for(k=0;k<7;k++)
2970               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH85,k);
2971             }
2972           }
2973 
2974 
2975         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
2976         if( temp > score)    {
2977           score = temp;
2978 
2979 
2980           if( j - 0 <= mergej)   {
2981             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = i-1;
2982             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,1) = j-0;
2983             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,2) = MATCH85;
2984             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,3) = i;
2985             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,4) = j;
2986             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,5) = MATCH85;
2987             }
2988           else   {
2989             for(k=0;k<7;k++)
2990               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,k);
2991             }
2992           }
2993 
2994 
2995         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
2996         if( temp > score)    {
2997           score = temp;
2998 
2999 
3000           if( j - 1 <= mergej)   {
3001             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = i-1;
3002             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,1) = j-1;
3003             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,2) = UNMATCHED_TARGET;
3004             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,3) = i;
3005             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,4) = j;
3006             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,5) = MATCH85;
3007             }
3008           else   {
3009             for(k=0;k<7;k++)
3010               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3011             }
3012           }
3013         /* Add any movement independant score */
3014         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = score;
3015         /* Finished with state MATCH85 */
3016 
3017 
3018         /* For state MATCH95, pushing when j - offj <= mergej */
3019         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3020         if( j - 1 <= mergej) {
3021           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = i-1;
3022           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,1) = j-1;
3023           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,2) = MATCH95;
3024           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,3) = i;
3025           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,4) = j;
3026           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,5) = MATCH95;
3027           }
3028         else {
3029           for(k=0;k<7;k++)
3030             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH95,k);
3031           }
3032 
3033 
3034         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
3035         if( temp > score)    {
3036           score = temp;
3037 
3038 
3039           if( j - 1 <= mergej)   {
3040             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = i-0;
3041             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,1) = j-1;
3042             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,2) = MATCH95;
3043             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,3) = i;
3044             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,4) = j;
3045             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,5) = MATCH95;
3046             }
3047           else   {
3048             for(k=0;k<7;k++)
3049               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH95,k);
3050             }
3051           }
3052 
3053 
3054         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
3055         if( temp > score)    {
3056           score = temp;
3057 
3058 
3059           if( j - 0 <= mergej)   {
3060             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = i-1;
3061             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,1) = j-0;
3062             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,2) = MATCH95;
3063             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,3) = i;
3064             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,4) = j;
3065             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,5) = MATCH95;
3066             }
3067           else   {
3068             for(k=0;k<7;k++)
3069               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,k);
3070             }
3071           }
3072 
3073 
3074         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3075         if( temp > score)    {
3076           score = temp;
3077 
3078 
3079           if( j - 1 <= mergej)   {
3080             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = i-1;
3081             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,1) = j-1;
3082             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,2) = UNMATCHED_TARGET;
3083             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,3) = i;
3084             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,4) = j;
3085             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,5) = MATCH95;
3086             }
3087           else   {
3088             for(k=0;k<7;k++)
3089               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3090             }
3091           }
3092         /* Add any movement independant score */
3093         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = score;
3094         /* Finished with state MATCH95 */
3095 
3096 
3097         /* For state UNMATCHED_QUERY, pushing when j - offj <= mergej */
3098         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
3099         if( j - 0 <= mergej) {
3100           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3101           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3102           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = MATCH55;
3103           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3104           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3105           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3106           }
3107         else {
3108           for(k=0;k<7;k++)
3109             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,k);
3110           }
3111 
3112 
3113         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
3114         if( temp > score)    {
3115           score = temp;
3116 
3117 
3118           if( j - 0 <= mergej)   {
3119             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3120             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3121             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = MATCH65;
3122             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3123             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3124             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3125             }
3126           else   {
3127             for(k=0;k<7;k++)
3128               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,k);
3129             }
3130           }
3131 
3132 
3133         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
3134         if( temp > score)    {
3135           score = temp;
3136 
3137 
3138           if( j - 0 <= mergej)   {
3139             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3140             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3141             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = MATCH75;
3142             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3143             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3144             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3145             }
3146           else   {
3147             for(k=0;k<7;k++)
3148               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,k);
3149             }
3150           }
3151 
3152 
3153         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
3154         if( temp > score)    {
3155           score = temp;
3156 
3157 
3158           if( j - 0 <= mergej)   {
3159             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3160             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3161             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = MATCH85;
3162             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3163             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3164             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3165             }
3166           else   {
3167             for(k=0;k<7;k++)
3168               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,k);
3169             }
3170           }
3171 
3172 
3173         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
3174         if( temp > score)    {
3175           score = temp;
3176 
3177 
3178           if( j - 0 <= mergej)   {
3179             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3180             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3181             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = MATCH95;
3182             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3183             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3184             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3185             }
3186           else   {
3187             for(k=0;k<7;k++)
3188               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,k);
3189             }
3190           }
3191 
3192 
3193         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
3194         if( temp > score)    {
3195           score = temp;
3196 
3197 
3198           if( j - 0 <= mergej)   {
3199             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = i-1;
3200             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,1) = j-0;
3201             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,2) = UNMATCHED_QUERY;
3202             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,3) = i;
3203             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,4) = j;
3204             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,5) = UNMATCHED_QUERY;
3205             }
3206           else   {
3207             for(k=0;k<7;k++)
3208               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED_QUERY,k);
3209             }
3210           }
3211         /* Add any movement independant score */
3212         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
3213         /* Finished with state UNMATCHED_QUERY */
3214 
3215 
3216         /* For state UNMATCHED_TARGET, pushing when j - offj <= mergej */
3217         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
3218         if( j - 1 <= mergej) {
3219           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,0) = i-0;
3220           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,1) = j-1;
3221           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,2) = UNMATCHED_QUERY;
3222           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,3) = i;
3223           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,4) = j;
3224           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,5) = UNMATCHED_TARGET;
3225           }
3226         else {
3227           for(k=0;k<7;k++)
3228             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_QUERY,k);
3229           }
3230 
3231 
3232         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
3233         if( temp > score)    {
3234           score = temp;
3235 
3236 
3237           if( j - 1 <= mergej)   {
3238             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,0) = i-0;
3239             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,1) = j-1;
3240             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,2) = UNMATCHED_TARGET;
3241             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,3) = i;
3242             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,4) = j;
3243             BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,5) = UNMATCHED_TARGET;
3244             }
3245           else   {
3246             for(k=0;k<7;k++)
3247               BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k) = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_TARGET,k);
3248             }
3249           }
3250         /* Add any movement independant score */
3251         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
3252         /* Finished with state UNMATCHED_TARGET */
3253         }
3254       }
3255     /* Put back j into * stop j so that calling function gets it correct */
3256     if( stopj == NULL)
3257       warn("Bad news... NULL stopj pointer in push dc function. This means that calling function does not know how many cells I have done!");
3258     else
3259       *stopj = j;
3260 
3261 
3262     return;
3263 }
3264 
3265 
3266 /* Function:  follow_on_dc_BigDnaMatchBlock(mat,starti,stopi,startj,stopj,dpenv,perc_done)
3267  *
3268  * Descrip: No Description
3269  *
3270  * Arg:              mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
3271  * Arg:           starti [UNKN ] Undocumented argument [int]
3272  * Arg:            stopi [UNKN ] Undocumented argument [int]
3273  * Arg:           startj [UNKN ] Undocumented argument [int]
3274  * Arg:            stopj [UNKN ] Undocumented argument [int]
3275  * Arg:            dpenv [UNKN ] Undocumented argument [DPEnvelope *]
3276  * Arg:        perc_done [UNKN ] Undocumented argument [int]
3277  *
3278  */
follow_on_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)3279 void follow_on_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)
3280 {
3281     int i;
3282     int j;
3283     int k;
3284     int score;
3285     int temp;
3286     int localshadow[7];
3287     long int total;
3288     long int num;
3289 
3290 
3291     total = (stopi - starti+1) * (stopj - startj+1);
3292     num = 0;
3293 
3294 
3295     for(j=startj;j<=stopj;j++)   { /*for each valid j column*/
3296       for(i=starti;i<=stopi;i++) { /*this is strip*/
3297         num++;
3298         if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE )  { /*Is not in envelope*/
3299           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
3300           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
3301           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
3302           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
3303           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
3304           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
3305           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
3306           continue;
3307           } /* end of Is not in envelope */
3308         if( num % 1000 == 0 )
3309           log_full_error(REPORT,0,"[%d%%%% done]After  mid-j %5d Cells done %d%%%%",perc_done,startj,(num*100)/total);
3310 
3311 
3312         /* For state MATCH55 */
3313         /* setting first movement to score */
3314         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3315         /* shift first shadow numbers */
3316         for(k=0;k<7;k++)
3317           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH55,k);
3318         /* From state MATCH55 to state MATCH55 */
3319         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
3320         if( temp  > score )  {
3321           score = temp;
3322           for(k=0;k<7;k++)
3323             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH55,k);
3324           }
3325         /* From state MATCH55 to state MATCH55 */
3326         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
3327         if( temp  > score )  {
3328           score = temp;
3329           for(k=0;k<7;k++)
3330             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,k);
3331           }
3332         /* From state UNMATCHED_TARGET to state MATCH55 */
3333         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3334         if( temp  > score )  {
3335           score = temp;
3336           for(k=0;k<7;k++)
3337             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3338           }
3339 
3340 
3341         /* Ok - finished max calculation for MATCH55 */
3342         /* Add any movement independant score and put away */
3343          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = score;
3344         for(k=0;k<7;k++)
3345           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = localshadow[k];
3346         /* Now figure out if any specials need this score */
3347         /* Finished calculating state MATCH55 */
3348 
3349 
3350         /* For state MATCH65 */
3351         /* setting first movement to score */
3352         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3353         /* shift first shadow numbers */
3354         for(k=0;k<7;k++)
3355           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH65,k);
3356         /* From state MATCH65 to state MATCH65 */
3357         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
3358         if( temp  > score )  {
3359           score = temp;
3360           for(k=0;k<7;k++)
3361             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH65,k);
3362           }
3363         /* From state MATCH65 to state MATCH65 */
3364         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
3365         if( temp  > score )  {
3366           score = temp;
3367           for(k=0;k<7;k++)
3368             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,k);
3369           }
3370         /* From state UNMATCHED_TARGET to state MATCH65 */
3371         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3372         if( temp  > score )  {
3373           score = temp;
3374           for(k=0;k<7;k++)
3375             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3376           }
3377 
3378 
3379         /* Ok - finished max calculation for MATCH65 */
3380         /* Add any movement independant score and put away */
3381          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = score;
3382         for(k=0;k<7;k++)
3383           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = localshadow[k];
3384         /* Now figure out if any specials need this score */
3385         /* Finished calculating state MATCH65 */
3386 
3387 
3388         /* For state MATCH75 */
3389         /* setting first movement to score */
3390         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3391         /* shift first shadow numbers */
3392         for(k=0;k<7;k++)
3393           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH75,k);
3394         /* From state MATCH75 to state MATCH75 */
3395         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
3396         if( temp  > score )  {
3397           score = temp;
3398           for(k=0;k<7;k++)
3399             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH75,k);
3400           }
3401         /* From state MATCH75 to state MATCH75 */
3402         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
3403         if( temp  > score )  {
3404           score = temp;
3405           for(k=0;k<7;k++)
3406             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,k);
3407           }
3408         /* From state UNMATCHED_TARGET to state MATCH75 */
3409         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3410         if( temp  > score )  {
3411           score = temp;
3412           for(k=0;k<7;k++)
3413             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3414           }
3415 
3416 
3417         /* Ok - finished max calculation for MATCH75 */
3418         /* Add any movement independant score and put away */
3419          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = score;
3420         for(k=0;k<7;k++)
3421           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = localshadow[k];
3422         /* Now figure out if any specials need this score */
3423         /* Finished calculating state MATCH75 */
3424 
3425 
3426         /* For state MATCH85 */
3427         /* setting first movement to score */
3428         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3429         /* shift first shadow numbers */
3430         for(k=0;k<7;k++)
3431           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH85,k);
3432         /* From state MATCH85 to state MATCH85 */
3433         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
3434         if( temp  > score )  {
3435           score = temp;
3436           for(k=0;k<7;k++)
3437             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH85,k);
3438           }
3439         /* From state MATCH85 to state MATCH85 */
3440         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
3441         if( temp  > score )  {
3442           score = temp;
3443           for(k=0;k<7;k++)
3444             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,k);
3445           }
3446         /* From state UNMATCHED_TARGET to state MATCH85 */
3447         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3448         if( temp  > score )  {
3449           score = temp;
3450           for(k=0;k<7;k++)
3451             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3452           }
3453 
3454 
3455         /* Ok - finished max calculation for MATCH85 */
3456         /* Add any movement independant score and put away */
3457          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = score;
3458         for(k=0;k<7;k++)
3459           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = localshadow[k];
3460         /* Now figure out if any specials need this score */
3461         /* Finished calculating state MATCH85 */
3462 
3463 
3464         /* For state MATCH95 */
3465         /* setting first movement to score */
3466         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3467         /* shift first shadow numbers */
3468         for(k=0;k<7;k++)
3469           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH95,k);
3470         /* From state MATCH95 to state MATCH95 */
3471         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
3472         if( temp  > score )  {
3473           score = temp;
3474           for(k=0;k<7;k++)
3475             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH95,k);
3476           }
3477         /* From state MATCH95 to state MATCH95 */
3478         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
3479         if( temp  > score )  {
3480           score = temp;
3481           for(k=0;k<7;k++)
3482             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,k);
3483           }
3484         /* From state UNMATCHED_TARGET to state MATCH95 */
3485         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3486         if( temp  > score )  {
3487           score = temp;
3488           for(k=0;k<7;k++)
3489             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,k);
3490           }
3491 
3492 
3493         /* Ok - finished max calculation for MATCH95 */
3494         /* Add any movement independant score and put away */
3495          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = score;
3496         for(k=0;k<7;k++)
3497           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = localshadow[k];
3498         /* Now figure out if any specials need this score */
3499         /* Finished calculating state MATCH95 */
3500 
3501 
3502         /* For state UNMATCHED_QUERY */
3503         /* setting first movement to score */
3504         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
3505         /* shift first shadow numbers */
3506         for(k=0;k<7;k++)
3507           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,k);
3508         /* From state MATCH65 to state UNMATCHED_QUERY */
3509         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
3510         if( temp  > score )  {
3511           score = temp;
3512           for(k=0;k<7;k++)
3513             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,k);
3514           }
3515         /* From state MATCH75 to state UNMATCHED_QUERY */
3516         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
3517         if( temp  > score )  {
3518           score = temp;
3519           for(k=0;k<7;k++)
3520             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,k);
3521           }
3522         /* From state MATCH85 to state UNMATCHED_QUERY */
3523         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
3524         if( temp  > score )  {
3525           score = temp;
3526           for(k=0;k<7;k++)
3527             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,k);
3528           }
3529         /* From state MATCH95 to state UNMATCHED_QUERY */
3530         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
3531         if( temp  > score )  {
3532           score = temp;
3533           for(k=0;k<7;k++)
3534             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,k);
3535           }
3536         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
3537         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
3538         if( temp  > score )  {
3539           score = temp;
3540           for(k=0;k<7;k++)
3541             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED_QUERY,k);
3542           }
3543 
3544 
3545         /* Ok - finished max calculation for UNMATCHED_QUERY */
3546         /* Add any movement independant score and put away */
3547          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
3548         for(k=0;k<7;k++)
3549           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = localshadow[k];
3550         /* Now figure out if any specials need this score */
3551         /* Finished calculating state UNMATCHED_QUERY */
3552 
3553 
3554         /* For state UNMATCHED_TARGET */
3555         /* setting first movement to score */
3556         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
3557         /* shift first shadow numbers */
3558         for(k=0;k<7;k++)
3559           localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_QUERY,k);
3560         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
3561         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
3562         if( temp  > score )  {
3563           score = temp;
3564           for(k=0;k<7;k++)
3565             localshadow[k] = BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_TARGET,k);
3566           }
3567 
3568 
3569         /* Ok - finished max calculation for UNMATCHED_TARGET */
3570         /* Add any movement independant score and put away */
3571          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
3572         for(k=0;k<7;k++)
3573           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k) = localshadow[k];
3574         /* Now figure out if any specials need this score */
3575         /* Finished calculating state UNMATCHED_TARGET */
3576         } /* end of this is strip */
3577       } /* end of for each valid j column */
3578 
3579 
3580 /* Function:  run_up_dc_BigDnaMatchBlock(mat,starti,stopi,startj,stopj,dpenv,perc_done)
3581  *
3582  * Descrip: No Description
3583  *
3584  * Arg:              mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
3585  * Arg:           starti [UNKN ] Undocumented argument [int]
3586  * Arg:            stopi [UNKN ] Undocumented argument [int]
3587  * Arg:           startj [UNKN ] Undocumented argument [int]
3588  * Arg:            stopj [UNKN ] Undocumented argument [int]
3589  * Arg:            dpenv [UNKN ] Undocumented argument [DPEnvelope *]
3590  * Arg:        perc_done [UNKN ] Undocumented argument [int]
3591  *
3592  */
3593 }
run_up_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)3594 void run_up_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,DPEnvelope * dpenv,int perc_done)
3595 {
3596     register int i;
3597     register int j;
3598     register int score;
3599     register int temp;
3600     long int total;
3601     long int num;
3602 
3603 
3604     total = (stopi - starti+1) * (stopj - startj+1);
3605     if( total <= 0 )
3606       total = 1;
3607     num = 0;
3608 
3609 
3610     for(j=startj;j<=stopj;j++)   { /*for each valid j column*/
3611       for(i=starti;i<=stopi;i++) { /*this is strip*/
3612         if( j == startj && i == starti)
3613           continue;
3614         num++;
3615         if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE )  { /*Is not in envelope*/
3616           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
3617           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
3618           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
3619           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
3620           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
3621           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
3622           BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
3623           continue;
3624           } /* end of Is not in envelope */
3625         if( num % 1000 == 0 )
3626           log_full_error(REPORT,0,"[%d%%%% done]Before mid-j %5d Cells done %d%%%%",perc_done,stopj,(num*100)/total);
3627 
3628 
3629         /* For state MATCH55 */
3630         /* setting first movement to score */
3631         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3632         /* From state MATCH55 to state MATCH55 */
3633         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
3634         if( temp  > score )  {
3635           score = temp;
3636           }
3637         /* From state MATCH55 to state MATCH55 */
3638         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
3639         if( temp  > score )  {
3640           score = temp;
3641           }
3642         /* From state UNMATCHED_TARGET to state MATCH55 */
3643         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3644         if( temp  > score )  {
3645           score = temp;
3646           }
3647 
3648 
3649         /* Ok - finished max calculation for MATCH55 */
3650         /* Add any movement independant score and put away */
3651          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = score;
3652         /* Finished calculating state MATCH55 */
3653 
3654 
3655         /* For state MATCH65 */
3656         /* setting first movement to score */
3657         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3658         /* From state MATCH65 to state MATCH65 */
3659         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
3660         if( temp  > score )  {
3661           score = temp;
3662           }
3663         /* From state MATCH65 to state MATCH65 */
3664         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
3665         if( temp  > score )  {
3666           score = temp;
3667           }
3668         /* From state UNMATCHED_TARGET to state MATCH65 */
3669         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3670         if( temp  > score )  {
3671           score = temp;
3672           }
3673 
3674 
3675         /* Ok - finished max calculation for MATCH65 */
3676         /* Add any movement independant score and put away */
3677          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = score;
3678         /* Finished calculating state MATCH65 */
3679 
3680 
3681         /* For state MATCH75 */
3682         /* setting first movement to score */
3683         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3684         /* From state MATCH75 to state MATCH75 */
3685         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
3686         if( temp  > score )  {
3687           score = temp;
3688           }
3689         /* From state MATCH75 to state MATCH75 */
3690         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
3691         if( temp  > score )  {
3692           score = temp;
3693           }
3694         /* From state UNMATCHED_TARGET to state MATCH75 */
3695         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3696         if( temp  > score )  {
3697           score = temp;
3698           }
3699 
3700 
3701         /* Ok - finished max calculation for MATCH75 */
3702         /* Add any movement independant score and put away */
3703          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = score;
3704         /* Finished calculating state MATCH75 */
3705 
3706 
3707         /* For state MATCH85 */
3708         /* setting first movement to score */
3709         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3710         /* From state MATCH85 to state MATCH85 */
3711         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
3712         if( temp  > score )  {
3713           score = temp;
3714           }
3715         /* From state MATCH85 to state MATCH85 */
3716         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
3717         if( temp  > score )  {
3718           score = temp;
3719           }
3720         /* From state UNMATCHED_TARGET to state MATCH85 */
3721         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3722         if( temp  > score )  {
3723           score = temp;
3724           }
3725 
3726 
3727         /* Ok - finished max calculation for MATCH85 */
3728         /* Add any movement independant score and put away */
3729          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = score;
3730         /* Finished calculating state MATCH85 */
3731 
3732 
3733         /* For state MATCH95 */
3734         /* setting first movement to score */
3735         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
3736         /* From state MATCH95 to state MATCH95 */
3737         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
3738         if( temp  > score )  {
3739           score = temp;
3740           }
3741         /* From state MATCH95 to state MATCH95 */
3742         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
3743         if( temp  > score )  {
3744           score = temp;
3745           }
3746         /* From state UNMATCHED_TARGET to state MATCH95 */
3747         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
3748         if( temp  > score )  {
3749           score = temp;
3750           }
3751 
3752 
3753         /* Ok - finished max calculation for MATCH95 */
3754         /* Add any movement independant score and put away */
3755          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = score;
3756         /* Finished calculating state MATCH95 */
3757 
3758 
3759         /* For state UNMATCHED_QUERY */
3760         /* setting first movement to score */
3761         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
3762         /* From state MATCH65 to state UNMATCHED_QUERY */
3763         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
3764         if( temp  > score )  {
3765           score = temp;
3766           }
3767         /* From state MATCH75 to state UNMATCHED_QUERY */
3768         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
3769         if( temp  > score )  {
3770           score = temp;
3771           }
3772         /* From state MATCH85 to state UNMATCHED_QUERY */
3773         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
3774         if( temp  > score )  {
3775           score = temp;
3776           }
3777         /* From state MATCH95 to state UNMATCHED_QUERY */
3778         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
3779         if( temp  > score )  {
3780           score = temp;
3781           }
3782         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
3783         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
3784         if( temp  > score )  {
3785           score = temp;
3786           }
3787 
3788 
3789         /* Ok - finished max calculation for UNMATCHED_QUERY */
3790         /* Add any movement independant score and put away */
3791          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
3792         /* Finished calculating state UNMATCHED_QUERY */
3793 
3794 
3795         /* For state UNMATCHED_TARGET */
3796         /* setting first movement to score */
3797         score = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
3798         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
3799         temp = BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
3800         if( temp  > score )  {
3801           score = temp;
3802           }
3803 
3804 
3805         /* Ok - finished max calculation for UNMATCHED_TARGET */
3806         /* Add any movement independant score and put away */
3807          BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
3808         /* Finished calculating state UNMATCHED_TARGET */
3809         } /* end of this is strip */
3810       } /* end of for each valid j column */
3811 
3812 
3813 /* Function:  init_dc_BigDnaMatchBlock(mat)
3814  *
3815  * Descrip: No Description
3816  *
3817  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
3818  *
3819  */
3820 }
init_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat)3821 void init_dc_BigDnaMatchBlock(BigDnaMatchBlock * mat)
3822 {
3823     register int i;
3824     register int j;
3825     register int k;
3826 
3827 
3828     for(j=0;j<3;j++) {
3829       for(i=(-1);i<mat->query->seq->len;i++) {
3830         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
3831         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
3832         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
3833         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
3834         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
3835         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
3836         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
3837         for(k=0;k<7;k++) {
3838           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = (-1);
3839           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = (-1);
3840           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = (-1);
3841           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = (-1);
3842           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = (-1);
3843           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = (-1);
3844           BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k) = (-1);
3845           }
3846         }
3847       }
3848 
3849 
3850     return;
3851 }
3852 
3853 
3854 /* Function:  start_end_find_end_BigDnaMatchBlock(mat,endj)
3855  *
3856  * Descrip:    First function used to find end of the best path in the special state !end
3857  *
3858  *
3859  * Arg:         mat [UNKN ] Matrix in small mode [BigDnaMatchBlock *]
3860  * Arg:        endj [WRITE] position of end in j (meaningless in i) [int *]
3861  *
3862  * Return [UNKN ]  Undocumented return value [int]
3863  *
3864  */
start_end_find_end_BigDnaMatchBlock(BigDnaMatchBlock * mat,int * endj)3865 int start_end_find_end_BigDnaMatchBlock(BigDnaMatchBlock * mat,int * endj)
3866 {
3867     register int j;
3868     register int max;
3869     register int maxj;
3870 
3871 
3872     max = BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,mat->target->seq->len-1,END);
3873     maxj = mat->target->seq->len-1;
3874     for(j= mat->target->seq->len-2 ;j >= 0 ;j--) {
3875       if( BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,j,END) > max )    {
3876         max = BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,j,END);
3877         maxj = j;
3878         }
3879       }
3880 
3881 
3882     if( endj != NULL)
3883       *endj = maxj;
3884 
3885 
3886     return max;
3887 }
3888 
3889 
3890 /* Function:  dc_optimised_start_end_calc_BigDnaMatchBlock(*mat,dpenv)
3891  *
3892  * Descrip:    Calculates special strip, leaving start/end/score points in shadow matrix
3893  *             Works off specially laid out memory from steve searle
3894  *
3895  *
3896  * Arg:         *mat [UNKN ] Undocumented argument [BigDnaMatchBlock]
3897  * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
3898  *
3899  * Return [UNKN ]  Undocumented return value [boolean]
3900  *
3901  */
dc_optimised_start_end_calc_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)3902 boolean dc_optimised_start_end_calc_BigDnaMatchBlock(BigDnaMatchBlock *mat,DPEnvelope * dpenv)
3903 {
3904     int i;
3905     int j;
3906     int k;
3907     int score;
3908     int temp;
3909     int leni;
3910     int lenj;
3911     int localshadow[7];
3912     long int total;
3913     long int num=0;
3914     int * score_pointers;
3915     int * shadow_pointers;
3916     int * localsp;
3917     leni = mat->query->seq->len;
3918     lenj = mat->target->seq->len;
3919     total = leni * lenj;
3920 
3921 
3922     score_pointers = (int *) calloc (1 * (leni + 1) * 7,sizeof(int));
3923     shadow_pointers = (int *) calloc (1 * (leni + 1) * 7 * 8,sizeof(int));
3924 
3925 
3926     for(j=0;j<lenj;j++)  { /*for each j strip*/
3927       for(i=0;i<leni;i++)    { /*for each i position in strip*/
3928         num++;
3929         if( dpenv != NULL && is_in_DPEnvelope(dpenv,i,j) == FALSE )  { /*Is not in envelope*/
3930           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
3931           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
3932           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
3933           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
3934           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
3935           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
3936           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
3937           continue;
3938           } /* end of Is not in envelope */
3939         if( num%1000 == 0)
3940           log_full_error(REPORT,0,"%6d Cells done [%2d%%%%]",num,num*100/total);
3941 
3942 
3943 
3944 
3945         /* For state MATCH55 */
3946         /* setting first movement to score */
3947         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
3948         /* assign local shadown pointer */
3949         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH55,0));
3950         /* From state MATCH55 to state MATCH55 */
3951         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55 +(0);
3952         if( temp  > score )  {
3953           score = temp;
3954           /* assign local shadown pointer */
3955           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH55,0));
3956           }
3957         /* From state MATCH55 to state MATCH55 */
3958         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55 +(0);
3959         if( temp  > score )  {
3960           score = temp;
3961           /* assign local shadown pointer */
3962           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,0));
3963           }
3964         /* From state UNMATCHED_TARGET to state MATCH55 */
3965         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) +(0);
3966         if( temp  > score )  {
3967           score = temp;
3968           /* assign local shadown pointer */
3969           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,0));
3970           }
3971 
3972 
3973         /* Ok - finished max calculation for MATCH55 */
3974         /* Add any movement independant score and put away */
3975         /* Actually, already done inside scores */
3976          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH55) = score;
3977         for(k=0;k<7;k++)
3978           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH55,k) = localsp[k];
3979         /* Now figure out if any specials need this score */
3980 
3981 
3982         /* Finished calculating state MATCH55 */
3983 
3984 
3985         /* For state MATCH65 */
3986         /* setting first movement to score */
3987         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
3988         /* assign local shadown pointer */
3989         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH65,0));
3990         /* From state MATCH65 to state MATCH65 */
3991         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65 +(0);
3992         if( temp  > score )  {
3993           score = temp;
3994           /* assign local shadown pointer */
3995           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH65,0));
3996           }
3997         /* From state MATCH65 to state MATCH65 */
3998         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65 +(0);
3999         if( temp  > score )  {
4000           score = temp;
4001           /* assign local shadown pointer */
4002           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,0));
4003           }
4004         /* From state UNMATCHED_TARGET to state MATCH65 */
4005         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) +(0);
4006         if( temp  > score )  {
4007           score = temp;
4008           /* assign local shadown pointer */
4009           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,0));
4010           }
4011 
4012 
4013         /* Ok - finished max calculation for MATCH65 */
4014         /* Add any movement independant score and put away */
4015         /* Actually, already done inside scores */
4016          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH65) = score;
4017         for(k=0;k<7;k++)
4018           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH65,k) = localsp[k];
4019         /* Now figure out if any specials need this score */
4020 
4021 
4022         /* Finished calculating state MATCH65 */
4023 
4024 
4025         /* For state MATCH75 */
4026         /* setting first movement to score */
4027         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
4028         /* assign local shadown pointer */
4029         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH75,0));
4030         /* From state MATCH75 to state MATCH75 */
4031         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH75) + mat->g +(0);
4032         if( temp  > score )  {
4033           score = temp;
4034           /* assign local shadown pointer */
4035           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH75,0));
4036           }
4037         /* From state MATCH75 to state MATCH75 */
4038         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->g +(0);
4039         if( temp  > score )  {
4040           score = temp;
4041           /* assign local shadown pointer */
4042           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,0));
4043           }
4044         /* From state UNMATCHED_TARGET to state MATCH75 */
4045         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) +(0);
4046         if( temp  > score )  {
4047           score = temp;
4048           /* assign local shadown pointer */
4049           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,0));
4050           }
4051 
4052 
4053         /* Ok - finished max calculation for MATCH75 */
4054         /* Add any movement independant score and put away */
4055         /* Actually, already done inside scores */
4056          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH75) = score;
4057         for(k=0;k<7;k++)
4058           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH75,k) = localsp[k];
4059         /* Now figure out if any specials need this score */
4060 
4061 
4062         /* Finished calculating state MATCH75 */
4063 
4064 
4065         /* For state MATCH85 */
4066         /* setting first movement to score */
4067         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
4068         /* assign local shadown pointer */
4069         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH85,0));
4070         /* From state MATCH85 to state MATCH85 */
4071         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH85) + mat->g +(0);
4072         if( temp  > score )  {
4073           score = temp;
4074           /* assign local shadown pointer */
4075           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH85,0));
4076           }
4077         /* From state MATCH85 to state MATCH85 */
4078         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->g +(0);
4079         if( temp  > score )  {
4080           score = temp;
4081           /* assign local shadown pointer */
4082           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,0));
4083           }
4084         /* From state UNMATCHED_TARGET to state MATCH85 */
4085         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) +(0);
4086         if( temp  > score )  {
4087           score = temp;
4088           /* assign local shadown pointer */
4089           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,0));
4090           }
4091 
4092 
4093         /* Ok - finished max calculation for MATCH85 */
4094         /* Add any movement independant score and put away */
4095         /* Actually, already done inside scores */
4096          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH85) = score;
4097         for(k=0;k<7;k++)
4098           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH85,k) = localsp[k];
4099         /* Now figure out if any specials need this score */
4100 
4101 
4102         /* Finished calculating state MATCH85 */
4103 
4104 
4105         /* For state MATCH95 */
4106         /* setting first movement to score */
4107         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s) + (0);
4108         /* assign local shadown pointer */
4109         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,MATCH95,0));
4110         /* From state MATCH95 to state MATCH95 */
4111         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,MATCH95) + mat->g +(0);
4112         if( temp  > score )  {
4113           score = temp;
4114           /* assign local shadown pointer */
4115           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,MATCH95,0));
4116           }
4117         /* From state MATCH95 to state MATCH95 */
4118         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->g +(0);
4119         if( temp  > score )  {
4120           score = temp;
4121           /* assign local shadown pointer */
4122           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,0));
4123           }
4124         /* From state UNMATCHED_TARGET to state MATCH95 */
4125         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v) +(0);
4126         if( temp  > score )  {
4127           score = temp;
4128           /* assign local shadown pointer */
4129           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 1,UNMATCHED_TARGET,0));
4130           }
4131 
4132 
4133         /* Ok - finished max calculation for MATCH95 */
4134         /* Add any movement independant score and put away */
4135         /* Actually, already done inside scores */
4136          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,MATCH95) = score;
4137         for(k=0;k<7;k++)
4138           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,MATCH95,k) = localsp[k];
4139         /* Now figure out if any specials need this score */
4140 
4141 
4142         /* Finished calculating state MATCH95 */
4143 
4144 
4145         /* For state UNMATCHED_QUERY */
4146         /* setting first movement to score */
4147         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH55) + mat->b + (0);
4148         /* assign local shadown pointer */
4149         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH55,0));
4150         /* From state MATCH65 to state UNMATCHED_QUERY */
4151         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH65) + mat->b +(0);
4152         if( temp  > score )  {
4153           score = temp;
4154           /* assign local shadown pointer */
4155           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH65,0));
4156           }
4157         /* From state MATCH75 to state UNMATCHED_QUERY */
4158         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH75) + mat->b +(0);
4159         if( temp  > score )  {
4160           score = temp;
4161           /* assign local shadown pointer */
4162           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH75,0));
4163           }
4164         /* From state MATCH85 to state UNMATCHED_QUERY */
4165         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH85) + mat->b +(0);
4166         if( temp  > score )  {
4167           score = temp;
4168           /* assign local shadown pointer */
4169           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH85,0));
4170           }
4171         /* From state MATCH95 to state UNMATCHED_QUERY */
4172         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,MATCH95) + mat->b +(0);
4173         if( temp  > score )  {
4174           score = temp;
4175           /* assign local shadown pointer */
4176           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,MATCH95,0));
4177           }
4178         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
4179         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u +(0);
4180         if( temp  > score )  {
4181           score = temp;
4182           /* assign local shadown pointer */
4183           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 1,j - 0,UNMATCHED_QUERY,0));
4184           }
4185         /* From state START to state UNMATCHED_QUERY */
4186         temp = BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL(mat,i-1,j-0,START) + 0 + (0);
4187         if( temp  > score )  {
4188           score = temp;
4189           /* This state [START] is a special for UNMATCHED_QUERY... push top shadow pointers here */
4190           localshadow[0]= i;
4191           localshadow[1]= j;
4192           localshadow[2]= UNMATCHED_QUERY;
4193           localshadow[3]= (-1);
4194           localshadow[4]= (-1);
4195           localshadow[5]= (-1);
4196           localshadow[6]= score;
4197           localsp = localshadow;
4198           }
4199 
4200 
4201         /* Ok - finished max calculation for UNMATCHED_QUERY */
4202         /* Add any movement independant score and put away */
4203         /* Actually, already done inside scores */
4204          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
4205         for(k=0;k<7;k++)
4206           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,k) = localsp[k];
4207         /* Now figure out if any specials need this score */
4208 
4209 
4210         /* Finished calculating state UNMATCHED_QUERY */
4211 
4212 
4213         /* For state UNMATCHED_TARGET */
4214         /* setting first movement to score */
4215         score = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v + (0);
4216         /* assign local shadown pointer */
4217         localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_QUERY,0));
4218         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
4219         temp = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u +(0);
4220         if( temp  > score )  {
4221           score = temp;
4222           /* assign local shadown pointer */
4223           localsp = &(BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i - 0,j - 1,UNMATCHED_TARGET,0));
4224           }
4225 
4226 
4227         /* Ok - finished max calculation for UNMATCHED_TARGET */
4228         /* Add any movement independant score and put away */
4229         /* Actually, already done inside scores */
4230          BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
4231         for(k=0;k<7;k++)
4232           BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k) = localsp[k];
4233         /* Now figure out if any specials need this score */
4234 
4235 
4236         /* state UNMATCHED_TARGET is a source for special END */
4237         temp = score + (0) + (0) ;
4238         if( temp > BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) )     {
4239           BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL(mat,i,j,END) = temp;
4240           /* Have to push only bottem half of system here */
4241           for(k=0;k<3;k++)
4242             BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,k) = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,k);
4243           BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,6) = BigDnaMatchBlock_DC_OPT_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,6);
4244           BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,3) = i;
4245           BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,4) = j;
4246           BigDnaMatchBlock_DC_OPT_SHADOW_SPECIAL_SP(mat,i,j,END,5) = UNMATCHED_TARGET;
4247           }
4248 
4249 
4250 
4251 
4252         /* Finished calculating state UNMATCHED_TARGET */
4253 
4254 
4255         } /* end of for each i position in strip */
4256       } /* end of for each j strip */
4257     free(score_pointers);
4258     free(shadow_pointers);
4259     return TRUE;
4260 }
4261 
4262 
4263 /* Function:  init_start_end_linear_BigDnaMatchBlock(mat)
4264  *
4265  * Descrip: No Description
4266  *
4267  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4268  *
4269  */
init_start_end_linear_BigDnaMatchBlock(BigDnaMatchBlock * mat)4270 void init_start_end_linear_BigDnaMatchBlock(BigDnaMatchBlock * mat)
4271 {
4272     register int i;
4273     register int j;
4274     for(j=0;j<3;j++) {
4275       for(i=(-1);i<mat->query->seq->len;i++) {
4276         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH55) = NEGI;
4277         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH55,0) = (-1);
4278         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH65) = NEGI;
4279         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH65,0) = (-1);
4280         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH75) = NEGI;
4281         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH75,0) = (-1);
4282         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH85) = NEGI;
4283         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH85,0) = (-1);
4284         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,MATCH95) = NEGI;
4285         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,MATCH95,0) = (-1);
4286         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
4287         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_QUERY,0) = (-1);
4288         BigDnaMatchBlock_DC_SHADOW_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
4289         BigDnaMatchBlock_DC_SHADOW_MATRIX_SP(mat,i,j,UNMATCHED_TARGET,0) = (-1);
4290         }
4291       }
4292 
4293 
4294     for(j=(-1);j<mat->target->seq->len;j++)  {
4295       BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,j,START) = 0;
4296       BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,j,START,0) = j;
4297       BigDnaMatchBlock_DC_SHADOW_SPECIAL(mat,0,j,END) = NEGI;
4298       BigDnaMatchBlock_DC_SHADOW_SPECIAL_SP(mat,0,j,END,0) = (-1);
4299       }
4300 
4301 
4302     return;
4303 }
4304 
4305 
4306 /* Function:  convert_PackAln_to_AlnBlock_BigDnaMatchBlock(pal)
4307  *
4308  * Descrip:    Converts a path alignment to a label alignment
4309  *             The label alignment is probably much more useful than the path
4310  *
4311  *
4312  * Arg:        pal [UNKN ] Undocumented argument [PackAln *]
4313  *
4314  * Return [UNKN ]  Undocumented return value [AlnBlock *]
4315  *
4316  */
convert_PackAln_to_AlnBlock_BigDnaMatchBlock(PackAln * pal)4317 AlnBlock * convert_PackAln_to_AlnBlock_BigDnaMatchBlock(PackAln * pal)
4318 {
4319     AlnConvertSet * acs;
4320     AlnBlock * alb;
4321 
4322 
4323     acs = AlnConvertSet_BigDnaMatchBlock();
4324     alb = AlnBlock_from_PackAln(acs,pal);
4325     free_AlnConvertSet(acs);
4326     return alb;
4327 }
4328 
4329 
4330  static char * query_label[] = { "MM55","MI55","MM65","MI65","MM75","MI75","MM85","MI85","MM95","MI95","UM","UI","END" };
4331 /* Function:  AlnConvertSet_BigDnaMatchBlock(void)
4332  *
4333  * Descrip: No Description
4334  *
4335  *
4336  * Return [UNKN ]  Undocumented return value [AlnConvertSet *]
4337  *
4338  */
4339  static char * target_label[] = { "MM55","MI55","MM65","MI65","MM75","MI75","MM85","MI85","MM95","MI95","UI","UM","END" };
AlnConvertSet_BigDnaMatchBlock(void)4340 AlnConvertSet * AlnConvertSet_BigDnaMatchBlock(void)
4341 {
4342     AlnConvertUnit * acu;
4343     AlnConvertSet  * out;
4344 
4345 
4346     out = AlnConvertSet_alloc_std();
4347 
4348 
4349     acu = AlnConvertUnit_alloc();
4350     add_AlnConvertSet(out,acu);
4351     acu->state1 = MATCH55;
4352     acu->state2 = MATCH55;
4353     acu->offi = 1;
4354     acu->offj = 1;
4355     acu->label1 = query_label[0];
4356     acu->label2 = target_label[0];
4357     acu = AlnConvertUnit_alloc();
4358     add_AlnConvertSet(out,acu);
4359     acu->state1 = MATCH55;
4360     acu->state2 = MATCH55;
4361     acu->offi = 0;
4362     acu->offj = 1;
4363     acu->label1 = query_label[0];
4364     acu->label2 = target_label[1];
4365     acu = AlnConvertUnit_alloc();
4366     add_AlnConvertSet(out,acu);
4367     acu->state1 = MATCH55;
4368     acu->state2 = MATCH55;
4369     acu->offi = 1;
4370     acu->offj = 0;
4371     acu->label1 = query_label[1];
4372     acu->label2 = target_label[0];
4373     acu = AlnConvertUnit_alloc();
4374     add_AlnConvertSet(out,acu);
4375     acu->state1 = UNMATCHED_TARGET;
4376     acu->state2 = MATCH55;
4377     acu->offi = 1;
4378     acu->offj = 1;
4379     acu->label1 = query_label[0];
4380     acu->label2 = target_label[0];
4381     acu = AlnConvertUnit_alloc();
4382     add_AlnConvertSet(out,acu);
4383     acu->state1 = MATCH65;
4384     acu->state2 = MATCH65;
4385     acu->offi = 1;
4386     acu->offj = 1;
4387     acu->label1 = query_label[2];
4388     acu->label2 = target_label[2];
4389     acu = AlnConvertUnit_alloc();
4390     add_AlnConvertSet(out,acu);
4391     acu->state1 = MATCH65;
4392     acu->state2 = MATCH65;
4393     acu->offi = 0;
4394     acu->offj = 1;
4395     acu->label1 = query_label[2];
4396     acu->label2 = target_label[3];
4397     acu = AlnConvertUnit_alloc();
4398     add_AlnConvertSet(out,acu);
4399     acu->state1 = MATCH65;
4400     acu->state2 = MATCH65;
4401     acu->offi = 1;
4402     acu->offj = 0;
4403     acu->label1 = query_label[3];
4404     acu->label2 = target_label[2];
4405     acu = AlnConvertUnit_alloc();
4406     add_AlnConvertSet(out,acu);
4407     acu->state1 = UNMATCHED_TARGET;
4408     acu->state2 = MATCH65;
4409     acu->offi = 1;
4410     acu->offj = 1;
4411     acu->label1 = query_label[2];
4412     acu->label2 = target_label[2];
4413     acu = AlnConvertUnit_alloc();
4414     add_AlnConvertSet(out,acu);
4415     acu->state1 = MATCH75;
4416     acu->state2 = MATCH75;
4417     acu->offi = 1;
4418     acu->offj = 1;
4419     acu->label1 = query_label[4];
4420     acu->label2 = target_label[4];
4421     acu = AlnConvertUnit_alloc();
4422     add_AlnConvertSet(out,acu);
4423     acu->state1 = MATCH75;
4424     acu->state2 = MATCH75;
4425     acu->offi = 0;
4426     acu->offj = 1;
4427     acu->label1 = query_label[4];
4428     acu->label2 = target_label[5];
4429     acu = AlnConvertUnit_alloc();
4430     add_AlnConvertSet(out,acu);
4431     acu->state1 = MATCH75;
4432     acu->state2 = MATCH75;
4433     acu->offi = 1;
4434     acu->offj = 0;
4435     acu->label1 = query_label[5];
4436     acu->label2 = target_label[4];
4437     acu = AlnConvertUnit_alloc();
4438     add_AlnConvertSet(out,acu);
4439     acu->state1 = UNMATCHED_TARGET;
4440     acu->state2 = MATCH75;
4441     acu->offi = 1;
4442     acu->offj = 1;
4443     acu->label1 = query_label[4];
4444     acu->label2 = target_label[4];
4445     acu = AlnConvertUnit_alloc();
4446     add_AlnConvertSet(out,acu);
4447     acu->state1 = MATCH85;
4448     acu->state2 = MATCH85;
4449     acu->offi = 1;
4450     acu->offj = 1;
4451     acu->label1 = query_label[6];
4452     acu->label2 = target_label[6];
4453     acu = AlnConvertUnit_alloc();
4454     add_AlnConvertSet(out,acu);
4455     acu->state1 = MATCH85;
4456     acu->state2 = MATCH85;
4457     acu->offi = 0;
4458     acu->offj = 1;
4459     acu->label1 = query_label[6];
4460     acu->label2 = target_label[7];
4461     acu = AlnConvertUnit_alloc();
4462     add_AlnConvertSet(out,acu);
4463     acu->state1 = MATCH85;
4464     acu->state2 = MATCH85;
4465     acu->offi = 1;
4466     acu->offj = 0;
4467     acu->label1 = query_label[7];
4468     acu->label2 = target_label[6];
4469     acu = AlnConvertUnit_alloc();
4470     add_AlnConvertSet(out,acu);
4471     acu->state1 = UNMATCHED_TARGET;
4472     acu->state2 = MATCH85;
4473     acu->offi = 1;
4474     acu->offj = 1;
4475     acu->label1 = query_label[6];
4476     acu->label2 = target_label[6];
4477     acu = AlnConvertUnit_alloc();
4478     add_AlnConvertSet(out,acu);
4479     acu->state1 = MATCH95;
4480     acu->state2 = MATCH95;
4481     acu->offi = 1;
4482     acu->offj = 1;
4483     acu->label1 = query_label[8];
4484     acu->label2 = target_label[8];
4485     acu = AlnConvertUnit_alloc();
4486     add_AlnConvertSet(out,acu);
4487     acu->state1 = MATCH95;
4488     acu->state2 = MATCH95;
4489     acu->offi = 0;
4490     acu->offj = 1;
4491     acu->label1 = query_label[8];
4492     acu->label2 = target_label[9];
4493     acu = AlnConvertUnit_alloc();
4494     add_AlnConvertSet(out,acu);
4495     acu->state1 = MATCH95;
4496     acu->state2 = MATCH95;
4497     acu->offi = 1;
4498     acu->offj = 0;
4499     acu->label1 = query_label[9];
4500     acu->label2 = target_label[8];
4501     acu = AlnConvertUnit_alloc();
4502     add_AlnConvertSet(out,acu);
4503     acu->state1 = UNMATCHED_TARGET;
4504     acu->state2 = MATCH95;
4505     acu->offi = 1;
4506     acu->offj = 1;
4507     acu->label1 = query_label[8];
4508     acu->label2 = target_label[8];
4509     acu = AlnConvertUnit_alloc();
4510     add_AlnConvertSet(out,acu);
4511     acu->state1 = MATCH55;
4512     acu->state2 = UNMATCHED_QUERY;
4513     acu->offi = 1;
4514     acu->offj = 0;
4515     acu->label1 = query_label[10];
4516     acu->label2 = target_label[10];
4517     acu = AlnConvertUnit_alloc();
4518     add_AlnConvertSet(out,acu);
4519     acu->state1 = MATCH65;
4520     acu->state2 = UNMATCHED_QUERY;
4521     acu->offi = 1;
4522     acu->offj = 0;
4523     acu->label1 = query_label[10];
4524     acu->label2 = target_label[10];
4525     acu = AlnConvertUnit_alloc();
4526     add_AlnConvertSet(out,acu);
4527     acu->state1 = MATCH75;
4528     acu->state2 = UNMATCHED_QUERY;
4529     acu->offi = 1;
4530     acu->offj = 0;
4531     acu->label1 = query_label[10];
4532     acu->label2 = target_label[10];
4533     acu = AlnConvertUnit_alloc();
4534     add_AlnConvertSet(out,acu);
4535     acu->state1 = MATCH85;
4536     acu->state2 = UNMATCHED_QUERY;
4537     acu->offi = 1;
4538     acu->offj = 0;
4539     acu->label1 = query_label[10];
4540     acu->label2 = target_label[10];
4541     acu = AlnConvertUnit_alloc();
4542     add_AlnConvertSet(out,acu);
4543     acu->state1 = MATCH95;
4544     acu->state2 = UNMATCHED_QUERY;
4545     acu->offi = 1;
4546     acu->offj = 0;
4547     acu->label1 = query_label[10];
4548     acu->label2 = target_label[10];
4549     acu = AlnConvertUnit_alloc();
4550     add_AlnConvertSet(out,acu);
4551     acu->state1 = UNMATCHED_QUERY;
4552     acu->state2 = UNMATCHED_QUERY;
4553     acu->offi = 1;
4554     acu->offj = 0;
4555     acu->label1 = query_label[10];
4556     acu->label2 = target_label[10];
4557     acu = AlnConvertUnit_alloc();
4558     add_AlnConvertSet(out,acu);
4559     acu->state1 = START + 7;
4560     acu->is_from_special = TRUE;
4561     acu->state2 = UNMATCHED_QUERY;
4562     acu->offi = (-1);
4563     acu->offj = 0;
4564     acu->label1 = query_label[10];
4565     acu->label2 = target_label[10];
4566     acu = AlnConvertUnit_alloc();
4567     add_AlnConvertSet(out,acu);
4568     acu->state1 = UNMATCHED_QUERY;
4569     acu->state2 = UNMATCHED_TARGET;
4570     acu->offi = 0;
4571     acu->offj = 1;
4572     acu->label1 = query_label[11];
4573     acu->label2 = target_label[11];
4574     acu = AlnConvertUnit_alloc();
4575     add_AlnConvertSet(out,acu);
4576     acu->state1 = UNMATCHED_TARGET;
4577     acu->state2 = UNMATCHED_TARGET;
4578     acu->offi = 0;
4579     acu->offj = 1;
4580     acu->label1 = query_label[11];
4581     acu->label2 = target_label[11];
4582     acu = AlnConvertUnit_alloc();
4583     add_AlnConvertSet(out,acu);
4584     acu->state1 = UNMATCHED_TARGET;
4585     acu->state2 = END + 7;
4586     acu->offi = (-1);
4587     acu->offj = 0;
4588     acu->label1 = query_label[12];
4589     acu->label2 = target_label[12];
4590     return out;
4591 }
4592 
4593 
4594 /* Function:  PackAln_read_Expl_BigDnaMatchBlock(mat)
4595  *
4596  * Descrip:    Reads off PackAln from explicit matrix structure
4597  *
4598  *
4599  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4600  *
4601  * Return [UNKN ]  Undocumented return value [PackAln *]
4602  *
4603  */
PackAln_read_Expl_BigDnaMatchBlock(BigDnaMatchBlock * mat)4604 PackAln * PackAln_read_Expl_BigDnaMatchBlock(BigDnaMatchBlock * mat)
4605 {
4606     BigDnaMatchBlock_access_func_holder holder;
4607 
4608 
4609     holder.access_main    = BigDnaMatchBlock_explicit_access_main;
4610     holder.access_special = BigDnaMatchBlock_explicit_access_special;
4611     return PackAln_read_generic_BigDnaMatchBlock(mat,holder);
4612 }
4613 
4614 
4615 /* Function:  BigDnaMatchBlock_explicit_access_main(mat,i,j,state)
4616  *
4617  * Descrip: No Description
4618  *
4619  * Arg:          mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4620  * Arg:            i [UNKN ] Undocumented argument [int]
4621  * Arg:            j [UNKN ] Undocumented argument [int]
4622  * Arg:        state [UNKN ] Undocumented argument [int]
4623  *
4624  * Return [UNKN ]  Undocumented return value [int]
4625  *
4626  */
BigDnaMatchBlock_explicit_access_main(BigDnaMatchBlock * mat,int i,int j,int state)4627 int BigDnaMatchBlock_explicit_access_main(BigDnaMatchBlock * mat,int i,int j,int state)
4628 {
4629     return BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,state);
4630 }
4631 
4632 
4633 /* Function:  BigDnaMatchBlock_explicit_access_special(mat,i,j,state)
4634  *
4635  * Descrip: No Description
4636  *
4637  * Arg:          mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4638  * Arg:            i [UNKN ] Undocumented argument [int]
4639  * Arg:            j [UNKN ] Undocumented argument [int]
4640  * Arg:        state [UNKN ] Undocumented argument [int]
4641  *
4642  * Return [UNKN ]  Undocumented return value [int]
4643  *
4644  */
BigDnaMatchBlock_explicit_access_special(BigDnaMatchBlock * mat,int i,int j,int state)4645 int BigDnaMatchBlock_explicit_access_special(BigDnaMatchBlock * mat,int i,int j,int state)
4646 {
4647     return BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,state);
4648 }
4649 
4650 
4651 /* Function:  PackAln_read_generic_BigDnaMatchBlock(mat,h)
4652  *
4653  * Descrip:    Reads off PackAln from explicit matrix structure
4654  *
4655  *
4656  * Arg:        mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4657  * Arg:          h [UNKN ] Undocumented argument [BigDnaMatchBlock_access_func_holder]
4658  *
4659  * Return [UNKN ]  Undocumented return value [PackAln *]
4660  *
4661  */
PackAln_read_generic_BigDnaMatchBlock(BigDnaMatchBlock * mat,BigDnaMatchBlock_access_func_holder h)4662 PackAln * PackAln_read_generic_BigDnaMatchBlock(BigDnaMatchBlock * mat,BigDnaMatchBlock_access_func_holder h)
4663 {
4664     register PackAln * out;
4665     int i;
4666     int j;
4667     int state;
4668     int cellscore = (-1);
4669     boolean isspecial;
4670     PackAlnUnit * pau = NULL;
4671     PackAlnUnit * prev = NULL;
4672 
4673 
4674     assert(mat);
4675     assert(h.access_main);
4676     assert(h.access_special);
4677 
4678 
4679     out = PackAln_alloc_std();
4680     if( out == NULL )
4681       return NULL;
4682 
4683 
4684     out->score =  find_end_BigDnaMatchBlock(mat,&i,&j,&state,&isspecial,h);
4685 
4686 
4687     /* Add final end transition (at the moment we have not got the score! */
4688     if( (pau= PackAlnUnit_alloc()) == NULL  || add_PackAln(out,pau) == FALSE )   {
4689       warn("Failed the first PackAlnUnit alloc, %d length of Alignment in BigDnaMatchBlock_basic_read, returning a mess.(Sorry!)",out->len);
4690       return out;
4691       }
4692 
4693 
4694     /* Put in positions for end trans. Remember that coordinates in C style */
4695     pau->i = i;
4696     pau->j = j;
4697     if( isspecial != TRUE)
4698       pau->state = state;
4699     else pau->state = state + 7;
4700     prev=pau;
4701     while( state != START || isspecial != TRUE)  { /*while state != START*/
4702 
4703 
4704       if( isspecial == TRUE )
4705         max_calc_special_BigDnaMatchBlock(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore,h);
4706       else
4707         max_calc_BigDnaMatchBlock(mat,i,j,state,isspecial,&i,&j,&state,&isspecial,&cellscore,h);
4708       if(i == BigDnaMatchBlock_READ_OFF_ERROR || j == BigDnaMatchBlock_READ_OFF_ERROR || state == BigDnaMatchBlock_READ_OFF_ERROR )  {
4709         warn("Problem - hit bad read off system, exiting now");
4710         break;
4711         }
4712       if( (pau= PackAlnUnit_alloc()) == NULL  || add_PackAln(out,pau) == FALSE ) {
4713         warn("Failed a PackAlnUnit alloc, %d length of Alignment in BigDnaMatchBlock_basic_read, returning partial alignment",out->len);
4714         break;
4715         }
4716 
4717 
4718       /* Put in positions for block. Remember that coordinates in C style */
4719       pau->i = i;
4720       pau->j = j;
4721       if( isspecial != TRUE)
4722         pau->state = state;
4723       else pau->state = state + 7;
4724       prev->score = cellscore;
4725       prev = pau;
4726       } /* end of while state != START */
4727 
4728 
4729     invert_PackAln(out);
4730     return out;
4731 }
4732 
4733 
4734 /* Function:  find_end_BigDnaMatchBlock(mat,ri,rj,state,isspecial,h)
4735  *
4736  * Descrip: No Description
4737  *
4738  * Arg:              mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4739  * Arg:               ri [UNKN ] Undocumented argument [int *]
4740  * Arg:               rj [UNKN ] Undocumented argument [int *]
4741  * Arg:            state [UNKN ] Undocumented argument [int *]
4742  * Arg:        isspecial [UNKN ] Undocumented argument [boolean *]
4743  * Arg:                h [UNKN ] Undocumented argument [BigDnaMatchBlock_access_func_holder]
4744  *
4745  * Return [UNKN ]  Undocumented return value [int]
4746  *
4747  */
find_end_BigDnaMatchBlock(BigDnaMatchBlock * mat,int * ri,int * rj,int * state,boolean * isspecial,BigDnaMatchBlock_access_func_holder h)4748 int find_end_BigDnaMatchBlock(BigDnaMatchBlock * mat,int * ri,int * rj,int * state,boolean * isspecial,BigDnaMatchBlock_access_func_holder h)
4749 {
4750     int j;
4751     int max;
4752     int maxj;
4753     int temp;
4754 
4755 
4756     max = (*h.access_special)(mat,0,mat->target->seq->len-1,END);
4757     maxj = mat->target->seq->len-1;
4758     for(j= mat->target->seq->len-2 ;j >= 0 ;j--) {
4759       if( (temp =(*h.access_special)(mat,0,j,END)) > max )   {
4760         max = temp;
4761         maxj = j;
4762         }
4763       }
4764 
4765 
4766     if( ri != NULL)
4767        *ri = 0;
4768     if( rj != NULL)
4769        *rj = maxj;
4770     if( state != NULL)
4771        *state = END;
4772     if( isspecial != NULL)
4773        *isspecial = TRUE;
4774 
4775 
4776     return max;
4777 }
4778 
4779 
4780 /* Function:  BigDnaMatchBlock_debug_show_matrix(mat,starti,stopi,startj,stopj,ofp)
4781  *
4782  * Descrip: No Description
4783  *
4784  * Arg:           mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4785  * Arg:        starti [UNKN ] Undocumented argument [int]
4786  * Arg:         stopi [UNKN ] Undocumented argument [int]
4787  * Arg:        startj [UNKN ] Undocumented argument [int]
4788  * Arg:         stopj [UNKN ] Undocumented argument [int]
4789  * Arg:           ofp [UNKN ] Undocumented argument [FILE *]
4790  *
4791  */
BigDnaMatchBlock_debug_show_matrix(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,FILE * ofp)4792 void BigDnaMatchBlock_debug_show_matrix(BigDnaMatchBlock * mat,int starti,int stopi,int startj,int stopj,FILE * ofp)
4793 {
4794     register int i;
4795     register int j;
4796 
4797 
4798     for(i=starti;i<stopi && i < mat->query->seq->len;i++)    {
4799       for(j=startj;j<stopj && j < mat->target->seq->len;j++) {
4800         fprintf(ofp,"Cell [%d - %d]\n",i,j);
4801         fprintf(ofp,"State MATCH55 %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55));
4802         fprintf(ofp,"State MATCH65 %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65));
4803         fprintf(ofp,"State MATCH75 %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75));
4804         fprintf(ofp,"State MATCH85 %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85));
4805         fprintf(ofp,"State MATCH95 %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95));
4806         fprintf(ofp,"State UNMATCHED_QUERY %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY));
4807         fprintf(ofp,"State UNMATCHED_TARGET %d\n",BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET));
4808         fprintf(ofp,"\n\n");
4809         }
4810       }
4811 
4812 
4813 }
4814 
4815 
4816 /* Function:  max_calc_BigDnaMatchBlock(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore,h)
4817  *
4818  * Descrip: No Description
4819  *
4820  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
4821  * Arg:                 i [UNKN ] Undocumented argument [int]
4822  * Arg:                 j [UNKN ] Undocumented argument [int]
4823  * Arg:             state [UNKN ] Undocumented argument [int]
4824  * Arg:         isspecial [UNKN ] Undocumented argument [boolean]
4825  * Arg:              reti [UNKN ] Undocumented argument [int *]
4826  * Arg:              retj [UNKN ] Undocumented argument [int *]
4827  * Arg:          retstate [UNKN ] Undocumented argument [int *]
4828  * Arg:        retspecial [UNKN ] Undocumented argument [boolean *]
4829  * Arg:         cellscore [UNKN ] Undocumented argument [int *]
4830  * Arg:                 h [UNKN ] Undocumented argument [BigDnaMatchBlock_access_func_holder]
4831  *
4832  * Return [UNKN ]  Undocumented return value [int]
4833  *
4834  */
max_calc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,BigDnaMatchBlock_access_func_holder h)4835 int max_calc_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,BigDnaMatchBlock_access_func_holder h)
4836 {
4837     register int temp;
4838     register int cscore;
4839 
4840 
4841     *reti = (*retj) = (*retstate) = BigDnaMatchBlock_READ_OFF_ERROR;
4842 
4843 
4844     if( i < 0 || j < 0 || i > mat->query->seq->len || j > mat->target->seq->len) {
4845       warn("In BigDnaMatchBlock matrix special read off - out of bounds on matrix [i,j is %d,%d state %d in standard matrix]",i,j,state);
4846       return -1;
4847       }
4848 
4849 
4850     /* Then you have to select the correct switch statement to figure out the readoff      */
4851     /* Somewhat odd - reverse the order of calculation and return as soon as it is correct */
4852     cscore = (*h.access_main)(mat,i,j,state);
4853     switch(state)    { /*Switch state */
4854       case MATCH55 :
4855         temp = cscore - ((mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
4856         if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET) ) {
4857           *reti = i - 1;
4858           *retj = j - 1;
4859           *retstate = UNMATCHED_TARGET;
4860           *retspecial = FALSE;
4861           if( cellscore != NULL) {
4862             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED_TARGET);
4863             }
4864           return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET);
4865           }
4866         temp = cscore - (mat->g55) -  (0);
4867         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH55) )  {
4868           *reti = i - 1;
4869           *retj = j - 0;
4870           *retstate = MATCH55;
4871           *retspecial = FALSE;
4872           if( cellscore != NULL) {
4873             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH55);
4874             }
4875           return (*h.access_main)(mat,i - 1,j - 0,MATCH55);
4876           }
4877         temp = cscore - (mat->g55) -  (0);
4878         if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH55) )  {
4879           *reti = i - 0;
4880           *retj = j - 1;
4881           *retstate = MATCH55;
4882           *retspecial = FALSE;
4883           if( cellscore != NULL) {
4884             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH55);
4885             }
4886           return (*h.access_main)(mat,i - 0,j - 1,MATCH55);
4887           }
4888         temp = cscore - ((mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
4889         if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH55) )  {
4890           *reti = i - 1;
4891           *retj = j - 1;
4892           *retstate = MATCH55;
4893           *retspecial = FALSE;
4894           if( cellscore != NULL) {
4895             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH55);
4896             }
4897           return (*h.access_main)(mat,i - 1,j - 1,MATCH55);
4898           }
4899         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
4900         return (-1);
4901       case MATCH65 :
4902         temp = cscore - ((mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
4903         if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET) ) {
4904           *reti = i - 1;
4905           *retj = j - 1;
4906           *retstate = UNMATCHED_TARGET;
4907           *retspecial = FALSE;
4908           if( cellscore != NULL) {
4909             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED_TARGET);
4910             }
4911           return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET);
4912           }
4913         temp = cscore - (mat->g65) -  (0);
4914         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH65) )  {
4915           *reti = i - 1;
4916           *retj = j - 0;
4917           *retstate = MATCH65;
4918           *retspecial = FALSE;
4919           if( cellscore != NULL) {
4920             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH65);
4921             }
4922           return (*h.access_main)(mat,i - 1,j - 0,MATCH65);
4923           }
4924         temp = cscore - (mat->g65) -  (0);
4925         if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH65) )  {
4926           *reti = i - 0;
4927           *retj = j - 1;
4928           *retstate = MATCH65;
4929           *retspecial = FALSE;
4930           if( cellscore != NULL) {
4931             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH65);
4932             }
4933           return (*h.access_main)(mat,i - 0,j - 1,MATCH65);
4934           }
4935         temp = cscore - ((mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
4936         if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH65) )  {
4937           *reti = i - 1;
4938           *retj = j - 1;
4939           *retstate = MATCH65;
4940           *retspecial = FALSE;
4941           if( cellscore != NULL) {
4942             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH65);
4943             }
4944           return (*h.access_main)(mat,i - 1,j - 1,MATCH65);
4945           }
4946         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
4947         return (-1);
4948       case MATCH75 :
4949         temp = cscore - ((mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
4950         if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET) ) {
4951           *reti = i - 1;
4952           *retj = j - 1;
4953           *retstate = UNMATCHED_TARGET;
4954           *retspecial = FALSE;
4955           if( cellscore != NULL) {
4956             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED_TARGET);
4957             }
4958           return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET);
4959           }
4960         temp = cscore - (mat->g) -  (0);
4961         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH75) )  {
4962           *reti = i - 1;
4963           *retj = j - 0;
4964           *retstate = MATCH75;
4965           *retspecial = FALSE;
4966           if( cellscore != NULL) {
4967             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH75);
4968             }
4969           return (*h.access_main)(mat,i - 1,j - 0,MATCH75);
4970           }
4971         temp = cscore - (mat->g) -  (0);
4972         if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH75) )  {
4973           *reti = i - 0;
4974           *retj = j - 1;
4975           *retstate = MATCH75;
4976           *retspecial = FALSE;
4977           if( cellscore != NULL) {
4978             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH75);
4979             }
4980           return (*h.access_main)(mat,i - 0,j - 1,MATCH75);
4981           }
4982         temp = cscore - ((mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
4983         if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH75) )  {
4984           *reti = i - 1;
4985           *retj = j - 1;
4986           *retstate = MATCH75;
4987           *retspecial = FALSE;
4988           if( cellscore != NULL) {
4989             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH75);
4990             }
4991           return (*h.access_main)(mat,i - 1,j - 1,MATCH75);
4992           }
4993         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
4994         return (-1);
4995       case MATCH85 :
4996         temp = cscore - ((mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
4997         if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET) ) {
4998           *reti = i - 1;
4999           *retj = j - 1;
5000           *retstate = UNMATCHED_TARGET;
5001           *retspecial = FALSE;
5002           if( cellscore != NULL) {
5003             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED_TARGET);
5004             }
5005           return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET);
5006           }
5007         temp = cscore - (mat->g) -  (0);
5008         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH85) )  {
5009           *reti = i - 1;
5010           *retj = j - 0;
5011           *retstate = MATCH85;
5012           *retspecial = FALSE;
5013           if( cellscore != NULL) {
5014             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH85);
5015             }
5016           return (*h.access_main)(mat,i - 1,j - 0,MATCH85);
5017           }
5018         temp = cscore - (mat->g) -  (0);
5019         if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH85) )  {
5020           *reti = i - 0;
5021           *retj = j - 1;
5022           *retstate = MATCH85;
5023           *retspecial = FALSE;
5024           if( cellscore != NULL) {
5025             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH85);
5026             }
5027           return (*h.access_main)(mat,i - 0,j - 1,MATCH85);
5028           }
5029         temp = cscore - ((mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
5030         if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH85) )  {
5031           *reti = i - 1;
5032           *retj = j - 1;
5033           *retstate = MATCH85;
5034           *retspecial = FALSE;
5035           if( cellscore != NULL) {
5036             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH85);
5037             }
5038           return (*h.access_main)(mat,i - 1,j - 1,MATCH85);
5039           }
5040         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
5041         return (-1);
5042       case MATCH95 :
5043         temp = cscore - ((mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v)) -  (0);
5044         if( temp == (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET) ) {
5045           *reti = i - 1;
5046           *retj = j - 1;
5047           *retstate = UNMATCHED_TARGET;
5048           *retspecial = FALSE;
5049           if( cellscore != NULL) {
5050             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,UNMATCHED_TARGET);
5051             }
5052           return (*h.access_main)(mat,i - 1,j - 1,UNMATCHED_TARGET);
5053           }
5054         temp = cscore - (mat->g) -  (0);
5055         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH95) )  {
5056           *reti = i - 1;
5057           *retj = j - 0;
5058           *retstate = MATCH95;
5059           *retspecial = FALSE;
5060           if( cellscore != NULL) {
5061             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH95);
5062             }
5063           return (*h.access_main)(mat,i - 1,j - 0,MATCH95);
5064           }
5065         temp = cscore - (mat->g) -  (0);
5066         if( temp == (*h.access_main)(mat,i - 0,j - 1,MATCH95) )  {
5067           *reti = i - 0;
5068           *retj = j - 1;
5069           *retstate = MATCH95;
5070           *retspecial = FALSE;
5071           if( cellscore != NULL) {
5072             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,MATCH95);
5073             }
5074           return (*h.access_main)(mat,i - 0,j - 1,MATCH95);
5075           }
5076         temp = cscore - ((mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s)) -  (0);
5077         if( temp == (*h.access_main)(mat,i - 1,j - 1,MATCH95) )  {
5078           *reti = i - 1;
5079           *retj = j - 1;
5080           *retstate = MATCH95;
5081           *retspecial = FALSE;
5082           if( cellscore != NULL) {
5083             *cellscore = cscore - (*h.access_main)(mat,i-1,j-1,MATCH95);
5084             }
5085           return (*h.access_main)(mat,i - 1,j - 1,MATCH95);
5086           }
5087         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
5088         return (-1);
5089       case UNMATCHED_QUERY :
5090         /* Has restricted position */
5091         if( (i-1) == 0 && (j-0) == 0 )   {
5092           temp = cscore - (0) -  (0);
5093           if( temp == (*h.access_special)(mat,i - 1,j - 0,START) )   {
5094             *reti = i - 1;
5095             *retj = j - 0;
5096             *retstate = START;
5097             *retspecial = TRUE;
5098             if( cellscore != NULL)   {
5099               *cellscore = cscore - (*h.access_special)(mat,i-1,j-0,START);
5100               }
5101             return (*h.access_main)(mat,i - 1,j - 0,START);
5102             }
5103           }
5104         temp = cscore - (mat->u) -  (0);
5105         if( temp == (*h.access_main)(mat,i - 1,j - 0,UNMATCHED_QUERY) )  {
5106           *reti = i - 1;
5107           *retj = j - 0;
5108           *retstate = UNMATCHED_QUERY;
5109           *retspecial = FALSE;
5110           if( cellscore != NULL) {
5111             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,UNMATCHED_QUERY);
5112             }
5113           return (*h.access_main)(mat,i - 1,j - 0,UNMATCHED_QUERY);
5114           }
5115         temp = cscore - (mat->b) -  (0);
5116         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH95) )  {
5117           *reti = i - 1;
5118           *retj = j - 0;
5119           *retstate = MATCH95;
5120           *retspecial = FALSE;
5121           if( cellscore != NULL) {
5122             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH95);
5123             }
5124           return (*h.access_main)(mat,i - 1,j - 0,MATCH95);
5125           }
5126         temp = cscore - (mat->b) -  (0);
5127         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH85) )  {
5128           *reti = i - 1;
5129           *retj = j - 0;
5130           *retstate = MATCH85;
5131           *retspecial = FALSE;
5132           if( cellscore != NULL) {
5133             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH85);
5134             }
5135           return (*h.access_main)(mat,i - 1,j - 0,MATCH85);
5136           }
5137         temp = cscore - (mat->b) -  (0);
5138         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH75) )  {
5139           *reti = i - 1;
5140           *retj = j - 0;
5141           *retstate = MATCH75;
5142           *retspecial = FALSE;
5143           if( cellscore != NULL) {
5144             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH75);
5145             }
5146           return (*h.access_main)(mat,i - 1,j - 0,MATCH75);
5147           }
5148         temp = cscore - (mat->b) -  (0);
5149         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH65) )  {
5150           *reti = i - 1;
5151           *retj = j - 0;
5152           *retstate = MATCH65;
5153           *retspecial = FALSE;
5154           if( cellscore != NULL) {
5155             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH65);
5156             }
5157           return (*h.access_main)(mat,i - 1,j - 0,MATCH65);
5158           }
5159         temp = cscore - (mat->b) -  (0);
5160         if( temp == (*h.access_main)(mat,i - 1,j - 0,MATCH55) )  {
5161           *reti = i - 1;
5162           *retj = j - 0;
5163           *retstate = MATCH55;
5164           *retspecial = FALSE;
5165           if( cellscore != NULL) {
5166             *cellscore = cscore - (*h.access_main)(mat,i-1,j-0,MATCH55);
5167             }
5168           return (*h.access_main)(mat,i - 1,j - 0,MATCH55);
5169           }
5170         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
5171         return (-1);
5172       case UNMATCHED_TARGET :
5173         temp = cscore - (mat->u) -  (0);
5174         if( temp == (*h.access_main)(mat,i - 0,j - 1,UNMATCHED_TARGET) ) {
5175           *reti = i - 0;
5176           *retj = j - 1;
5177           *retstate = UNMATCHED_TARGET;
5178           *retspecial = FALSE;
5179           if( cellscore != NULL) {
5180             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,UNMATCHED_TARGET);
5181             }
5182           return (*h.access_main)(mat,i - 0,j - 1,UNMATCHED_TARGET);
5183           }
5184         temp = cscore - (mat->v) -  (0);
5185         if( temp == (*h.access_main)(mat,i - 0,j - 1,UNMATCHED_QUERY) )  {
5186           *reti = i - 0;
5187           *retj = j - 1;
5188           *retstate = UNMATCHED_QUERY;
5189           *retspecial = FALSE;
5190           if( cellscore != NULL) {
5191             *cellscore = cscore - (*h.access_main)(mat,i-0,j-1,UNMATCHED_QUERY);
5192             }
5193           return (*h.access_main)(mat,i - 0,j - 1,UNMATCHED_QUERY);
5194           }
5195         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
5196         return (-1);
5197       default:
5198         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found!",i,j,state);
5199         return (-1);
5200       } /* end of Switch state  */
5201 }
5202 
5203 
5204 /* Function:  max_calc_special_BigDnaMatchBlock(mat,i,j,state,isspecial,reti,retj,retstate,retspecial,cellscore,h)
5205  *
5206  * Descrip: No Description
5207  *
5208  * Arg:               mat [UNKN ] Undocumented argument [BigDnaMatchBlock *]
5209  * Arg:                 i [UNKN ] Undocumented argument [int]
5210  * Arg:                 j [UNKN ] Undocumented argument [int]
5211  * Arg:             state [UNKN ] Undocumented argument [int]
5212  * Arg:         isspecial [UNKN ] Undocumented argument [boolean]
5213  * Arg:              reti [UNKN ] Undocumented argument [int *]
5214  * Arg:              retj [UNKN ] Undocumented argument [int *]
5215  * Arg:          retstate [UNKN ] Undocumented argument [int *]
5216  * Arg:        retspecial [UNKN ] Undocumented argument [boolean *]
5217  * Arg:         cellscore [UNKN ] Undocumented argument [int *]
5218  * Arg:                 h [UNKN ] Undocumented argument [BigDnaMatchBlock_access_func_holder]
5219  *
5220  * Return [UNKN ]  Undocumented return value [int]
5221  *
5222  */
max_calc_special_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,BigDnaMatchBlock_access_func_holder h)5223 int max_calc_special_BigDnaMatchBlock(BigDnaMatchBlock * mat,int i,int j,int state,boolean isspecial,int * reti,int * retj,int * retstate,boolean * retspecial,int * cellscore,BigDnaMatchBlock_access_func_holder h)
5224 {
5225     register int temp;
5226     register int cscore;
5227 
5228 
5229     *reti = (*retj) = (*retstate) = BigDnaMatchBlock_READ_OFF_ERROR;
5230 
5231 
5232     if( j < 0 || j > mat->target->seq->len)  {
5233       warn("In BigDnaMatchBlock matrix special read off - out of bounds on matrix [j is %d in special]",j);
5234       return -1;
5235       }
5236 
5237 
5238     cscore = (*h.access_special)(mat,i,j,state);
5239     switch(state)    { /*switch on special states*/
5240       case START :
5241       case END :
5242         /* source UNMATCHED_TARGET is from main matrix */
5243         for(i= mat->query->seq->len-1;i >= 0 ;i--)   { /*for i >= 0*/
5244           temp = cscore - (0) - (0);
5245           if( temp == (*h.access_main)(mat,i - 0,j - 0,UNMATCHED_TARGET) )   {
5246             *reti = i - 0;
5247             *retj = j - 0;
5248             *retstate = UNMATCHED_TARGET;
5249             *retspecial = FALSE;
5250             if( cellscore != NULL)   {
5251               *cellscore = cscore - (*h.access_main)(mat,i-0,j-0,UNMATCHED_TARGET);
5252               }
5253             return (*h.access_main)(mat,i - 0,j - 0,UNMATCHED_TARGET) ;
5254             }
5255           } /* end of for i >= 0 */
5256       default:
5257         warn("Major problem (!) - in BigDnaMatchBlock read off, position %d,%d state %d no source found  dropped into default on source switch!",i,j,state);
5258         return (-1);
5259       } /* end of switch on special states */
5260 }
5261 
5262 
5263 /* Function:  calculate_BigDnaMatchBlock(mat)
5264  *
5265  * Descrip:    This function calculates the BigDnaMatchBlock matrix when in explicit mode
5266  *             To allocate the matrix use /allocate_Expl_BigDnaMatchBlock
5267  *
5268  *
5269  * Arg:        mat [UNKN ] BigDnaMatchBlock which contains explicit basematrix memory [BigDnaMatchBlock *]
5270  *
5271  * Return [UNKN ]  Undocumented return value [boolean]
5272  *
5273  */
calculate_BigDnaMatchBlock(BigDnaMatchBlock * mat)5274 boolean calculate_BigDnaMatchBlock(BigDnaMatchBlock * mat)
5275 {
5276     int i;
5277     int j;
5278     int leni;
5279     int lenj;
5280     int tot;
5281     int num;
5282 
5283 
5284     if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT )  {
5285       warn("in calculate_BigDnaMatchBlock, passed a non Explicit matrix type, cannot calculate!");
5286       return FALSE;
5287       }
5288 
5289 
5290     leni = mat->leni;
5291     lenj = mat->lenj;
5292     tot = leni * lenj;
5293     num = 0;
5294 
5295 
5296     start_reporting("BigDnaMatchBlock Matrix calculation: ");
5297     for(j=0;j<lenj;j++)  {
5298       auto int score;
5299       auto int temp;
5300       for(i=0;i<leni;i++)    {
5301         if( num%1000 == 0 )
5302           log_full_error(REPORT,0,"[%7d] Cells %2d%%%%",num,num*100/tot);
5303         num++;
5304 
5305 
5306         /* For state MATCH55 */
5307         /* setting first movement to score */
5308         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5309         /* From state MATCH55 to state MATCH55 */
5310         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
5311         if( temp  > score )  {
5312           score = temp;
5313           }
5314         /* From state MATCH55 to state MATCH55 */
5315         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
5316         if( temp  > score )  {
5317           score = temp;
5318           }
5319         /* From state UNMATCHED_TARGET to state MATCH55 */
5320         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5321         if( temp  > score )  {
5322           score = temp;
5323           }
5324 
5325 
5326         /* Ok - finished max calculation for MATCH55 */
5327         /* Add any movement independant score and put away */
5328          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = score;
5329 
5330 
5331         /* Finished calculating state MATCH55 */
5332 
5333 
5334         /* For state MATCH65 */
5335         /* setting first movement to score */
5336         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5337         /* From state MATCH65 to state MATCH65 */
5338         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
5339         if( temp  > score )  {
5340           score = temp;
5341           }
5342         /* From state MATCH65 to state MATCH65 */
5343         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
5344         if( temp  > score )  {
5345           score = temp;
5346           }
5347         /* From state UNMATCHED_TARGET to state MATCH65 */
5348         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5349         if( temp  > score )  {
5350           score = temp;
5351           }
5352 
5353 
5354         /* Ok - finished max calculation for MATCH65 */
5355         /* Add any movement independant score and put away */
5356          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = score;
5357 
5358 
5359         /* Finished calculating state MATCH65 */
5360 
5361 
5362         /* For state MATCH75 */
5363         /* setting first movement to score */
5364         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5365         /* From state MATCH75 to state MATCH75 */
5366         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
5367         if( temp  > score )  {
5368           score = temp;
5369           }
5370         /* From state MATCH75 to state MATCH75 */
5371         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
5372         if( temp  > score )  {
5373           score = temp;
5374           }
5375         /* From state UNMATCHED_TARGET to state MATCH75 */
5376         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5377         if( temp  > score )  {
5378           score = temp;
5379           }
5380 
5381 
5382         /* Ok - finished max calculation for MATCH75 */
5383         /* Add any movement independant score and put away */
5384          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = score;
5385 
5386 
5387         /* Finished calculating state MATCH75 */
5388 
5389 
5390         /* For state MATCH85 */
5391         /* setting first movement to score */
5392         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5393         /* From state MATCH85 to state MATCH85 */
5394         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
5395         if( temp  > score )  {
5396           score = temp;
5397           }
5398         /* From state MATCH85 to state MATCH85 */
5399         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
5400         if( temp  > score )  {
5401           score = temp;
5402           }
5403         /* From state UNMATCHED_TARGET to state MATCH85 */
5404         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5405         if( temp  > score )  {
5406           score = temp;
5407           }
5408 
5409 
5410         /* Ok - finished max calculation for MATCH85 */
5411         /* Add any movement independant score and put away */
5412          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = score;
5413 
5414 
5415         /* Finished calculating state MATCH85 */
5416 
5417 
5418         /* For state MATCH95 */
5419         /* setting first movement to score */
5420         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5421         /* From state MATCH95 to state MATCH95 */
5422         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
5423         if( temp  > score )  {
5424           score = temp;
5425           }
5426         /* From state MATCH95 to state MATCH95 */
5427         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
5428         if( temp  > score )  {
5429           score = temp;
5430           }
5431         /* From state UNMATCHED_TARGET to state MATCH95 */
5432         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5433         if( temp  > score )  {
5434           score = temp;
5435           }
5436 
5437 
5438         /* Ok - finished max calculation for MATCH95 */
5439         /* Add any movement independant score and put away */
5440          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = score;
5441 
5442 
5443         /* Finished calculating state MATCH95 */
5444 
5445 
5446         /* For state UNMATCHED_QUERY */
5447         /* setting first movement to score */
5448         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
5449         /* From state MATCH65 to state UNMATCHED_QUERY */
5450         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
5451         if( temp  > score )  {
5452           score = temp;
5453           }
5454         /* From state MATCH75 to state UNMATCHED_QUERY */
5455         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
5456         if( temp  > score )  {
5457           score = temp;
5458           }
5459         /* From state MATCH85 to state UNMATCHED_QUERY */
5460         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
5461         if( temp  > score )  {
5462           score = temp;
5463           }
5464         /* From state MATCH95 to state UNMATCHED_QUERY */
5465         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
5466         if( temp  > score )  {
5467           score = temp;
5468           }
5469         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
5470         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
5471         if( temp  > score )  {
5472           score = temp;
5473           }
5474         /* Has restricted position */
5475         if( (i-1) == 0 && (j-0) == 0 )   {
5476           /* From state START to state UNMATCHED_QUERY */
5477           temp = BigDnaMatchBlock_EXPL_SPECIAL(mat,i-1,j-0,START) + 0;
5478           if( temp  > score )    {
5479             score = temp;
5480             }
5481           }
5482 
5483 
5484         /* Ok - finished max calculation for UNMATCHED_QUERY */
5485         /* Add any movement independant score and put away */
5486          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
5487 
5488 
5489         /* Finished calculating state UNMATCHED_QUERY */
5490 
5491 
5492         /* For state UNMATCHED_TARGET */
5493         /* setting first movement to score */
5494         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
5495         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
5496         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
5497         if( temp  > score )  {
5498           score = temp;
5499           }
5500 
5501 
5502         /* Ok - finished max calculation for UNMATCHED_TARGET */
5503         /* Add any movement independant score and put away */
5504          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
5505 
5506 
5507         /* state UNMATCHED_TARGET is a source for special END */
5508         /* Has restricted position */
5509         if( i == mat->leni-1 && j == mat->lenj-1 )   {
5510           temp = score + (0) + (0) ;
5511           if( temp > BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) )    {
5512             BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) = temp;
5513             }
5514 
5515 
5516           }
5517 
5518 
5519         /* Finished calculating state UNMATCHED_TARGET */
5520         }
5521 
5522 
5523       /* Special state START has no special to special movements */
5524 
5525 
5526       /* Special state END has no special to special movements */
5527       }
5528     stop_reporting();
5529     return TRUE;
5530 }
5531 
5532 
5533 /* Function:  calculate_dpenv_BigDnaMatchBlock(mat,dpenv)
5534  *
5535  * Descrip:    This function calculates the BigDnaMatchBlock matrix when in explicit mode, subject to the envelope
5536  *
5537  *
5538  * Arg:          mat [UNKN ] BigDnaMatchBlock which contains explicit basematrix memory [BigDnaMatchBlock *]
5539  * Arg:        dpenv [UNKN ] Undocumented argument [DPEnvelope *]
5540  *
5541  * Return [UNKN ]  Undocumented return value [boolean]
5542  *
5543  */
calculate_dpenv_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)5544 boolean calculate_dpenv_BigDnaMatchBlock(BigDnaMatchBlock * mat,DPEnvelope * dpenv)
5545 {
5546     int i;
5547     int j;
5548     int k;
5549     int starti;
5550     int startj;
5551     int endi;
5552     int endj;
5553     int tot;
5554     int num;
5555     int should_calc;
5556 
5557 
5558     if( mat->basematrix->type != BASEMATRIX_TYPE_EXPLICIT )  {
5559       warn("in calculate_BigDnaMatchBlock, passed a non Explicit matrix type, cannot calculate!");
5560       return FALSE;
5561       }
5562 
5563 
5564     prepare_DPEnvelope(dpenv);
5565     starti = dpenv->starti;
5566     if( starti < 0 )
5567       starti = 0;
5568     startj = dpenv->startj;
5569     if( startj < 0 )
5570       startj = 0;
5571     endi = dpenv->endi;
5572     if( endi > mat->leni )
5573       endi = mat->leni;
5574     endj = dpenv->endj;
5575     if( endj > mat->lenj )
5576       endj = mat->lenj;
5577     tot = (endi-starti) * (endj-startj);
5578     num = 0;
5579 
5580 
5581     for(j=startj-1;j<endj;j++)   {
5582       for(i=1;i<mat->leni;i++)   {
5583         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = NEGI;
5584         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = NEGI;
5585         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = NEGI;
5586         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = NEGI;
5587         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = NEGI;
5588         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
5589         BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
5590         }
5591       }
5592     for(j=-1;j<mat->lenj;j++)    {
5593       BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,START) = 0;
5594       BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) = NEGI;
5595       }
5596 
5597 
5598     start_reporting("BigDnaMatchBlock Matrix calculation: ");
5599     for(j=startj;j<endj;j++) {
5600       auto int score;
5601       auto int temp;
5602       for(i=starti;i<endi;i++)   {
5603         /* Check if is in envelope - code identical to is_in_DPEnvelope, but aggressively inlined here for speed */
5604         should_calc = 0;
5605         for(k=0;k<dpenv->len;k++)    {
5606           auto DPUnit * u;
5607           u = dpenv->dpu[k];
5608           switch(u->type)    {
5609             case DPENV_RECT :
5610               if( i >= u->starti && j >= u->startj && i <= (u->starti+u->height) && j <= (u->startj+u->length))
5611                 should_calc = 1;
5612               break;
5613             case DPENV_DIAG :
5614               if(  abs( (i-j) - (u->starti-u->startj)) <= u->height && i+j >= u->starti+u->startj && i+j+u->length >= u->starti+u->startj)
5615                 should_calc = 1;
5616               break;
5617             }
5618           if( should_calc == 1 )
5619             break;
5620           }
5621         if( should_calc == 0)    {
5622           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = NEGI;
5623           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = NEGI;
5624           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = NEGI;
5625           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = NEGI;
5626           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = NEGI;
5627           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = NEGI;
5628           BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = NEGI;
5629           continue;
5630           }
5631 
5632 
5633         if( num%1000 == 0 )
5634           log_full_error(REPORT,0,"[%7d] Cells %2d%%%%",num,num*100/tot);
5635         num++;
5636 
5637 
5638         /* For state MATCH55 */
5639         /* setting first movement to score */
5640         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH55) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5641         /* From state MATCH55 to state MATCH55 */
5642         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH55) + mat->g55;
5643         if( temp  > score )  {
5644           score = temp;
5645           }
5646         /* From state MATCH55 to state MATCH55 */
5647         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH55) + mat->g55;
5648         if( temp  > score )  {
5649           score = temp;
5650           }
5651         /* From state UNMATCHED_TARGET to state MATCH55 */
5652         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp55->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5653         if( temp  > score )  {
5654           score = temp;
5655           }
5656 
5657 
5658         /* Ok - finished max calculation for MATCH55 */
5659         /* Add any movement independant score and put away */
5660          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH55) = score;
5661 
5662 
5663         /* Finished calculating state MATCH55 */
5664 
5665 
5666         /* For state MATCH65 */
5667         /* setting first movement to score */
5668         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH65) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5669         /* From state MATCH65 to state MATCH65 */
5670         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH65) + mat->g65;
5671         if( temp  > score )  {
5672           score = temp;
5673           }
5674         /* From state MATCH65 to state MATCH65 */
5675         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH65) + mat->g65;
5676         if( temp  > score )  {
5677           score = temp;
5678           }
5679         /* From state UNMATCHED_TARGET to state MATCH65 */
5680         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp65->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5681         if( temp  > score )  {
5682           score = temp;
5683           }
5684 
5685 
5686         /* Ok - finished max calculation for MATCH65 */
5687         /* Add any movement independant score and put away */
5688          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH65) = score;
5689 
5690 
5691         /* Finished calculating state MATCH65 */
5692 
5693 
5694         /* For state MATCH75 */
5695         /* setting first movement to score */
5696         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH75) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5697         /* From state MATCH75 to state MATCH75 */
5698         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH75) + mat->g;
5699         if( temp  > score )  {
5700           score = temp;
5701           }
5702         /* From state MATCH75 to state MATCH75 */
5703         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH75) + mat->g;
5704         if( temp  > score )  {
5705           score = temp;
5706           }
5707         /* From state UNMATCHED_TARGET to state MATCH75 */
5708         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp75->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5709         if( temp  > score )  {
5710           score = temp;
5711           }
5712 
5713 
5714         /* Ok - finished max calculation for MATCH75 */
5715         /* Add any movement independant score and put away */
5716          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH75) = score;
5717 
5718 
5719         /* Finished calculating state MATCH75 */
5720 
5721 
5722         /* For state MATCH85 */
5723         /* setting first movement to score */
5724         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH85) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5725         /* From state MATCH85 to state MATCH85 */
5726         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH85) + mat->g;
5727         if( temp  > score )  {
5728           score = temp;
5729           }
5730         /* From state MATCH85 to state MATCH85 */
5731         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH85) + mat->g;
5732         if( temp  > score )  {
5733           score = temp;
5734           }
5735         /* From state UNMATCHED_TARGET to state MATCH85 */
5736         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp85->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5737         if( temp  > score )  {
5738           score = temp;
5739           }
5740 
5741 
5742         /* Ok - finished max calculation for MATCH85 */
5743         /* Add any movement independant score and put away */
5744          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH85) = score;
5745 
5746 
5747         /* Finished calculating state MATCH85 */
5748 
5749 
5750         /* For state MATCH95 */
5751         /* setting first movement to score */
5752         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,MATCH95) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->s);
5753         /* From state MATCH95 to state MATCH95 */
5754         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,MATCH95) + mat->g;
5755         if( temp  > score )  {
5756           score = temp;
5757           }
5758         /* From state MATCH95 to state MATCH95 */
5759         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH95) + mat->g;
5760         if( temp  > score )  {
5761           score = temp;
5762           }
5763         /* From state UNMATCHED_TARGET to state MATCH95 */
5764         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-1,UNMATCHED_TARGET) + (mat->comp95->score[CSEQ_DNA_BASE(mat->query,i)][CSEQ_DNA_BASE(mat->target,j)]+mat->v);
5765         if( temp  > score )  {
5766           score = temp;
5767           }
5768 
5769 
5770         /* Ok - finished max calculation for MATCH95 */
5771         /* Add any movement independant score and put away */
5772          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,MATCH95) = score;
5773 
5774 
5775         /* Finished calculating state MATCH95 */
5776 
5777 
5778         /* For state UNMATCHED_QUERY */
5779         /* setting first movement to score */
5780         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH55) + mat->b;
5781         /* From state MATCH65 to state UNMATCHED_QUERY */
5782         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH65) + mat->b;
5783         if( temp  > score )  {
5784           score = temp;
5785           }
5786         /* From state MATCH75 to state UNMATCHED_QUERY */
5787         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH75) + mat->b;
5788         if( temp  > score )  {
5789           score = temp;
5790           }
5791         /* From state MATCH85 to state UNMATCHED_QUERY */
5792         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH85) + mat->b;
5793         if( temp  > score )  {
5794           score = temp;
5795           }
5796         /* From state MATCH95 to state UNMATCHED_QUERY */
5797         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,MATCH95) + mat->b;
5798         if( temp  > score )  {
5799           score = temp;
5800           }
5801         /* From state UNMATCHED_QUERY to state UNMATCHED_QUERY */
5802         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-1,j-0,UNMATCHED_QUERY) + mat->u;
5803         if( temp  > score )  {
5804           score = temp;
5805           }
5806         /* Has restricted position */
5807         if( (i-1) == 0 && (j-0) == 0 )   {
5808           /* From state START to state UNMATCHED_QUERY */
5809           temp = BigDnaMatchBlock_EXPL_SPECIAL(mat,i-1,j-0,START) + 0;
5810           if( temp  > score )    {
5811             score = temp;
5812             }
5813           }
5814 
5815 
5816         /* Ok - finished max calculation for UNMATCHED_QUERY */
5817         /* Add any movement independant score and put away */
5818          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_QUERY) = score;
5819 
5820 
5821         /* Finished calculating state UNMATCHED_QUERY */
5822 
5823 
5824         /* For state UNMATCHED_TARGET */
5825         /* setting first movement to score */
5826         score = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED_QUERY) + mat->v;
5827         /* From state UNMATCHED_TARGET to state UNMATCHED_TARGET */
5828         temp = BigDnaMatchBlock_EXPL_MATRIX(mat,i-0,j-1,UNMATCHED_TARGET) + mat->u;
5829         if( temp  > score )  {
5830           score = temp;
5831           }
5832 
5833 
5834         /* Ok - finished max calculation for UNMATCHED_TARGET */
5835         /* Add any movement independant score and put away */
5836          BigDnaMatchBlock_EXPL_MATRIX(mat,i,j,UNMATCHED_TARGET) = score;
5837 
5838 
5839         /* state UNMATCHED_TARGET is a source for special END */
5840         /* Has restricted position */
5841         if( i == mat->leni-1 && j == mat->lenj-1 )   {
5842           temp = score + (0) + (0) ;
5843           if( temp > BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) )    {
5844             BigDnaMatchBlock_EXPL_SPECIAL(mat,i,j,END) = temp;
5845             }
5846 
5847 
5848           }
5849 
5850 
5851         /* Finished calculating state UNMATCHED_TARGET */
5852         }
5853 
5854 
5855       /* Special state START has no special to special movements */
5856 
5857 
5858       /* Special state END has no special to special movements */
5859       }
5860     stop_reporting();
5861     return TRUE;
5862 }
5863 
5864 
5865 /* Function:  BigDnaMatchBlock_alloc(void)
5866  *
5867  * Descrip:    Allocates structure: assigns defaults if given
5868  *
5869  *
5870  *
5871  * Return [UNKN ]  Undocumented return value [BigDnaMatchBlock *]
5872  *
5873  */
BigDnaMatchBlock_alloc(void)5874 BigDnaMatchBlock * BigDnaMatchBlock_alloc(void)
5875 {
5876     BigDnaMatchBlock * out; /* out is exported at end of function */
5877 
5878 
5879     /* call ckalloc and see if NULL */
5880     if((out=(BigDnaMatchBlock *) ckalloc (sizeof(BigDnaMatchBlock))) == NULL)    {
5881       warn("BigDnaMatchBlock_alloc failed ");
5882       return NULL;  /* calling function should respond! */
5883       }
5884     out->dynamite_hard_link = 1;
5885 #ifdef PTHREAD
5886     pthread_mutex_init(&(out->dynamite_mutex),NULL);
5887 #endif
5888     out->basematrix = NULL;
5889     out->shatter = NULL;
5890     out->leni = 0;
5891     out->lenj = 0;
5892 
5893 
5894     return out;
5895 }
5896 
5897 
5898 /* Function:  free_BigDnaMatchBlock(obj)
5899  *
5900  * Descrip:    Free Function: removes the memory held by obj
5901  *             Will chain up to owned members and clear all lists
5902  *
5903  *
5904  * Arg:        obj [UNKN ] Object that is free'd [BigDnaMatchBlock *]
5905  *
5906  * Return [UNKN ]  Undocumented return value [BigDnaMatchBlock *]
5907  *
5908  */
free_BigDnaMatchBlock(BigDnaMatchBlock * obj)5909 BigDnaMatchBlock * free_BigDnaMatchBlock(BigDnaMatchBlock * obj)
5910 {
5911     int return_early = 0;
5912 
5913 
5914     if( obj == NULL) {
5915       warn("Attempting to free a NULL pointer to a BigDnaMatchBlock obj. Should be trappable");
5916       return NULL;
5917       }
5918 
5919 
5920 #ifdef PTHREAD
5921     assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
5922 #endif
5923     if( obj->dynamite_hard_link > 1)     {
5924       return_early = 1;
5925       obj->dynamite_hard_link--;
5926       }
5927 #ifdef PTHREAD
5928     assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
5929 #endif
5930     if( return_early == 1)
5931       return NULL;
5932     if( obj->basematrix != NULL)
5933       free_BaseMatrix(obj->basematrix);
5934     if( obj->shatter != NULL)
5935       free_ShatterMatrix(obj->shatter);
5936     /* obj->query is linked in */
5937     /* obj->target is linked in */
5938     /* obj->comp55 is linked in */
5939     /* obj->comp65 is linked in */
5940     /* obj->comp75 is linked in */
5941     /* obj->comp85 is linked in */
5942     /* obj->comp95 is linked in */
5943     /* obj->g is linked in */
5944     /* obj->g65 is linked in */
5945     /* obj->g55 is linked in */
5946     /* obj->u is linked in */
5947     /* obj->v is linked in */
5948     /* obj->s is linked in */
5949     /* obj->b is linked in */
5950 
5951 
5952     ckfree(obj);
5953     return NULL;
5954 }
5955 
5956 
5957 
5958 
5959 
5960 #ifdef _cplusplus
5961 }
5962 #endif
5963