aboutsummaryrefslogtreecommitdiff
path: root/sequence_end_points.c
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-03-21 14:23:12 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2014-03-21 14:23:12 -0400
commit872e0ad9563c6d53201eb337458d108dd57d9e94 (patch)
tree3950a68375364c8eeac059ee3005a70313ec763a /sequence_end_points.c
parent3cd522e991a71dde566023091f1cccc68beef038 (diff)
add more tools
Diffstat (limited to 'sequence_end_points.c')
-rw-r--r--sequence_end_points.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/sequence_end_points.c b/sequence_end_points.c
new file mode 100644
index 0000000..dc03dd9
--- /dev/null
+++ b/sequence_end_points.c
@@ -0,0 +1,54 @@
+// Copyright 2013 Calvin Morrison
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+int main() {
+
+ size_t len = 0;
+
+ char buffer[4096];
+ bool header = false;
+
+ len = fread(&buffer, 1, 1, stdin);
+
+ unsigned long long seq_length = 0;
+ if(!errno) {
+ if(buffer[0] == '>') {
+ header = true;
+
+ while((len = fread(&buffer, 1, 4096, stdin)) != 0) {
+ size_t i = 0;
+ for(i = 0; i < len; i++) {
+ if(buffer[i] == '>') {
+ printf("%llu\n", seq_length);
+ header = true;
+ continue;
+ }
+ else if(buffer[i] == '\n' && header == true) {
+ header = false;
+ continue;
+ }
+ if(header == false && buffer[i] != '\n') {
+ seq_length++;
+ }
+ }
+ }
+ }
+ else {
+ fprintf(stderr, "this does not look like a fasta file\n");
+ return EXIT_FAILURE;
+ }
+ }
+ else {
+ fprintf(stderr, "could not read file\n");
+ return EXIT_FAILURE;
+ }
+
+ printf("%llu\n", seq_length);
+
+ return EXIT_SUCCESS;
+}
+