-mkdir -p sws1-s4109503-s4202015/exercise{1,2,3}
+mkdir -p sws1-s4109503-s4202015/exercise{1,2}
cd sws1-s4109503-s4202015
echo -e "s4109503: Mart Lubbers\ns4202015: Chris Kamphuis" > names.txt
du -sb | cut -f 1 > exercise1/1b.txt
-#include <stdint.h> /* - Basically we save the 4 frequencies in a 64bit int */
-#include <stdio.h> /* - The polynome fits the following coordinates: */
-#include <stdlib.h> /* (65,0), (67, 16), (71, 32), (84, 48) */
-#include <string.h> /* - Which is the mapping from ascii value and shiftwidth*/
- /* - When no input file is given assume stdin */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
int main(int argc, char* argv[])
{
+ char *alphabet = "AGTC";
char c;
- char charsperline = 0;
- short numlines = 0;
+ int charsperline = 0;
+ int numlines = 0;
uint64_t occs = 0;
- FILE *f = (argc!=2 || strcmp(argv[1], "-")==0) ? stdin : fopen(argv[1], "r");
+ FILE *f = argc != 2 ? stdin : fopen(argv[1], "r");
if(f == NULL)
return 2;
- while((c=fgetc(f)) != EOF)
+ while((c = fgetc(f)) != EOF)
if(c == '\n' && charsperline == 100 && numlines++ < 500)
charsperline = 0;
- else if((c=='A' ||c=='C' || c=='G' || c=='T') && charsperline++<100)
- occs += 1LL<<(char)(0.026514*c*c*c-6.049*c*c+459.96*c-11621.2);
+ else if(strchr(alphabet, c) && charsperline++ < 100)
+ occs += 1LL<<((int)(strchr(alphabet, c)-alphabet)*16);
else
break;
- if(f != stdout)
+ if(f != stdin)
fclose(f);
- if(numlines!=500)
+ if(numlines != 500)
return -1;
- printf("A:%u\nC:%u\nG:%u\nT:%u\n", (uint16_t)occs, (uint16_t)(occs>>16),
- (uint16_t)(occs>>32), (uint16_t)(occs>>48));
+ for(unsigned i=0; i<strlen(alphabet); i++)
+ printf("%c: %u\n", alphabet[i], (uint16_t)(occs >> (16*i)));
return 0;
}