diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-08-30 14:33:50 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-08-30 14:33:50 -0400 |
commit | 0a9476fe2aa09610a23b2a54974bbb733b478a92 (patch) | |
tree | 9a210ed654715f980ba19f6fc3478591434a2164 | |
parent | 613bbe2d3e0717c0e2d89fb2a67395205a88b6e1 (diff) |
check for fasta headers
-rwxr-xr-x | count_nucleobases | bin | 0 -> 5496 bytes | |||
-rwxr-xr-x | count_nucleobases.c | 19 |
2 files changed, 13 insertions, 6 deletions
diff --git a/count_nucleobases b/count_nucleobases Binary files differnew file mode 100755 index 0000000..8c1b122 --- /dev/null +++ b/count_nucleobases diff --git a/count_nucleobases.c b/count_nucleobases.c index d1a4f1c..c2aafe5 100755 --- a/count_nucleobases.c +++ b/count_nucleobases.c @@ -5,27 +5,34 @@ #include <stdint.h> int main(int argc, char **argv) { + char *line = NULL; + size_t len = 0; + ssize_t read; if(argc != 2) { printf("Please supply a filename, and only a filename\n"); exit(EXIT_FAILURE); } + FILE *fh = fopen(argv[1], "r" ); if(fh == NULL) { fprintf(stderr, "Couldn't open: %s\n", argv[1]); exit(EXIT_FAILURE); } - char line[8192]; - long unsigned long counts[256]; - while (fgets(line, 8192, fh) != NULL) { + unsigned long long counts[256] = {0}; - unsigned int i = 0; - for(i = 0; i < strlen(line); i++) { - counts[line[i]]++; + while ((read = getline(&line, &len, fh)) != -1) { + if(line[0] != '>') { + unsigned int i = 0; + for(i = 0; i < strlen(line); i++) { + counts[line[i]]++; + } } } + free(line); + printf("A:%llu\nC:%llu\nG:%llu\nT:%llu\n", counts['a'] + counts['A'], counts['c'] + counts['C'], |