9 #define PACKAGE_VERSION "0.1.6 (r565)"
11 int main(int argc, char *argv[])
13 int c, skip = -1, meta = -1, list_chrms = 0, force = 0;
14 ti_conf_t conf = ti_conf_gff;
15 while ((c = getopt(argc, argv, "p:s:b:e:0S:c:lf")) >= 0) {
17 case '0': conf.preset |= TI_FLAG_UCSC; break;
18 case 'S': skip = atoi(optarg); break;
19 case 'c': meta = optarg[0]; break;
21 if (strcmp(optarg, "gff") == 0) conf = ti_conf_gff;
22 else if (strcmp(optarg, "bed") == 0) conf = ti_conf_bed;
23 else if (strcmp(optarg, "sam") == 0) conf = ti_conf_sam;
24 else if (strcmp(optarg, "vcf") == 0) conf = ti_conf_vcf;
25 else if (strcmp(optarg, "psltbl") == 0) conf = ti_conf_psltbl;
27 fprintf(stderr, "[main] unrecognized preset '%s'\n", optarg);
31 case 's': conf.sc = atoi(optarg); break;
32 case 'b': conf.bc = atoi(optarg); break;
33 case 'e': conf.ec = atoi(optarg); break;
34 case 'l': list_chrms = 1; break;
35 case 'f': force = 1; break;
38 if (skip >= 0) conf.line_skip = skip;
39 if (meta >= 0) conf.meta_char = meta;
41 fprintf(stderr, "\n");
42 fprintf(stderr, "Program: tabix (TAB-delimited file InderXer)\n");
43 fprintf(stderr, "Version: %s\n\n", PACKAGE_VERSION);
44 fprintf(stderr, "Usage: tabix <in.tab.bgz> [region1 [region2 [...]]]\n\n");
45 fprintf(stderr, "Options: -p STR preset: gff, bed, sam, vcf, psltbl [gff]\n");
46 fprintf(stderr, " -s INT sequence name column [1]\n");
47 fprintf(stderr, " -b INT start column [4]\n");
48 fprintf(stderr, " -e INT end column [5]\n");
49 fprintf(stderr, " -S INT skip first INT lines [0]\n");
50 fprintf(stderr, " -c CHAR symbol for comment/meta lines [#]\n");
51 fprintf(stderr, " -0 zero-based coordinate\n");
52 fprintf(stderr, " -l list chromosome names\n");
53 fprintf(stderr, " -f force to overwrite the index\n");
54 fprintf(stderr, "\n");
61 idx = ti_index_load(argv[optind]);
63 fprintf(stderr, "[main] fail to load the index file.\n");
66 names = ti_seqname(idx, &n);
67 for (i = 0; i < n; ++i) printf("%s\n", names[i]);
69 ti_index_destroy(idx);
72 if (optind + 1 == argc) {
75 char *fnidx = calloc(strlen(argv[optind]) + 5, 1);
76 strcat(strcpy(fnidx, argv[optind]), ".tbi");
77 if (stat(fnidx, &buf) == 0) {
78 fprintf(stderr, "[tabix] the index file exists. Please use '-f' to overwrite.\n");
84 return ti_index_build(argv[optind], &conf);
88 fp = bgzf_open(argv[optind], "r");
90 fprintf(stderr, "[main] fail to open the data file.\n");
93 if (strcmp(argv[optind+1], ".") == 0) { // retrieve all
98 while ((s = ti_iter_read(iter, &len)) != 0) {
99 fputs(s, stdout); fputc('\n', stdout);
101 ti_iter_destroy(iter);
102 } else { // retrieve from specified regions
105 idx = ti_index_load(argv[optind]);
108 fprintf(stderr, "[main] fail to load the index.\n");
111 for (i = optind + 1; i < argc; ++i) {
113 if (ti_parse_region(idx, argv[i], &tid, &beg, &end) == 0) {
117 iter = ti_query(fp, idx, tid, beg, end);
118 while ((s = ti_iter_read(iter, &len)) != 0) {
119 fputs(s, stdout); fputc('\n', stdout);
121 ti_iter_destroy(iter);
122 } else fprintf(stderr, "[main] invalid region: unknown target name or minus interval.\n");
124 ti_index_destroy(idx);