mart: ex1 done
authorMart Lubbers <mart@martlubbers.net>
Sun, 1 Feb 2015 21:58:48 +0000 (22:58 +0100)
committerMart Lubbers <mart@martlubbers.net>
Sun, 1 Feb 2015 21:58:48 +0000 (22:58 +0100)
ex1/mart/sws1-s4109503-s4202015.tar.gz [new file with mode: 0644]
ex1/mart/sws1-s4109503-s4202015/exercise2/2a.txt [new file with mode: 0644]
ex1/mart/sws1-s4109503-s4202015/exercise2/Makefile [new file with mode: 0644]
ex1/mart/sws1-s4109503-s4202015/exercise2/gengenome.sh [new file with mode: 0755]
ex1/mart/sws1-s4109503-s4202015/exercise2/genome.sh [new file with mode: 0755]
ex1/mart/sws1-s4109503-s4202015/exercise2/parsegenome.c [new file with mode: 0644]

diff --git a/ex1/mart/sws1-s4109503-s4202015.tar.gz b/ex1/mart/sws1-s4109503-s4202015.tar.gz
new file mode 100644 (file)
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 (file)
index 0000000..30eb450
--- /dev/null
@@ -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 (file)
index 0000000..95d7d4d
--- /dev/null
@@ -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 (executable)
index 0000000..4fd66dc
--- /dev/null
@@ -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 (executable)
index 0000000..5a771a5
--- /dev/null
@@ -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 (file)
index 0000000..2572cbe
--- /dev/null
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+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;
+}