final ass1
[sws1-1415.git] / ass1 / mart / sws1-s4109503-s4202015 / exercise2 / parsegenome.c
1 #include <stdint.h> /* - Basically we save the 4 frequencies in a 64bit int */
2 #include <stdio.h> /* - The polynome fits the following coordinates: */
3 #include <stdlib.h> /* (65,0), (67, 16), (71, 32), (84, 48) */
4 #include <string.h> /* - Which is the mapping from ascii value and shiftwidth*/
5 /* - When no input file is given assume stdin */
6 int main(int argc, char* argv[])
7 {
8 char c;
9 char charsperline = 0;
10 short numlines = 0;
11 uint64_t occs = 0;
12 FILE *f = (argc!=2 || strcmp(argv[1], "-")==0) ? stdin : fopen(argv[1], "r");
13 if(f == NULL)
14 return 2;
15 while((c=fgetc(f)) != EOF)
16 if(c == '\n' && charsperline == 100 && numlines++ < 500)
17 charsperline = 0;
18 else if((c=='A' ||c=='C' || c=='G' || c=='T') && charsperline++<100)
19 occs += 1LL<<(char)(0.026514*c*c*c-6.049*c*c+459.96*c-11621.2);
20 else
21 break;
22 if(f != stdout)
23 fclose(f);
24 if(numlines!=500)
25 return -1;
26 printf("A:%u\nC:%u\nG:%u\nT:%u\n", (uint16_t)occs, (uint16_t)(occs>>16),
27 (uint16_t)(occs>>32), (uint16_t)(occs>>48));
28 return 0;
29 }