test thing
[sws1-1415.git] / ass1 / mart / sws1-s4109503-s4202015 / exercise2 / parsegenome.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char* argv[])
5 {
6 if(argc != 2)
7 {
8 printf("Usage: %s filepath\n", argv[0]);
9 return 2;
10 }
11
12 char c;
13 int charsperline = 0;
14 int numlines = 0;
15 int occs[4] = {0, 0, 0, 0};
16
17 FILE *f = fopen(argv[1], "r");
18 if(f == NULL)
19 {
20 printf("Unable to open file...");
21 return 2;
22 }
23
24 while((c = fgetc(f)) != EOF)
25 {
26 if(c == '\n')
27 {
28 if(charsperline != 100 || numlines > 500)
29 return -1;
30 numlines += 1;
31 charsperline = 0;
32 }
33 else
34 {
35 /* Fancy polynome that translates A: 0, C: 1, G: 2, T: 3 */
36 if(c == 'A' || c == 'C' || c == 'G' || c == 'T')
37 occs[(int)(.001657140781*c*c*c-0.3780662484*c*c+28.74757194*c-726.3545635)] += 1;
38 else
39 return -1;
40 charsperline += 1;
41 }
42 }
43 fclose(f);
44 if(numlines != 500)
45 return -1;
46
47 printf("A: %d\nC: %d\nG: %d\nT: %d\n", occs[0], occs[1], occs[2], occs[3]);
48 return 0;
49 }