From: Mart Lubbers Date: Sun, 1 Feb 2015 21:58:48 +0000 (+0100) Subject: mart: ex1 done X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=1a024facb6b6d8747ecfe48dc510b2b0335d9da7;p=sws1-1415.git mart: ex1 done --- diff --git a/ex1/mart/sws1-s4109503-s4202015.tar.gz b/ex1/mart/sws1-s4109503-s4202015.tar.gz new file mode 100644 index 0000000..02e5755 Binary files /dev/null and b/ex1/mart/sws1-s4109503-s4202015.tar.gz differ diff --git a/ex1/mart/sws1-s4109503-s4202015/exercise2/2a.txt b/ex1/mart/sws1-s4109503-s4202015/exercise2/2a.txt new file mode 100644 index 0000000..30eb450 --- /dev/null +++ b/ex1/mart/sws1-s4109503-s4202015/exercise2/2a.txt @@ -0,0 +1,2 @@ +# Answer: 5 +wget -qO- http://cryptojedi.org/peter/teaching/genome.txt | tr -d '\n' | grep -o "GATTACA" | wc -l diff --git a/ex1/mart/sws1-s4109503-s4202015/exercise2/Makefile b/ex1/mart/sws1-s4109503-s4202015/exercise2/Makefile new file mode 100644 index 0000000..95d7d4d --- /dev/null +++ b/ex1/mart/sws1-s4109503-s4202015/exercise2/Makefile @@ -0,0 +1,2 @@ +all: + gcc -Wall parsegenome.c -o parsegenome diff --git a/ex1/mart/sws1-s4109503-s4202015/exercise2/gengenome.sh b/ex1/mart/sws1-s4109503-s4202015/exercise2/gengenome.sh new file mode 100755 index 0000000..4fd66dc --- /dev/null +++ b/ex1/mart/sws1-s4109503-s4202015/exercise2/gengenome.sh @@ -0,0 +1 @@ +tr -cd 'ACGT' < /dev/urandom | fold -w 100 | head -500 diff --git a/ex1/mart/sws1-s4109503-s4202015/exercise2/genome.sh b/ex1/mart/sws1-s4109503-s4202015/exercise2/genome.sh new file mode 100755 index 0000000..5a771a5 --- /dev/null +++ b/ex1/mart/sws1-s4109503-s4202015/exercise2/genome.sh @@ -0,0 +1 @@ +[ "$#" -eq "2" ] && tr -d '\n' < "$1" | grep -o "$2" | wc -l diff --git a/ex1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c b/ex1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c new file mode 100644 index 0000000..2572cbe --- /dev/null +++ b/ex1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c @@ -0,0 +1,55 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + if(argc != 2) + { + printf("Usage: %s filepath\n", argv[0]); + return 2; + } + + FILE *f; + int c = 0; + int charsperline = 0; + int numlines = 0; + int occs[4] = {0, 0, 0, 0}; + + f = fopen(argv[1], "r"); + if(f == NULL) + { + printf("Unable to open file..."); + return 2; + } + + while((c = fgetc(f)) != EOF) + { + if(c == '\n') + { + if(charsperline != 100) + return -1; + numlines += 1; + charsperline = 0; + } + else + { + if(c == 'A') + occs[0] += 1; + else if(c == 'C') + occs[1] += 1; + else if(c == 'G') + occs[2] += 1; + else if(c == 'T') + occs[3] += 1; + else + return -1; + charsperline += 1; + } + } + 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]); + return 0; +}