-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
47 lines (39 loc) · 961 Bytes
/
main.c
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
#include "twobit.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char ** argv) {
char * filename;
TwoBit * tb;
int start, end;
char * seq;
char * name;
if (argc != 5) {
printf("Usage: %s <2bit filename> <name> <start> <end>\n", argv[0]);
return EXIT_FAILURE;
}
filename = argv[1];
name = argv[2];
start = atoi(argv[3]);
end = atoi(argv[4]);
tb = twobit_open(filename);
if (tb == NULL) {
fprintf(stderr, "Failed to open: %s\n", filename);
return EXIT_FAILURE;
}
printf("%s: size = %d\n", name, twobit_sequence_size(tb, name));
seq = twobit_sequence(tb, name, start, end);
if (seq) {
int i;
printf(">%s:%d-%d\n", name, start, end + 1);
for (i = 0; i < end - start + 1; ++i) {
if (i != 0 && !(i % 50))
putc('\n', stdout);
putc(seq[i], stdout);
}
putc('\n', stdout);
}
/* free resources */
if (seq) free(seq);
twobit_close(tb);
return EXIT_SUCCESS;
}