From b30315f84a312370a69561dae09f89ce9bb3cd52 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 3 Feb 2015 16:28:56 +0100 Subject: [PATCH] final ass1 --- .../sws1-s4109503-s4202015/exercise1/commands | 2 +- .../sws1-s4109503-s4202015/exercise2/Makefile | 10 ++++- .../exercise2/parsegenome.c | 37 +++++++------------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ass1/mart/sws1-s4109503-s4202015/exercise1/commands b/ass1/mart/sws1-s4109503-s4202015/exercise1/commands index ef8e2bc..8748d46 100644 --- a/ass1/mart/sws1-s4109503-s4202015/exercise1/commands +++ b/ass1/mart/sws1-s4109503-s4202015/exercise1/commands @@ -1,4 +1,4 @@ mkdir -p sws1-s4109503-s4202015/exercise{1,2,3} cd sws1-s4109503-s4202015 echo -e "s4109503: Mart Lubbers\ns4202015: Chris Kamphuis" > names.txt -du -cb | tail -1 | cut -f 1 > exercise1/1b.txt +du -sb | cut -f 1 > exercise1/1b.txt diff --git a/ass1/mart/sws1-s4109503-s4202015/exercise2/Makefile b/ass1/mart/sws1-s4109503-s4202015/exercise2/Makefile index 95d7d4d..e7ef6d1 100644 --- a/ass1/mart/sws1-s4109503-s4202015/exercise2/Makefile +++ b/ass1/mart/sws1-s4109503-s4202015/exercise2/Makefile @@ -1,2 +1,8 @@ -all: - gcc -Wall parsegenome.c -o parsegenome +CC=gcc +CFLAGS=-Wall -Wextra + +all: parsegenome.c + $(CC) $(CFLAGS) parsegenome.c -o parsegenome + +clean: + rm -vf parsegenome diff --git a/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c b/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c index 3faf91c..d561d4f 100644 --- a/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c +++ b/ass1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c @@ -1,40 +1,29 @@ -#include -#include -#include - +#include /* - Basically we save the 4 frequencies in a 64bit int */ +#include /* - The polynome fits the following coordinates: */ +#include /* (65,0), (67, 16), (71, 32), (84, 48) */ +#include /* - Which is the mapping from ascii value and shiftwidth*/ + /* - When no input file is given assume stdin */ int main(int argc, char* argv[]) { char c; char charsperline = 0; short numlines = 0; - long long unsigned int occs = 0; - /* When the filepath is not given or "-" assume stdin */ + uint64_t occs = 0; FILE *f = (argc!=2 || strcmp(argv[1], "-")==0) ? stdin : fopen(argv[1], "r"); if(f == NULL) - { - printf("Unable to open file or stdin...\n"); return 2; - } - while((c = fgetc(f)) != EOF) - { - if(c == '\n' && charsperline == 100 && numlines <= 500) - { - numlines += 1; + 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) - { /*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 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 break; - } if(f != stdout) fclose(f); - if(numlines != 500) + if(numlines!=500) return -1; - printf("A: %llu\nC: %llu\nG: %llu\nT: %llu\n", occs & 0xFFFF, - (occs >> 16) & 0xFFFF, (occs >> 32) & 0xFFFF, (occs >> 48) & 0xFFFF); + 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)); return 0; } -- 2.20.1