From: Mart Lubbers Date: Mon, 2 Feb 2015 09:08:23 +0000 (+0100) Subject: ass1 done X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=7a406388fad470fb5fc443b546523a4d87d96439;p=sws1-1415.git ass1 done --- diff --git a/ass1/mart/s4109503-s4202015-sws1.tar.gz b/ass1/mart/s4109503-s4202015-sws1.tar.gz new file mode 100644 index 0000000..d3162b4 Binary files /dev/null and b/ass1/mart/s4109503-s4202015-sws1.tar.gz differ diff --git a/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c b/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c index eee156f..3faf91c 100644 --- a/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c +++ b/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c @@ -1,49 +1,40 @@ #include #include +#include int main(int argc, char* argv[]) { - if(argc != 2) - { - printf("Usage: %s filepath\n", argv[0]); - return 2; - } - char c; - int charsperline = 0; - int numlines = 0; - int occs[4] = {0, 0, 0, 0}; - - FILE *f = fopen(argv[1], "r"); + char charsperline = 0; + short numlines = 0; + long long unsigned int occs = 0; + /* When the filepath is not given or "-" assume stdin */ + FILE *f = (argc!=2 || strcmp(argv[1], "-")==0) ? stdin : fopen(argv[1], "r"); if(f == NULL) { - printf("Unable to open file..."); + printf("Unable to open file or stdin...\n"); return 2; } - while((c = fgetc(f)) != EOF) { - if(c == '\n') + if(c == '\n' && charsperline == 100 && numlines <= 500) { - if(charsperline != 100 || numlines > 500) - return -1; numlines += 1; charsperline = 0; } - else - { -/* Fancy polynome that translates A: 0, C: 1, G: 2, T: 3 */ - if(c == 'A' || c == 'C' || c == 'G' || c == 'T') - occs[(int)(.001657140781*c*c*c-0.3780662484*c*c+28.74757194*c-726.3545635)] += 1; - else - return -1; + else if((c == 'A' || c=='C' || c=='G' || c=='T') && charsperline < 100) + { /*Fancy polynomial that translates the ascii value to a bitshift*/ + occs += 1LL<<(int)(0.026514*c*c*c-6.049*c*c+459.96*c-11621.2); charsperline += 1; } + else + break; } - fclose(f); + if(f != stdout) + fclose(f); if(numlines != 500) return -1; - - printf("A: %d\nC: %d\nG: %d\nT: %d\n", occs[0], occs[1], occs[2], occs[3]); + printf("A: %llu\nC: %llu\nG: %llu\nT: %llu\n", occs & 0xFFFF, + (occs >> 16) & 0xFFFF, (occs >> 32) & 0xFFFF, (occs >> 48) & 0xFFFF); return 0; }