aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-07-23 16:37:19 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-07-23 16:37:19 -0400
commit5d4fabb8f2a31ad87fccfb0b8ee426b464867f54 (patch)
tree490eddf35611e5328941efbae4b5c831f6234c01
added a nucleobase counter
-rwxr-xr-xcount_nucleobases.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/count_nucleobases.c b/count_nucleobases.c
new file mode 100755
index 0000000..6edf5e8
--- /dev/null
+++ b/count_nucleobases.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+main() {
+
+long unsigned long a = 0;
+long unsigned long c = 0;
+long unsigned long g = 0;
+long unsigned long t = 0;
+
+FILE *fh = fopen("dna.txt", "r" );
+ if(fh == NULL) {
+ fprintf(stderr, "could not open dna.txt\n");
+ exit(EXIT_FAILURE);
+ }
+
+ unsigned int ch = 0;
+ while ((ch = getc(fh)) != EOF) {
+ switch(ch) {
+ case 'A':
+ case 'a':
+ a++;
+ break;
+ case 'C':
+ case 'c':
+ c++;
+ break;
+ case 'G':
+ case 'g':
+ g++;
+ break;
+ case 'T':
+ case 't':
+ t++;
+ break;
+ }
+ }
+
+ printf("A:%lu\nC:%lu\nG:%lu\nT:%lu\n", a, c, g, t);
+}