9 #define PACKAGE_VERSION "0.1.5 (r560)"
11 static int fetch_func(int l, const char *s, void *data)
17 int main(int argc, char *argv[])
19 int c, skip = -1, meta = -1, list_chrms = 0, force = 0;
20 ti_conf_t conf = ti_conf_gff;
21 while ((c = getopt(argc, argv, "p:s:b:e:0S:c:lf")) >= 0) {
23 case '0': conf.preset |= TI_FLAG_UCSC; break;
24 case 'S': skip = atoi(optarg); break;
25 case 'c': meta = optarg[0]; break;
27 if (strcmp(optarg, "gff") == 0) conf = ti_conf_gff;
28 else if (strcmp(optarg, "bed") == 0) conf = ti_conf_bed;
29 else if (strcmp(optarg, "sam") == 0) conf = ti_conf_sam;
30 else if (strcmp(optarg, "vcf") == 0) conf = ti_conf_vcf;
31 else if (strcmp(optarg, "psltbl") == 0) conf = ti_conf_psltbl;
33 fprintf(stderr, "[main] unrecognized preset '%s'\n", optarg);
37 case 's': conf.sc = atoi(optarg); break;
38 case 'b': conf.bc = atoi(optarg); break;
39 case 'e': conf.ec = atoi(optarg); break;
40 case 'l': list_chrms = 1; break;
41 case 'f': force = 1; break;
44 if (skip >= 0) conf.line_skip = skip;
45 if (meta >= 0) conf.meta_char = meta;
47 fprintf(stderr, "\n");
48 fprintf(stderr, "Program: tabix (TAB-delimited file InderXer)\n");
49 fprintf(stderr, "Version: %s\n\n", PACKAGE_VERSION);
50 fprintf(stderr, "Usage: tabix <in.tab.bgz> [region1 [region2 [...]]]\n\n");
51 fprintf(stderr, "Options: -p STR preset: gff, bed, sam, vcf, psltbl [gff]\n");
52 fprintf(stderr, " -s INT sequence name column [1]\n");
53 fprintf(stderr, " -b INT start column [4]\n");
54 fprintf(stderr, " -e INT end column [5]\n");
55 fprintf(stderr, " -S INT skip first INT lines [0]\n");
56 fprintf(stderr, " -c CHAR symbol for comment/meta lines [#]\n");
57 fprintf(stderr, " -0 zero-based coordinate\n");
58 fprintf(stderr, " -l list chromosome names\n");
59 fprintf(stderr, " -f force to overwrite the index\n");
60 fprintf(stderr, "\n");
64 return ti_list_chromosomes(argv[optind]);
65 if (optind + 1 == argc) {
68 char *fnidx = calloc(strlen(argv[optind]) + 5, 1);
69 strcat(strcpy(fnidx, argv[optind]), ".tbi");
70 if (stat(fnidx, &buf) == 0) {
71 fprintf(stderr, "[tabix] the index file exists. Please use '-f' to overwrite.\n");
77 return ti_index_build(argv[optind], &conf);
81 fp = bgzf_open(argv[optind], "r");
83 fprintf(stderr, "[main] fail to open the data file.\n");
86 if (strcmp(argv[optind+1], ".") == 0) { // retrieve all
87 kstring_t *str = calloc(1, sizeof(kstring_t));
88 while (ti_readline(fp, str) >= 0) { // FIXME: check return code for error
89 fputs(str->s, stdout); fputc('\n', stdout);
91 free(str->s); free(str);
92 } else { // retrieve from specified regions
95 idx = ti_index_load(argv[optind]);
98 fprintf(stderr, "[main] fail to load the index.\n");
101 for (i = optind + 1; i < argc; ++i) {
103 if (ti_parse_region(idx, argv[i], &tid, &beg, &end) == 0) {
104 ti_fetch(fp, idx, tid, beg, end, 0, fetch_func);
105 } else fprintf(stderr, "[main] invalid region: unknown target name or minus interval.\n");
107 ti_index_destroy(idx);