1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "pairbase.h"
5
6 /* Function: diagonal_tweak_PairBaseCodonModel(m,ratio_on,ratio_off_positive,ratio_off_negative)
7 *
8 * Descrip: Tweaks a PairBaseCodonModel with on and off diagonal ratios
9 *
10 *
11 * Arg: m [UNKN ] Undocumented argument [PairBaseCodonModel *]
12 * Arg: ratio_on [UNKN ] Undocumented argument [double]
13 * Arg: ratio_off_positive [UNKN ] Undocumented argument [double]
14 * Arg: ratio_off_negative [UNKN ] Undocumented argument [double]
15 *
16 */
17 # line 43 "pairbase.dy"
diagonal_tweak_PairBaseCodonModel(PairBaseCodonModel * m,double ratio_on,double ratio_off_positive,double ratio_off_negative)18 void diagonal_tweak_PairBaseCodonModel(PairBaseCodonModel * m,double ratio_on,double ratio_off_positive,double ratio_off_negative)
19 {
20 int a,b,c,x,y,z;
21 int p;
22 int codon_a;
23 int codon_b;
24 pairbase_type seq[3];
25
26 for(a=0;a<5;a++) {
27 for(b=0;b<5;b++) {
28 for(c=0;c<5;c++) {
29 for(x=0;x<5;x++) {
30 for(y=0;y<5;y++) {
31 for(z=0;z<5;z++) {
32
33 /* build the sequence */
34 seq[0] = MAKE_PAIRBASE(a,x);
35 seq[1] = MAKE_PAIRBASE(b,y);
36 seq[2] = MAKE_PAIRBASE(c,z);
37
38 p = pairbase_codon_from_seq(seq);
39
40
41
42 if( a == x && b == y && c == z ) {
43 if( a == 4 && b == 4 && c== 4 ) {
44 m->codon[p] *= 0.5;
45 } else {
46 m->codon[p] *= ratio_on;
47 }
48 } else if ( m->codon[p] > 1.0 ) {
49 /* fprintf(stderr,"For %d %d,%d,%d vs %d,%d,%d\n",p,a,b,c,x,y,z); */
50 m->codon[p] *= ratio_off_positive;
51 } else {
52 m->codon[p] *= ratio_off_negative;
53 }
54 }
55 }
56 }
57 }
58 }
59 }
60 }
61
62
63 /* Function: flatten_diagonal_PairBaseCodonModel(m,ct)
64 *
65 * Descrip: flattens out the diagonal signal
66 *
67 *
68 * Arg: m [UNKN ] Undocumented argument [PairBaseCodonModel *]
69 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
70 *
71 */
72 # line 91 "pairbase.dy"
flatten_diagonal_PairBaseCodonModel(PairBaseCodonModel * m,CodonTable * ct)73 void flatten_diagonal_PairBaseCodonModel(PairBaseCodonModel * m,CodonTable * ct)
74 {
75 int a,b,c;
76 pairbase_type seq[3];
77 int codon_a;
78 int p;
79
80
81 for(a=0;a<5;a++) {
82 for(b=0;b<5;b++) {
83 for(c=0;c<5;c++) {
84
85 if( a < 4 && b < 4 && c < 4 ) {
86 codon_a = (25 * a) + (5 * b) + c;
87 if( is_stop_codon(codon_a,ct) ) {
88 m->codon[p] = 0.0;
89 continue;
90 }
91 }
92
93 /* build the sequence */
94 seq[0] = MAKE_PAIRBASE(a,a);
95 seq[1] = MAKE_PAIRBASE(b,b);
96 seq[2] = MAKE_PAIRBASE(c,c);
97
98
99 p = pairbase_codon_from_seq(seq);
100
101 if( a == 4 && b == 4 && c== 4 ) {
102 m->codon[p] = 0.5;
103 } else {
104 m->codon[p] = 1.0;
105 }
106 }
107 }
108 }
109
110 }
111
112 /* Function: flatten_diagonal_PairBaseCodonModelScore(m,ct)
113 *
114 * Descrip: flattens out the diagonal signal - for scores!
115 *
116 *
117 * Arg: m [UNKN ] Undocumented argument [PairBaseCodonModelScore *]
118 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
119 *
120 */
121 # line 133 "pairbase.dy"
flatten_diagonal_PairBaseCodonModelScore(PairBaseCodonModelScore * m,CodonTable * ct)122 void flatten_diagonal_PairBaseCodonModelScore(PairBaseCodonModelScore * m,CodonTable * ct)
123 {
124 int a,b,c;
125 pairbase_type seq[3];
126 int codon_a;
127 int p;
128
129
130 for(a=0;a<5;a++) {
131 for(b=0;b<5;b++) {
132 for(c=0;c<5;c++) {
133
134 if( a < 4 && b < 4 && c < 4 ) {
135 codon_a = (25 * a) + (5 * b) + c;
136 if( is_stop_codon(codon_a,ct) ) {
137 m->codon[p] = NEGI;
138 continue;
139 }
140 }
141
142 /* build the sequence */
143 seq[0] = MAKE_PAIRBASE(a,a);
144 seq[1] = MAKE_PAIRBASE(b,b);
145 seq[2] = MAKE_PAIRBASE(c,c);
146
147
148 p = pairbase_codon_from_seq(seq);
149
150 if( a == 4 && b == 4 && c== 4 ) {
151 m->codon[p] = -2;
152 } else {
153 m->codon[p] = 0;
154 }
155 }
156 }
157 }
158
159 }
160
161
162
163
164 /* Function: zero_PairBaseModelScore(void)
165 *
166 * Descrip: a 0 pairbasemodel score
167 *
168 *
169 *
170 * Return [UNKN ] Undocumented return value [PairBaseModelScore *]
171 *
172 */
173 # line 178 "pairbase.dy"
zero_PairBaseModelScore(void)174 PairBaseModelScore * zero_PairBaseModelScore(void)
175 {
176 PairBaseModelScore * out;
177 int i;
178
179 out = PairBaseModelScore_alloc();
180
181 for(i=0;i<PAIRBASE_LENGTH;i++) {
182 out->base[i] = 0;
183 }
184
185 return out;
186 }
187
188
189
190 /* Function: very_simple_PairBaseCodonModel(id,rnd,nonm,gap,ct)
191 *
192 * Descrip: Makes a PairBaseCodonModel from just a one parameter! Wow!
193 *
194 *
195 * Arg: id [UNKN ] Undocumented argument [Probability]
196 * Arg: rnd [UNKN ] Undocumented argument [Probability]
197 * Arg: nonm [UNKN ] Undocumented argument [Probability]
198 * Arg: gap [UNKN ] Undocumented argument [Probability]
199 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
200 *
201 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
202 *
203 */
204 # line 197 "pairbase.dy"
very_simple_PairBaseCodonModel(Probability id,Probability rnd,Probability nonm,Probability gap,CodonTable * ct)205 PairBaseCodonModel * very_simple_PairBaseCodonModel(Probability id,Probability rnd,Probability nonm,Probability gap,CodonTable * ct)
206 {
207 CompProb * p;
208 PairBaseCodonModel * out;
209
210 p = simple_aa_CompProb(id,id,rnd);
211
212 out = make_flat_PairBaseCodonModel(p,nonm,gap,ct);
213
214 free_CompProb(p);
215
216 return out;
217 }
218
219
220 /* Function: make_flat_PairBaseCodonModel(cp,nonm,gap,ct)
221 *
222 * Descrip: Makes a PairBaseCodonModel from a protein matrix - assumming a flat
223 * mapping to CodonMatrix
224 *
225 *
226 * Arg: cp [UNKN ] Undocumented argument [CompProb *]
227 * Arg: nonm [UNKN ] Undocumented argument [Probability]
228 * Arg: gap [UNKN ] Undocumented argument [Probability]
229 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
230 *
231 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
232 *
233 */
234 # line 216 "pairbase.dy"
make_flat_PairBaseCodonModel(CompProb * cp,Probability nonm,Probability gap,CodonTable * ct)235 PairBaseCodonModel * make_flat_PairBaseCodonModel(CompProb * cp,Probability nonm,Probability gap,CodonTable * ct)
236 {
237 CodonMatrix * cm;
238 PairBaseCodonModel * out;
239
240 cm = naive_CodonMatrix(ct,cp);
241
242 out = make_PairBaseCodonModel(cm,nonm,gap,ct);
243
244 free_CodonMatrix(cm);
245
246 return out;
247 }
248
249 /* Function: make_start_PairBaseCodonModelScore(ct)
250 *
251 * Descrip: Makes a PairBaseCodonModel score for start codon
252 *
253 *
254 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
255 *
256 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
257 *
258 */
259 # line 233 "pairbase.dy"
make_start_PairBaseCodonModelScore(CodonTable * ct)260 PairBaseCodonModelScore * make_start_PairBaseCodonModelScore(CodonTable * ct)
261 {
262 PairBaseCodonModel * model;
263 PairBaseCodonModelScore * out;
264
265 model = make_conserved_PairBaseCodonModel(100.0,0.000000000001,'M',ct);
266
267 out = new_PairBaseCodonModelScore(model);
268
269 free_PairBaseCodonModel(model);
270
271 return out;
272
273 }
274
275 /* Function: make_stop_PairBaseCodonModelScore(ct)
276 *
277 * Descrip: Makes a PairBaseCodonModel score for start codon
278 *
279 *
280 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
281 *
282 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
283 *
284 */
285 # line 251 "pairbase.dy"
make_stop_PairBaseCodonModelScore(CodonTable * ct)286 PairBaseCodonModelScore * make_stop_PairBaseCodonModelScore(CodonTable * ct)
287 {
288 PairBaseCodonModel * model;
289 PairBaseCodonModelScore * out;
290
291 model = make_conserved_PairBaseCodonModel(100.0,0.000000000001,'X',ct);
292
293 out = new_PairBaseCodonModelScore(model);
294
295 free_PairBaseCodonModel(model);
296
297 return out;
298
299 }
300
301
302 /* Function: make_conserved_PairBaseCodonModel(cons,non_cons,aa_var,ct)
303 *
304 * Descrip: Makes a PairBaseCodonModel for a particular character in the CodonTable
305 *
306 *
307 * Arg: cons [UNKN ] Undocumented argument [Probability]
308 * Arg: non_cons [UNKN ] Undocumented argument [Probability]
309 * Arg: aa_var [UNKN ] Undocumented argument [char]
310 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
311 *
312 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
313 *
314 */
315 # line 270 "pairbase.dy"
make_conserved_PairBaseCodonModel(Probability cons,Probability non_cons,char aa_var,CodonTable * ct)316 PairBaseCodonModel * make_conserved_PairBaseCodonModel(Probability cons,Probability non_cons,char aa_var,CodonTable * ct)
317 {
318 PairBaseCodonModel * out;
319 int i;
320 base base_a,base_b,base_c;
321 pairbase_type seq[3];
322 int p;
323
324 assert(ct);
325
326 out = PairBaseCodonModel_alloc();
327
328 for(i=0;i<PAIRBASE_CODON_LENGTH;i++) {
329 out->codon[i] = non_cons;
330 }
331
332 for(i=0;i<125;i++) {
333 if( ct->codon_str[i] == aa_var ) {
334 fprintf(stderr,"Assinging %d with %c\n",i,aa_var);
335 all_bases_from_codon(i,&base_a,&base_b,&base_c);
336 seq[0] = MAKE_PAIRBASE(base_a,base_a);
337 seq[1] = MAKE_PAIRBASE(base_b,base_b);
338 seq[2] = MAKE_PAIRBASE(base_c,base_c);
339
340 p = pairbase_codon_from_seq(seq);
341 out->codon[p] = cons;
342 }
343 }
344
345 return out;
346 }
347
348
349 /* Function: make_PairBaseCodonModel(codon_matrix,nonm,gap,ct)
350 *
351 * Descrip: Makes a PairBaseCodonModel from a CodonMatrix and parameters
352 *
353 *
354 * Arg: codon_matrix [UNKN ] Undocumented argument [CodonMatrix *]
355 * Arg: nonm [UNKN ] Undocumented argument [Probability]
356 * Arg: gap [UNKN ] Undocumented argument [Probability]
357 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
358 *
359 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
360 *
361 */
362 # line 306 "pairbase.dy"
make_PairBaseCodonModel(CodonMatrix * codon_matrix,Probability nonm,Probability gap,CodonTable * ct)363 PairBaseCodonModel * make_PairBaseCodonModel(CodonMatrix * codon_matrix,Probability nonm,Probability gap,CodonTable * ct)
364 {
365 PairBaseCodonModel * out;
366 int a,b,c,x,y,z;
367 int i;
368 int codon_a;
369 int codon_b;
370 int p;
371
372 pairbase_type seq[3];
373
374
375 assert(codon_matrix);
376 assert(ct);
377
378 out = PairBaseCodonModel_alloc();
379
380 for(i=0;i<PAIRBASE_CODON_LENGTH;i++) {
381 out->codon[i] = 0.0;
382 }
383
384 for(a=0;a<5;a++) {
385 for(b=0;b<5;b++) {
386 for(c=0;c<5;c++) {
387 for(x=0;x<5;x++) {
388 for(y=0;y<5;y++) {
389 for(z=0;z<5;z++) {
390
391 /* build the sequence */
392 seq[0] = MAKE_PAIRBASE(a,x);
393 seq[1] = MAKE_PAIRBASE(b,y);
394 seq[2] = MAKE_PAIRBASE(c,z);
395
396 p = pairbase_codon_from_seq(seq);
397
398 codon_a = (a * 25) + (b * 5) + c;
399 codon_b = (x * 25) + (y * 5) + z;
400
401 if( is_stop_codon(codon_a,ct) || is_stop_codon(codon_b,ct) ) {
402 out->codon[p] = 0.0;
403 continue;
404 }
405
406 /* else */
407 out->codon[p] = codon_matrix->prob[codon_a][codon_b];
408
409 }
410 }
411 }
412 }
413 }
414 }
415
416 /* now to do blank and gap scores */
417
418 for(a=0;a<5;a++) {
419 for(b=0;b<5;b++) {
420 for(c=0;c<5;c++) {
421
422 codon_a = (a * 25) + (b * 5) + c;
423
424 seq[0] = MAKE_PAIRBASE(a,BASE_GAP);
425 seq[1] = MAKE_PAIRBASE(b,BASE_GAP);
426 seq[2] = MAKE_PAIRBASE(c,BASE_GAP);
427
428 p = pairbase_codon_from_seq(seq);
429
430 if( is_stop_codon(codon_a,ct) ) {
431 out->codon[p] = 0.0;
432 } else {
433 out->codon[p] = gap;
434 }
435
436 seq[0] = MAKE_PAIRBASE(BASE_GAP,a);
437 seq[1] = MAKE_PAIRBASE(BASE_GAP,b);
438 seq[2] = MAKE_PAIRBASE(BASE_GAP,c);
439
440 p = pairbase_codon_from_seq(seq);
441
442 if( is_stop_codon(codon_a,ct) ) {
443 out->codon[p] = 0.0;
444 } else {
445 out->codon[p] = gap;
446 }
447
448
449 seq[0] = MAKE_PAIRBASE(a,BASE_OPEN);
450 seq[1] = MAKE_PAIRBASE(b,BASE_OPEN);
451 seq[2] = MAKE_PAIRBASE(c,BASE_OPEN);
452
453 p = pairbase_codon_from_seq(seq);
454
455 if( is_stop_codon(codon_a,ct) ) {
456 out->codon[p] = 0.0;
457 } else {
458 out->codon[p] = nonm;
459 }
460
461 seq[0] = MAKE_PAIRBASE(BASE_OPEN,a);
462 seq[1] = MAKE_PAIRBASE(BASE_OPEN,b);
463 seq[2] = MAKE_PAIRBASE(BASE_OPEN,c);
464
465 p = pairbase_codon_from_seq(seq);
466
467 if( is_stop_codon(codon_a,ct) ) {
468 out->codon[p] = 0.0;
469 } else {
470 out->codon[p] = nonm;
471 }
472 }
473 }
474 }
475
476 return out;
477 }
478
479
480
481 /* Function: simple_PairBaseModel(iden,other,gap)
482 *
483 * Descrip: Makes a pair base model from simple leading diagonal
484 *
485 *
486 * Arg: iden [UNKN ] Undocumented argument [Probability]
487 * Arg: other [UNKN ] Undocumented argument [Probability]
488 * Arg: gap [UNKN ] Undocumented argument [Probability]
489 *
490 * Return [UNKN ] Undocumented return value [PairBaseModel *]
491 *
492 */
493 # line 427 "pairbase.dy"
simple_PairBaseModel(Probability iden,Probability other,Probability gap)494 PairBaseModel * simple_PairBaseModel(Probability iden,Probability other,Probability gap)
495 {
496 PairBaseModel * out;
497 int i;
498 int j;
499 int base;
500
501
502 out = PairBaseModel_alloc();
503
504 for(i=0;i<7;i++) {
505 for(j=0;j<7;j++) {
506 base = (i*7)+j;
507 if( i == 5 || j == 5 ) {
508 out->base[base]= gap/0.25;
509 } else if( i == 6 || j == 6 ) {
510 out->base[base]= 0.0;
511 } else if( i == 4 || j == 4 ) {
512 out->base[base]= 1.0;
513 } else if( i == j ) {
514 out->base[base]= iden / 0.25;
515 } else {
516 out->base[base]= other / 0.25;
517 }
518 }
519 }
520
521 return out;
522 }
523
524
525
526 /* Function: new_PairBaseCodonModelScore(pbcm)
527 *
528 * Descrip: Makes a codon score from a codon model
529 *
530 *
531 * Arg: pbcm [UNKN ] Undocumented argument [PairBaseCodonModel *]
532 *
533 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
534 *
535 */
536 # line 462 "pairbase.dy"
new_PairBaseCodonModelScore(PairBaseCodonModel * pbcm)537 PairBaseCodonModelScore * new_PairBaseCodonModelScore(PairBaseCodonModel * pbcm)
538 {
539 PairBaseCodonModelScore * out;
540
541 out = PairBaseCodonModelScore_alloc();
542
543 Probability2Score_move(pbcm->codon,out->codon,PAIRBASE_CODON_LENGTH);
544
545 return out;
546 }
547
548 /* Function: new_PairBaseModelScore(pbm)
549 *
550 * Descrip: Makes a base score from a base model
551 *
552 *
553 * Arg: pbm [UNKN ] Undocumented argument [PairBaseModel *]
554 *
555 * Return [UNKN ] Undocumented return value [PairBaseModelScore *]
556 *
557 */
558 # line 476 "pairbase.dy"
new_PairBaseModelScore(PairBaseModel * pbm)559 PairBaseModelScore * new_PairBaseModelScore(PairBaseModel * pbm)
560 {
561 PairBaseModelScore * out;
562
563 out = PairBaseModelScore_alloc();
564
565 Probability2Score_move(pbm->base,out->base,PAIRBASE_LENGTH);
566
567 return out;
568 }
569
570 /* Function: show_PairBaseModelScore(sc,ofp)
571 *
572 * Descrip: Debugging
573 *
574 *
575 * Arg: sc [UNKN ] Undocumented argument [PairBaseModelScore *]
576 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
577 *
578 */
579 # line 490 "pairbase.dy"
show_PairBaseModelScore(PairBaseModelScore * sc,FILE * ofp)580 void show_PairBaseModelScore(PairBaseModelScore * sc,FILE * ofp)
581 {
582 int i;
583 int anchor;
584 int informant;
585
586
587 for(i=0;i<PAIRBASE_LENGTH;i++) {
588 anchor =anchor_base_from_pairbase(i);
589 informant = informant_base_from_pairbase(i);
590
591 fprintf(ofp," %2d %c %c %d\n",i,char_for_base(anchor),char_for_base(informant),sc->base[i]);
592 }
593
594 }
595
596 /* Function: show_PairBaseCodonModelScore(sc,ct,ofp)
597 *
598 * Descrip: Debugging
599 *
600 *
601 * Arg: sc [UNKN ] Undocumented argument [PairBaseCodonModelScore *]
602 * Arg: ct [UNKN ] Undocumented argument [CodonTable *]
603 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
604 *
605 */
606 # line 509 "pairbase.dy"
show_PairBaseCodonModelScore(PairBaseCodonModelScore * sc,CodonTable * ct,FILE * ofp)607 void show_PairBaseCodonModelScore(PairBaseCodonModelScore * sc,CodonTable * ct,FILE * ofp)
608 {
609 int i;
610 pairbase_type a;
611 pairbase_type b;
612 pairbase_type c;
613
614 int anchor_a;
615 int anchor_b;
616 int anchor_c;
617
618 int informant_a;
619 int informant_b;
620 int informant_c;
621
622 char seq1[4];
623 char seq2[4];
624
625 seq1[3] = seq2[3] = '\0';
626
627 for(i=0;i<PAIRBASE_CODON_LENGTH;i++) {
628 decompose_pairbase_codon(i,&a,&b,&c);
629
630 anchor_a = anchor_base_from_pairbase(a);
631 anchor_b = anchor_base_from_pairbase(b);
632 anchor_c = anchor_base_from_pairbase(c);
633
634 informant_a = informant_base_from_pairbase(a);
635 informant_b = informant_base_from_pairbase(b);
636 informant_c = informant_base_from_pairbase(c);
637
638 seq1[0] = char_for_base(anchor_a);
639 seq1[1] = char_for_base(anchor_b);
640 seq1[2] = char_for_base(anchor_c);
641
642 seq2[0] = char_for_base(informant_a);
643 seq2[1] = char_for_base(informant_b);
644 seq2[2] = char_for_base(informant_c);
645
646
647 fprintf(ofp,"%9d %s[%c] %s[%c] : %d\n",i,seq1,aminoacid_from_seq(ct,seq1),seq2,aminoacid_from_seq(ct,seq2),sc->codon[i]);
648
649 }
650
651 }
652
653 /* Function: reverse_pairbase_codon(codon)
654 *
655 * Descrip: Inverts pairbase codon
656 *
657 *
658 * Arg: codon [UNKN ] Undocumented argument [pairbase_codon_type]
659 *
660 * Return [UNKN ] Undocumented return value [pairbase_codon_type]
661 *
662 */
663 # line 558 "pairbase.dy"
reverse_pairbase_codon(pairbase_codon_type codon)664 pairbase_codon_type reverse_pairbase_codon(pairbase_codon_type codon)
665 {
666 pairbase_type a;
667 pairbase_type b;
668 pairbase_type c;
669
670 decompose_pairbase_codon(codon,&a,&b,&c);
671
672 a = complement_pairbase(a);
673 b = complement_pairbase(b);
674 c = complement_pairbase(c);
675
676 return (c*(PAIRBASE_LENGTH*PAIRBASE_LENGTH))+(b*PAIRBASE_LENGTH)+a;
677 }
678
679
680 /* Function: complement_pairbase(b)
681 *
682 * Descrip: complements a pairbase
683 *
684 *
685 * Arg: b [UNKN ] Undocumented argument [pairbase_type]
686 *
687 * Return [UNKN ] Undocumented return value [pairbase_type]
688 *
689 */
690 # line 577 "pairbase.dy"
complement_pairbase(pairbase_type b)691 pairbase_type complement_pairbase(pairbase_type b)
692 {
693 pairbase_type anchor;
694 pairbase_type informant;
695
696 anchor = anchor_base_from_pairbase(b);
697 informant = informant_base_from_pairbase(b);
698
699 /* we reverse completement anchor */
700
701 anchor = complement_base(anchor);
702
703 if( informant != BASE_GAP && informant != BASE_OPEN ) {
704 informant = complement_base(informant);
705 }
706
707 return MAKE_PAIRBASE(anchor,informant);
708 }
709
710
711 /* Function: pairbase_codon_from_seq(seq)
712 *
713 * Descrip: Makes a pairbase_codon from a pairbase_sequence
714 *
715 *
716 * Arg: seq [UNKN ] Undocumented argument [pairbase_type *]
717 *
718 * Return [UNKN ] Undocumented return value [pairbase_codon_type]
719 *
720 */
721 # line 600 "pairbase.dy"
pairbase_codon_from_seq(pairbase_type * seq)722 pairbase_codon_type pairbase_codon_from_seq(pairbase_type * seq)
723 {
724 pairbase_type one;
725 pairbase_type two;
726 pairbase_type three;
727
728 one = (*seq);
729 two = (*(seq+1));
730 three = (*(seq+2));
731
732 return (one*(PAIRBASE_LENGTH*PAIRBASE_LENGTH))+(two*PAIRBASE_LENGTH)+three;
733 }
734
735
736
737 /* Function: decompose_pairbase_codon(t,a,b,c)
738 *
739 * Descrip: Decomposes a pairbase codon
740 *
741 *
742 * Arg: t [UNKN ] Undocumented argument [pairbase_codon_type]
743 * Arg: a [UNKN ] Undocumented argument [pairbase_type *]
744 * Arg: b [UNKN ] Undocumented argument [pairbase_type *]
745 * Arg: c [UNKN ] Undocumented argument [pairbase_type *]
746 *
747 */
748 # line 618 "pairbase.dy"
decompose_pairbase_codon(pairbase_codon_type t,pairbase_type * a,pairbase_type * b,pairbase_type * c)749 void decompose_pairbase_codon(pairbase_codon_type t,pairbase_type * a,pairbase_type * b,pairbase_type * c)
750 {
751 assert(a);
752 assert(b);
753 assert(c);
754
755 *a = t/(PAIRBASE_LENGTH*PAIRBASE_LENGTH);
756 t -= (*a) * (PAIRBASE_LENGTH*PAIRBASE_LENGTH);
757
758 *b = t/PAIRBASE_LENGTH;
759 t -= (*b) * PAIRBASE_LENGTH;
760
761 *c = t;
762
763 }
764
765
766 /* Function: anchor_base_from_pairbase(pairbase)
767 *
768 * Descrip: Finds the anchor base from a pair base
769 *
770 *
771 * Arg: pairbase [UNKN ] Undocumented argument [pairbase_type]
772 *
773 * Return [UNKN ] Undocumented return value [base]
774 *
775 */
776 # line 638 "pairbase.dy"
anchor_base_from_pairbase(pairbase_type pairbase)777 base anchor_base_from_pairbase(pairbase_type pairbase)
778 {
779 int top;
780
781 top = (int)pairbase / 7;
782
783 return top;
784 }
785
786 /* Function: informant_base_from_pairbase(pairbase)
787 *
788 * Descrip: Finds the informant base from a pair base
789 *
790 *
791 * Arg: pairbase [UNKN ] Undocumented argument [pairbase_type]
792 *
793 * Return [UNKN ] Undocumented return value [base]
794 *
795 */
796 # line 650 "pairbase.dy"
informant_base_from_pairbase(pairbase_type pairbase)797 base informant_base_from_pairbase(pairbase_type pairbase)
798 {
799 int top;
800
801 top = (int) pairbase /7;
802 pairbase -= top*7;
803
804 return pairbase;
805 }
806
807
808 /* Function: char_for_base(base)
809 *
810 * Descrip: gives back the character for the base
811 *
812 *
813 * Arg: base [UNKN ] Undocumented argument [int]
814 *
815 * Return [UNKN ] Undocumented return value [char]
816 *
817 */
818 # line 664 "pairbase.dy"
char_for_base(int base)819 char char_for_base(int base)
820 {
821 if( base < 5 ) {
822 return char_from_base(base);
823 }
824 if( base == BASE_GAP ) {
825 return '-';
826 } else {
827 return ' ';
828 }
829 }
830
831
832
833
834
835
836
837
838
839
840 # line 795 "pairbase.c"
841 /* Function: hard_link_PairBaseModel(obj)
842 *
843 * Descrip: Bumps up the reference count of the object
844 * Meaning that multiple pointers can 'own' it
845 *
846 *
847 * Arg: obj [UNKN ] Object to be hard linked [PairBaseModel *]
848 *
849 * Return [UNKN ] Undocumented return value [PairBaseModel *]
850 *
851 */
hard_link_PairBaseModel(PairBaseModel * obj)852 PairBaseModel * hard_link_PairBaseModel(PairBaseModel * obj)
853 {
854 if( obj == NULL ) {
855 warn("Trying to hard link to a PairBaseModel object: passed a NULL object");
856 return NULL;
857 }
858 obj->dynamite_hard_link++;
859 return obj;
860 }
861
862
863 /* Function: PairBaseModel_alloc(void)
864 *
865 * Descrip: Allocates structure: assigns defaults if given
866 *
867 *
868 *
869 * Return [UNKN ] Undocumented return value [PairBaseModel *]
870 *
871 */
PairBaseModel_alloc(void)872 PairBaseModel * PairBaseModel_alloc(void)
873 {
874 PairBaseModel * out;/* out is exported at end of function */
875
876
877 /* call ckalloc and see if NULL */
878 if((out=(PairBaseModel *) ckalloc (sizeof(PairBaseModel))) == NULL) {
879 warn("PairBaseModel_alloc failed ");
880 return NULL; /* calling function should respond! */
881 }
882 out->dynamite_hard_link = 1;
883 #ifdef PTHREAD
884 pthread_mutex_init(&(out->dynamite_mutex),NULL);
885 #endif
886 /* base[PAIRBASE_LENGTH] is an array: no default possible */
887
888
889 return out;
890 }
891
892
893 /* Function: free_PairBaseModel(obj)
894 *
895 * Descrip: Free Function: removes the memory held by obj
896 * Will chain up to owned members and clear all lists
897 *
898 *
899 * Arg: obj [UNKN ] Object that is free'd [PairBaseModel *]
900 *
901 * Return [UNKN ] Undocumented return value [PairBaseModel *]
902 *
903 */
free_PairBaseModel(PairBaseModel * obj)904 PairBaseModel * free_PairBaseModel(PairBaseModel * obj)
905 {
906 int return_early = 0;
907
908
909 if( obj == NULL) {
910 warn("Attempting to free a NULL pointer to a PairBaseModel obj. Should be trappable");
911 return NULL;
912 }
913
914
915 #ifdef PTHREAD
916 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
917 #endif
918 if( obj->dynamite_hard_link > 1) {
919 return_early = 1;
920 obj->dynamite_hard_link--;
921 }
922 #ifdef PTHREAD
923 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
924 #endif
925 if( return_early == 1)
926 return NULL;
927
928
929 ckfree(obj);
930 return NULL;
931 }
932
933
934 /* Function: hard_link_PairBaseCodonModel(obj)
935 *
936 * Descrip: Bumps up the reference count of the object
937 * Meaning that multiple pointers can 'own' it
938 *
939 *
940 * Arg: obj [UNKN ] Object to be hard linked [PairBaseCodonModel *]
941 *
942 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
943 *
944 */
hard_link_PairBaseCodonModel(PairBaseCodonModel * obj)945 PairBaseCodonModel * hard_link_PairBaseCodonModel(PairBaseCodonModel * obj)
946 {
947 if( obj == NULL ) {
948 warn("Trying to hard link to a PairBaseCodonModel object: passed a NULL object");
949 return NULL;
950 }
951 obj->dynamite_hard_link++;
952 return obj;
953 }
954
955
956 /* Function: PairBaseCodonModel_alloc(void)
957 *
958 * Descrip: Allocates structure: assigns defaults if given
959 *
960 *
961 *
962 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
963 *
964 */
PairBaseCodonModel_alloc(void)965 PairBaseCodonModel * PairBaseCodonModel_alloc(void)
966 {
967 PairBaseCodonModel * out; /* out is exported at end of function */
968
969
970 /* call ckalloc and see if NULL */
971 if((out=(PairBaseCodonModel *) ckalloc (sizeof(PairBaseCodonModel))) == NULL) {
972 warn("PairBaseCodonModel_alloc failed ");
973 return NULL; /* calling function should respond! */
974 }
975 out->dynamite_hard_link = 1;
976 #ifdef PTHREAD
977 pthread_mutex_init(&(out->dynamite_mutex),NULL);
978 #endif
979 /* codon[PAIRBASE_CODON_LENGTH] is an array: no default possible */
980
981
982 return out;
983 }
984
985
986 /* Function: free_PairBaseCodonModel(obj)
987 *
988 * Descrip: Free Function: removes the memory held by obj
989 * Will chain up to owned members and clear all lists
990 *
991 *
992 * Arg: obj [UNKN ] Object that is free'd [PairBaseCodonModel *]
993 *
994 * Return [UNKN ] Undocumented return value [PairBaseCodonModel *]
995 *
996 */
free_PairBaseCodonModel(PairBaseCodonModel * obj)997 PairBaseCodonModel * free_PairBaseCodonModel(PairBaseCodonModel * obj)
998 {
999 int return_early = 0;
1000
1001
1002 if( obj == NULL) {
1003 warn("Attempting to free a NULL pointer to a PairBaseCodonModel obj. Should be trappable");
1004 return NULL;
1005 }
1006
1007
1008 #ifdef PTHREAD
1009 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1010 #endif
1011 if( obj->dynamite_hard_link > 1) {
1012 return_early = 1;
1013 obj->dynamite_hard_link--;
1014 }
1015 #ifdef PTHREAD
1016 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1017 #endif
1018 if( return_early == 1)
1019 return NULL;
1020
1021
1022 ckfree(obj);
1023 return NULL;
1024 }
1025
1026
1027 /* Function: hard_link_PairBaseModelScore(obj)
1028 *
1029 * Descrip: Bumps up the reference count of the object
1030 * Meaning that multiple pointers can 'own' it
1031 *
1032 *
1033 * Arg: obj [UNKN ] Object to be hard linked [PairBaseModelScore *]
1034 *
1035 * Return [UNKN ] Undocumented return value [PairBaseModelScore *]
1036 *
1037 */
hard_link_PairBaseModelScore(PairBaseModelScore * obj)1038 PairBaseModelScore * hard_link_PairBaseModelScore(PairBaseModelScore * obj)
1039 {
1040 if( obj == NULL ) {
1041 warn("Trying to hard link to a PairBaseModelScore object: passed a NULL object");
1042 return NULL;
1043 }
1044 obj->dynamite_hard_link++;
1045 return obj;
1046 }
1047
1048
1049 /* Function: PairBaseModelScore_alloc(void)
1050 *
1051 * Descrip: Allocates structure: assigns defaults if given
1052 *
1053 *
1054 *
1055 * Return [UNKN ] Undocumented return value [PairBaseModelScore *]
1056 *
1057 */
PairBaseModelScore_alloc(void)1058 PairBaseModelScore * PairBaseModelScore_alloc(void)
1059 {
1060 PairBaseModelScore * out; /* out is exported at end of function */
1061
1062
1063 /* call ckalloc and see if NULL */
1064 if((out=(PairBaseModelScore *) ckalloc (sizeof(PairBaseModelScore))) == NULL) {
1065 warn("PairBaseModelScore_alloc failed ");
1066 return NULL; /* calling function should respond! */
1067 }
1068 out->dynamite_hard_link = 1;
1069 #ifdef PTHREAD
1070 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1071 #endif
1072 /* base[PAIRBASE_LENGTH] is an array: no default possible */
1073
1074
1075 return out;
1076 }
1077
1078
1079 /* Function: free_PairBaseModelScore(obj)
1080 *
1081 * Descrip: Free Function: removes the memory held by obj
1082 * Will chain up to owned members and clear all lists
1083 *
1084 *
1085 * Arg: obj [UNKN ] Object that is free'd [PairBaseModelScore *]
1086 *
1087 * Return [UNKN ] Undocumented return value [PairBaseModelScore *]
1088 *
1089 */
free_PairBaseModelScore(PairBaseModelScore * obj)1090 PairBaseModelScore * free_PairBaseModelScore(PairBaseModelScore * obj)
1091 {
1092 int return_early = 0;
1093
1094
1095 if( obj == NULL) {
1096 warn("Attempting to free a NULL pointer to a PairBaseModelScore obj. Should be trappable");
1097 return NULL;
1098 }
1099
1100
1101 #ifdef PTHREAD
1102 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1103 #endif
1104 if( obj->dynamite_hard_link > 1) {
1105 return_early = 1;
1106 obj->dynamite_hard_link--;
1107 }
1108 #ifdef PTHREAD
1109 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1110 #endif
1111 if( return_early == 1)
1112 return NULL;
1113
1114
1115 ckfree(obj);
1116 return NULL;
1117 }
1118
1119
1120 /* Function: hard_link_PairBaseCodonModelScore(obj)
1121 *
1122 * Descrip: Bumps up the reference count of the object
1123 * Meaning that multiple pointers can 'own' it
1124 *
1125 *
1126 * Arg: obj [UNKN ] Object to be hard linked [PairBaseCodonModelScore *]
1127 *
1128 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
1129 *
1130 */
hard_link_PairBaseCodonModelScore(PairBaseCodonModelScore * obj)1131 PairBaseCodonModelScore * hard_link_PairBaseCodonModelScore(PairBaseCodonModelScore * obj)
1132 {
1133 if( obj == NULL ) {
1134 warn("Trying to hard link to a PairBaseCodonModelScore object: passed a NULL object");
1135 return NULL;
1136 }
1137 obj->dynamite_hard_link++;
1138 return obj;
1139 }
1140
1141
1142 /* Function: PairBaseCodonModelScore_alloc(void)
1143 *
1144 * Descrip: Allocates structure: assigns defaults if given
1145 *
1146 *
1147 *
1148 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
1149 *
1150 */
PairBaseCodonModelScore_alloc(void)1151 PairBaseCodonModelScore * PairBaseCodonModelScore_alloc(void)
1152 {
1153 PairBaseCodonModelScore * out; /* out is exported at end of function */
1154
1155
1156 /* call ckalloc and see if NULL */
1157 if((out=(PairBaseCodonModelScore *) ckalloc (sizeof(PairBaseCodonModelScore))) == NULL) {
1158 warn("PairBaseCodonModelScore_alloc failed ");
1159 return NULL; /* calling function should respond! */
1160 }
1161 out->dynamite_hard_link = 1;
1162 #ifdef PTHREAD
1163 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1164 #endif
1165 /* codon[PAIRBASE_CODON_LENGTH] is an array: no default possible */
1166
1167
1168 return out;
1169 }
1170
1171
1172 /* Function: free_PairBaseCodonModelScore(obj)
1173 *
1174 * Descrip: Free Function: removes the memory held by obj
1175 * Will chain up to owned members and clear all lists
1176 *
1177 *
1178 * Arg: obj [UNKN ] Object that is free'd [PairBaseCodonModelScore *]
1179 *
1180 * Return [UNKN ] Undocumented return value [PairBaseCodonModelScore *]
1181 *
1182 */
free_PairBaseCodonModelScore(PairBaseCodonModelScore * obj)1183 PairBaseCodonModelScore * free_PairBaseCodonModelScore(PairBaseCodonModelScore * obj)
1184 {
1185 int return_early = 0;
1186
1187
1188 if( obj == NULL) {
1189 warn("Attempting to free a NULL pointer to a PairBaseCodonModelScore obj. Should be trappable");
1190 return NULL;
1191 }
1192
1193
1194 #ifdef PTHREAD
1195 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1196 #endif
1197 if( obj->dynamite_hard_link > 1) {
1198 return_early = 1;
1199 obj->dynamite_hard_link--;
1200 }
1201 #ifdef PTHREAD
1202 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1203 #endif
1204 if( return_early == 1)
1205 return NULL;
1206
1207
1208 ckfree(obj);
1209 return NULL;
1210 }
1211
1212
1213
1214 #ifdef _cplusplus
1215 }
1216 #endif
1217