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