blob: dc03dd996542c5b0de8c0a1e2864d93c0351e5e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
|