File: genefrequency.dy

package info (click to toggle)
wise 2.4.1-21
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 27,140 kB
  • sloc: ansic: 276,365; makefile: 1,003; perl: 886; lex: 93; yacc: 81; sh: 24
file content (963 lines) | stat: -rw-r--r-- 21,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
/*  Last edited: Apr 22 17:49 1997 (birney) */



%{
#include "probability.h"
#include "codon.h"
#include "wisebase.h"
#include "dyna.h"
#include "randommodel.h"

enum {
  GF21_CENTRAL_STAY,
  GF21_PY_STAY,
  GF21_SPACER_STAY,
  GF21_NO_SPACER,
  GF21_INTRON_CORR_TERM,
  GENEFREQUENCY21_TRANSITION_LEN
};

#define GeneConsensusLISTLENGTH 128

enum {
  GeneConsensusType_5SS = 131,
  GeneConsensusType_3SS,
  GeneConsensusType_CDS,
  GeneConsensusType_Intron_Corr_Term,
  GeneConsensusType_Intron_emission,
  GeneConsensusType_Pyrimidine_emission,
  GeneConsensusType_Spacer_emission,
  GeneConsensusType_Central_stay,
  GeneConsensusType_Pyrimidine_stay,
  GeneConsensusType_Spacer_stay,
  GeneConsensusType_No_spacer,
  GeneConsensusType_Error
};


%}



struct GeneSingleCons
char * string
double number

struct GeneConsensus
int center
GeneSingleCons ** gsc !list

struct GeneFrequency21
GeneConsensus * ss5
GeneConsensus * ss3
double codon[64]
double central[4]
double py[4]
double spacer[4]
double transition[GENEFREQUENCY21_TRANSITION_LEN]
double cds_triplet[64] // phase 0


api
object GeneFrequency21
des free_GeneFrequency21
endobject
object GeneConsensus
des    free_GeneConsensus
endobject
object GeneSingleCons
des    free_GeneSingleCons
endobject
func read_GeneFrequency21_file
func read_GeneFrequency21
endapi

%{
#include "genefrequency.h"

%func
makes a randomcodon probability emission
from the counts in genefrequency
%%
RandomCodon * RandomCodon_from_cds_triplet(GeneFrequency21 * gf)
{
  int i;
  int a,b,c;
  double total;
  double lit;

  RandomCodon * out;

  out = RandomCodon_alloc();

  for(i=0,total=0;i<64;i++)
    total += gf->cds_triplet[i];
  
  for(i=0;i<125;i++) {
    if( has_random_bases(i) ) {
      lit = 0.0;
      for(a=0;a<4;a++)
	for(b=0;b<4;b++)
	  for(c=0;c<4;c++)
	    lit += gf->cds_triplet[base4_codon_from_codon(permute_possible_random_bases(i,a,b,c))];
      out->codon[i] = lit/(64*total);
    } else {
      out->codon[i] = gf->cds_triplet[base4_codon_from_codon(i)]/(total);
    }
  }

  return out;
}


%func
Makes a random model from the central gene 
model of an intron. Ideal for tieing intron
state distribution to the randommodel
%%
RandomModelDNA * RandomModelDNA_from_central_GeneFrequency21(GeneFrequency21 * gf)
{
  RandomModelDNA * out;
  double total;

  total = sum_Probability_array(gf->central,4);


  out = RandomModelDNA_alloc();

  out->base[BASE_A] = gf->central[BASE_A]/total;
  out->base[BASE_T] = gf->central[BASE_T]/total;
  out->base[BASE_G] = gf->central[BASE_G]/total;
  out->base[BASE_C] = gf->central[BASE_C]/total;
  out->base[BASE_N] = 1.0;

  return out;
}

%func
makes 5'SS ComplexConsensi from GeneFrequency21 structure using

  CCC|XXXXXXX score = no(5'SS with CCC|XXXXXXX) / no(CCC in cds).
%%
ComplexConsensi * ComplexConsensi_5SS_from_GeneFrequency(GeneFrequency21 * gf)
{
  register int i;
  double nocds;
  ComplexConsensi * out;

  out = ComplexConsensi_alloc_len(gf->ss5->len);



  for(i=0;i<gf->ss5->len;i++) {
    nocds = nocds_from_ambiguous_codon(gf->ss5->gsc[i]->string,gf->cds_triplet);
    if( nocds < 20 ) {
      warn("In making 5'SS consensi, got %g cds for codon %s ... not happy about this",nocds,gf->ss5->gsc[i]->string);
    }
    add_ComplexConsensi(out,ComplexConsensusWord_from_string_and_prob(gf->ss5->gsc[i]->string,gf->ss5->gsc[i]->number / nocds));
  }

  return out;
  
}

%func
makes 3'SS ComplexConsensi from GeneFrequency21 structure using

  ZZZ|CCC score = no(3'SS with ZZZ|CCC) / no(CCC in cds).
%%
ComplexConsensi * ComplexConsensi_3SS_from_GeneFrequency(GeneFrequency21 * gf)
{
  register int i;
  double nocds;
  ComplexConsensi * out;

  out = ComplexConsensi_alloc_len(gf->ss3->len);

  for(i=0;i<gf->ss3->len;i++) {
    nocds = nocds_from_ambiguous_codon(gf->ss3->gsc[i]->string+3,gf->cds_triplet);
    if( nocds < 20 ) {
      warn("In making 3'SS consensi, got %g cds for codon %s ... not happy about this!",nocds,gf->ss3->gsc[i]->string);
    }
    add_ComplexConsensi(out,ComplexConsensusWord_from_string_and_prob(gf->ss3->gsc[i]->string,gf->ss3->gsc[i]->number / nocds));
  }

  return out;
  
}

%func
helper function for above guys
%type internal
%%
double nocds_from_ambiguous_codon(char * codon,double * codon_freq_array)
{
  int factor = 1;
  int one;
  int two;
  int three;
  int i,j,k;
  double ret = 0.0;

  one = base_from_char(*codon == '-' ? 'N' : *codon);
  two = base_from_char(*(codon+1) == '-' ? 'N' : *(codon+1));
  three = base_from_char(*(codon+2) == '-' ? 'N' : *(codon+2));


  if(one == BASE_N)
    factor *= 4;
  if(two == BASE_N)
    factor *= 4;
  if(three == BASE_N)
    factor *= 4;
  

  for(i=0;i<4;i++)
    for(j=0;j<4;j++) 
      for(k=0;k<4;k++) 
	if( (one == i || one == BASE_N) && (two == j || two == BASE_N) && (three == k || three == BASE_N)) { 
	  ret += codon_freq_array[i*16+j*4+k];
	}
  

  ret = ret / factor;

  if( ret < 0.0000000000000001 ) {
    warn("For codon  %c%c%c we have a frequency of %g",*codon,*(codon+1),*(codon+2),ret);
    ret = 0.0000000000000001;
  }

  return ret;
}

%func
convienent constructor
%type internal
%%
ComplexConsensusWord * ComplexConsensusWord_from_string_and_prob(char * string,Probability p)
{
  ComplexConsensusWord * out;

  out = ComplexConsensusWord_alloc();

  out->pattern = stringalloc(string);
  out->p = p;
  out->score = Probability2Score(p);

  return out;
}


%func
Builds a codon frequency table from raw counts
in the counts file
%%
CodonFrequency * CodonFrequency_from_GeneFrequency21(GeneFrequency21 * gf,CodonTable * ct)
{
  return CodonFrequence_from_raw_counts(gf->codon,ct);
}


%func
For debugging
%type internal
%%
void show_flat_GeneFrequency21(GeneFrequency21 * gf21,FILE * ofp)
{
  if( gf21->ss5 != NULL ) {
    fprintf(ofp,"5'SS\n");
    show_GeneConsensus(gf21->ss5,ofp);
  }
  if( gf21->ss3 != NULL ) {
    fprintf(ofp,"3'SS\n");
    show_GeneConsensus(gf21->ss3,ofp);
  }

  fprintf(ofp,"Codon frequency\n");
  show_codon_emission(gf21->codon,ofp);

  fprintf(ofp,"Central emission\n");
  show_base_emission(gf21->central,ofp);

  fprintf(ofp,"Pyrimidine emission\n");
  show_base_emission(gf21->py,ofp);

  fprintf(ofp,"Spacer emission\n");
  show_base_emission(gf21->spacer,ofp);

  fprintf(ofp,"Transitions\n");
  show_Probability_array(gf21->transition,GENEFREQUENCY21_TRANSITION_LEN,ofp);

  fprintf(ofp,"\n\n");
}

%func
For debugging
%type internal
%%
void show_codon_emission(double * codon,FILE * ofp)
{
  register int i;

  fprintf(ofp,"begin consensus\n");

  for(i=0;i<64;i++) 
    show_single_codon_emission(codon[i],i,ofp);

  fprintf(ofp,"end consensus\n");
}

%func
For debugging
%type internal
%%
void show_single_codon_emission(double no,int base4codon,FILE * ofp)
{
  codon c;
  base one;
  base two;
  base three;

  c = codon_from_base4_codon(base4codon);

  all_bases_from_codon(c,&one,&two,&three);

  fprintf(ofp,"%c%c%c %.2f\n",char_from_base(one),char_from_base(two),char_from_base(three),no);
}

%func
For debugging
%type internal
%%
void show_base_emission(double * base,FILE * ofp)
{
  register int i;

  fprintf(ofp,"begin consensus\n");

  for(i=0;i<4;i++)
    fprintf(ofp,"%c %.2f\n",char_from_base(i),base[i]);

  fprintf(ofp,"end consensus\n");
}


%func
For debugging
%type internal
%%
void show_GeneConsensus(GeneConsensus * gc,FILE * ofp)
{
  register int i;

  fprintf(ofp,"begin consensus\n");

  for(i=0;i<gc->len;i++)
    show_GeneSingleCons(gc->gsc[i],ofp);

  fprintf(ofp,"end consensus\n");
}


%func
For debugging
%type internal
%%
void show_GeneSingleCons(GeneSingleCons * gsc,FILE * ofp)
{
  fprintf(ofp,"%s %f\n",gsc->string,gsc->number);
}




 /*** reading in ***/

%func
Opens the file with /openfile

Reads in a GeneFrequency (Mor-Ewan style)

%arg
filename will open from WISECONFIGDIR etc via openfile
return a newly allocated structure
%%
GeneFrequency21 * read_GeneFrequency21_file(char * filename)
{
  GeneFrequency21 * out;
  FILE * ifp;

  ifp = openfile(filename,"r");

  if( ifp == NULL ) {
    warn("Could not open %s as a genefrequency file",filename);
    return NULL;
  }

  out = read_GeneFrequency21(ifp);

  fclose(ifp);

  return out;
}

%func
Reads in a GeneFrequency (Mor-Ewan style)
file from ifp
%arg
ifp file pointer
return a newly allocated structure
%%
GeneFrequency21 * read_GeneFrequency21(FILE * ifp)
{
  GeneFrequency21 * out;
  GeneConsensus   * temp;
  char buffer[MAXLINE];
  int phase;
  int center;
  int type;
  boolean err = FALSE;

  out = GeneFrequency21_alloc();

  while( fgets(buffer,MAXLINE,ifp) != NULL ) {
    if( buffer[0] == '#' )
      continue;


    if( strwhitestartcmp(buffer,"type",spacestr) == 0 ) {

      phase = 3; /** if no phase, assumme it is for all phases **/

      type = check_type_GeneFrequency(buffer,ifp,&center,&phase);
      
      switch(type) {
      case GeneConsensusType_5SS :
	if( phase == 3) {
	  temp = read_line_GeneConsensus(buffer,ifp);
	  temp->center = center;
	  out->ss5 = temp;
	}
	else {
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd 5'SS information ... problem!");
	    break;
	  }
	}
	break;
      case GeneConsensusType_3SS :
	if( phase == 3) {
	  temp = read_line_GeneConsensus(buffer,ifp);
	  temp->center = center;
	  out->ss3 = temp;
	}
	else {
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd 5'SS information ... problem!");
	    err = TRUE;
	  }
	}
	break;
      case GeneConsensusType_CDS :
	if( phase == 0) {
	  if( read_codon_GeneConsensus(out->codon,buffer,ifp) == FALSE ) {
	    warn("Unable to read codon information in GeneFrequency21... problem!");
	    break;
	  }
	}
	else if( phase == 3 ) {
	  /*** we need this! ***/
	  if( read_codon_GeneConsensus(out->cds_triplet,buffer,ifp) == FALSE ) {
	    warn("Unable to read codon information in GeneFrequency21... problem!");
	    break;
	  }
	}
	else { /** in a different phase **/
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd CDS information ... problem!");
	    err = TRUE;
	  }
	}
	break;
      case GeneConsensusType_Intron_emission :
	if( phase == 3 ) {
	  if( read_base_GeneConsensus(out->central,buffer,ifp) == FALSE ) {
	    warn("Unable to read Intron emissions in genefrequency21 ... problem!");
	    err = TRUE;
	  }
	}
	else {
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd CDS information ... problem!");
	    err = TRUE;
	  }
	}
	break;
      case GeneConsensusType_Pyrimidine_emission :
	if( phase == 3 ) {
	  if( read_base_GeneConsensus(out->py,buffer,ifp) == FALSE ) {
	    warn("Unable to read pyrimidine emissions in genefrequency21 ... problem!");
	    err = TRUE;
	  }
	}
	else {
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd pyrimidine information ... problem!");
	    err = TRUE;
	  }
	}
	break;
      case GeneConsensusType_Spacer_emission :
	if( phase == 3 ) {
	  if( read_base_GeneConsensus(out->spacer,buffer,ifp) == FALSE ) {
	    warn("Unable to read spacer emissions in genefrequency21 ... problem!");
	    err = TRUE;
	  }
	}
	else {
	  if( skip_consensus(ifp) == FALSE ) {
	    warn("Unable to skip phase'd spacer information ... problem!");
	    err = TRUE;
	  }
	}
	break;
      case GeneConsensusType_Central_stay :
	out->transition[GF21_CENTRAL_STAY] = double_from_line(buffer);
	break;
      case GeneConsensusType_Pyrimidine_stay :
	out->transition[GF21_PY_STAY] = double_from_line(buffer);
	break;
      case GeneConsensusType_Spacer_stay :
	out->transition[GF21_SPACER_STAY] = double_from_line(buffer);
	break;
      case GeneConsensusType_No_spacer :
	out->transition[GF21_NO_SPACER] = double_from_line(buffer);
	break;
      case GeneConsensusType_Intron_Corr_Term :
	switch(phase) {
	case 0 :
/*	  out->transition[GF21_INTRON_CORR_TERM_0] = double_from_line(buffer); */
	  break;
	case 1 :
/*	  out->transition[GF21_INTRON_CORR_TERM_1] = double_from_line(buffer); */
	  break;
	case 2 :
/*	  out->transition[GF21_INTRON_CORR_TERM_2] = double_from_line(buffer); */
	  break;
	case 3 :
	  out->transition[GF21_INTRON_CORR_TERM] = double_from_line(buffer); 
	  break;
	default :
	  warn("Well... I have got some bad news for you. We found a phase of %d in Intron correction term. ",phase);
	  break;
	}
	break;
      default :
	warn("Got an unidenitifable type in GeneFrequency21 parse. Skippping");
	if( skip_consensus(ifp) == FALSE ) {
	  warn("Unable to skip phase'd 5'SS information ... problem!");
	  err = TRUE;
	}
	
      }

      if( err == TRUE ) {
	warn("You have had an unrecoverable error in GeneFrequency21 parsing");
	break;
      }

    }
    else {
      striptoprint(buffer);
      warn("Could not understand line [%s] in GeneFrequency21 parse",buffer);
    }
  }

  return out;
}
	
	
%func
helper string function
%%	
double double_from_line(char * buffer)
{
  char * runner;
  char * end;
  double ret;

  runner = strtok(buffer,spacestr);

  if( runner == NULL ) {
    warn("Unable to read a number in double_from_line");
    return -1.0;
  }

  ret = strtod(runner,&end);

  if( end == runner || isalnum((int)*end) ) {
    warn("Bad conversion of string [%s] to double [%f] occurred",runner,ret);
  }

  return ret;
}
  
%func
helper function for
teh file parsing
%type internal
%%
boolean skip_consensus(FILE * ifp)
{
  char buffer[MAXLINE];


  while(fgets(buffer,MAXLINE,ifp) != NULL ) 
    if( strwhitestartcmp(buffer,"end",spacestr) == 0)
      break;

  if( feof(ifp) || ferror(ifp) )
    return FALSE;
  return TRUE;
}


%func 
Pretty sneaky function 

give 

  line starting with "type xxx"
  ifp  file pointer
  centre a &int for returning the centre value of the consensus if any.
  phase  a &int for returning the phase value of the consensus if any.

you get *back* the line with the line "begin consensus" or "number" in it.

  
It returns a GeneConsensusType

with GeneConsensusType_Error on error

%%
int check_type_GeneFrequency(char *line,FILE * ifp,int * center,int * phase)  
{
  int ret = GeneConsensusType_Error;
  char * runner;


  if( strwhitestartcmp(line,"type",spacestr) != 0 ) {
    warn("Attempting to check phase of consensus with no type line...");
    return GeneConsensusType_Error;
  }

  runner = strtok(line,spacestr);
  runner = strtok(NULL,spacestr);

  if( runner == NULL ) {
    warn("GeneFrequency type with no type. Can't read type, must set to error, but problem in later parsing");
    ret = GeneConsensusType_Error;
  }

  else {
    ret = string_to_GeneConsensusType(runner);
  }

  while( fgets(line,MAXLINE,ifp) != NULL ) {
    if( line[0] == '#' )
      continue;

    else if( strwhitestartcmp(line,"phase",spacestr) == 0 ) {
      runner = strtok(line,spacestr);
      runner = strtok(NULL,spacestr);

      if( runner == NULL ) {
	warn("Got phase line with no phase. Sad....");
	continue;
      }
      

      if( phase != NULL ) {
	if( strcmp(runner,"all") ==0 || strcmp(runner,"All") == 0)
	  *phase = 3;
	else *phase = atoi(runner);
      }
    }

    else if( strwhitestartcmp(line,"center",spacestr) == 0 || strwhitestartcmp(line,"centre",spacestr) == 0) {
      runner = strtok(line,spacestr);
      runner = strtok(NULL,spacestr);

      if( runner == NULL ) {
	warn("Got center line with no phase. Sad....");
	continue;
      }

      if( center != NULL ) {
	*center = atoi(runner);
      }
    }
    else {
      break;
    }
  }



  return ret;
}

%func
flips string 5SS to enum type
%type internal
%%
int string_to_GeneConsensusType(char * string)
{


  if( strcmp(string,"5SS") == 0 )
    return GeneConsensusType_5SS;
  else if( strcmp(string,"3SS") == 0 )
    return GeneConsensusType_3SS;
  else if( strcmp(string,"CDS") == 0 )
    return GeneConsensusType_CDS;
  else if( strcmp(string,"Intron_Corr_Term") == 0 )
    return  GeneConsensusType_Intron_Corr_Term;
  else if( strcmp(string,"Intron_emission") == 0 )
    return  GeneConsensusType_Intron_emission;
  else if( strcmp(string,"Pyrimidine_emission") == 0 )
    return  GeneConsensusType_Pyrimidine_emission;
  else if( strcmp(string,"Spacer_emission") == 0 )
    return GeneConsensusType_Spacer_emission;
  else if( strcmp(string,"Central_Intron_Stay_Prob") == 0 )
    return GeneConsensusType_Central_stay;
  else if( strcmp(string,"Pyrimidine_Stay_Prob") == 0 )
    return GeneConsensusType_Pyrimidine_stay;
  else if( strcmp(string,"Spacer_Stay_Prob") == 0 )
    return GeneConsensusType_Spacer_stay;
  else if( strcmp(string,"No_Spacer_Prob") == 0 )
    return GeneConsensusType_No_spacer;
  else {
    warn("Could convert string [%s] into a gene frequency type",string);
    return GeneConsensusType_Error;
  }
}
  
%func
assummes base_array is 4 positions long
  
line should have begin consensus on it and be of MAXLINE length as it will be used as the buffer.
  
This does **not** check that you have filled up all 4 positions.
%%
boolean read_base_GeneConsensus(double * base_array,char* line,FILE * ifp)
{
  boolean ret = TRUE;
  int b;
  char * base;
  char * number;


  if( strwhitestartcmp(line,"begin",spacestr) != 0 || strstr(line,"consensus") == NULL ) {
    warn("In reading base GeneConsensus line, got no 'begin consensus' tag [%s]",line);
    return FALSE;
  }


  while( fgets(line,MAXLINE,ifp) != NULL ) {
    if( line[0] == '#' )
      continue;

    if( strwhitestartcmp(line,"end",spacestr) == 0 )
      break;

    base = strtok(line,spacestr);
    number = strtok(NULL,spacestr);

    if( base == NULL ) {
      warn("Found an uncommented line in base consensus with no leading base word");
      continue;
    }

    if( number == NULL ) {
      warn("For base %s, no number found",base);
      ret = FALSE;
      continue;
    }

    if( strlen(base) > 1 || (b=base_from_char(*base)) == BASE_N ) {
      warn("Could not interpret %s as an actual DNA base in read_base_GeneConsensus");
      ret = FALSE;
      continue;
    }

    base_array[b]= atof(number);

  }

  return ret;
}



%func
assummes codon_array is 64 positions long
  
line should have begin consensus on it and be of MAXLINE length as it will be used as the buffer.

This does **not** check that you have filled up all 64 positions.
%%
boolean read_codon_GeneConsensus(double * codon_array,char* line,FILE * ifp)
{
  boolean ret = TRUE;
  char * codon;
  char * number;


  if( strwhitestartcmp(line,"begin",spacestr) != 0 || strstr(line,"consensus") == NULL ) {
    warn("In reading codon GeneConsensus line, got no 'begin consensus' tag [%s]",line);
    return FALSE;
  }


  while( fgets(line,MAXLINE,ifp) != NULL ) {
    if( line[0] == '#' )
      continue;

    if( strwhitestartcmp(line,"end",spacestr) == 0 )
      break;

    codon = strtok(line,spacestr);
    number = strtok(NULL,spacestr);

    if( codon == NULL ) {
      warn("Found an uncommented line in codon consensus with no leading codon word");
      continue;
    }

    if( number == NULL ) {
      warn("For codon %s, no number found",codon);
      ret = FALSE;
      continue;
    }

    if( strchr(codon,'N') != NULL ) 
      continue;

    if( is_non_ambiguous_codon_seq(codon) == FALSE ) {
      warn("Codon %s is not really a codon... problem!");
      ret = FALSE;
      continue;
    }



    codon_array[base4_codon_from_seq(codon)]= atof(number);

  }

  return ret;
}
    
%func
Reads a single GeneConsensus from a file
%%
GeneConsensus  * read_line_GeneConsensus(char * line,FILE * ifp)
{
  GeneConsensus * out;
  GeneSingleCons * temp;
  char buffer[MAXLINE];
  char * runner;



  if( strwhitestartcmp(line,"begin",spacestr) != 0 ) {
    warn("Attempting to read a GeneConsensus structure with a line not starting with 'begin' [%s]",line);
    return NULL;
  }

  runner = strtok(line,spacestr);
  runner = strtok(NULL,spacestr);

  if( runner == NULL || strcmp(runner,"consensus") != 0 ) {
    warn("Attempting to read a GeneConsensus structure without a 'begin consensus' tag [%s]",line);
    return NULL;
  }

  out = GeneConsensus_alloc_std();

  while( fgets(buffer,MAXLINE,ifp) != NULL ) {
    if( buffer[0] == '#' )
      continue;
    if( strwhitestartcmp(buffer,"end",spacestr) == 0 )
      break;
    
   
    temp = read_line_GeneSingleCons(buffer);

    if( temp == NULL ) {
      warn("Unable to process GeneSingleCons line... dropping out...");
      break;
    }

    add_GeneConsensus(out,temp);
  }


  return out;
}
    


GeneSingleCons * read_line_GeneSingleCons(char * line)
{
  GeneSingleCons * out;
  char * runner;
  char * run2;


  runner = strtok(line,spacestr);
  run2   = strtok(NULL,spacestr);

  if( runner == NULL || run2 == NULL ) {
    warn("In read_line_GeneSingleCons was not give two different words in line [%s]",line);
    return NULL;
  }

  out = GeneSingleCons_alloc();

  out->string = stringalloc(runner);

  out->number = strtod(run2,&runner);

  if( runner == run2 || *runner != '\0' ) {
    warn("In read_line_GeneSingleCons, for string [%s], unable to convert the number [%s]",out->string,run2);
  }

  return out;
}


GeneFrequency21  * untouched_GeneFrequency21(void)
{
  register int i;
  GeneFrequency21 * out;

  out = GeneFrequency21_alloc();

  for(i=0;i<64;i++)
    out->codon[i] = (-1);

  for(i=0;i<4;i++)
    out->central[i] = out->py[i] = out->spacer[i] = (-1);
  
  for(i=0;i<GENEFREQUENCY21_TRANSITION_LEN;i++) 
    out->transition[i] = (-1.0);

  return out;
}



%}