9 #define PACKAGE_VERSION "0.2.3 (r876)"
11 int main(int argc, char *argv[])
13 int c, skip = -1, meta = -1, list_chrms = 0, force = 0, print_header = 0;
14 ti_conf_t conf = ti_conf_gff;
15 while ((c = getopt(argc, argv, "p:s:b:e:0S:c:lhf")) >= 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 || strcmp(optarg, "vcf4") == 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 'h': print_header = 1; break;
36 case 'f': force = 1; break;
39 if (skip >= 0) conf.line_skip = skip;
40 if (meta >= 0) conf.meta_char = meta;
42 fprintf(stderr, "\n");
43 fprintf(stderr, "Program: tabix (TAB-delimited file InderXer)\n");
44 fprintf(stderr, "Version: %s\n\n", PACKAGE_VERSION);
45 fprintf(stderr, "Usage: tabix <in.tab.bgz> [region1 [region2 [...]]]\n\n");
46 fprintf(stderr, "Options: -p STR preset: gff, bed, sam, vcf, psltbl [gff]\n");
47 fprintf(stderr, " -s INT sequence name column [1]\n");
48 fprintf(stderr, " -b INT start column [4]\n");
49 fprintf(stderr, " -e INT end column [5]\n");
50 fprintf(stderr, " -S INT skip first INT lines [0]\n");
51 fprintf(stderr, " -c CHAR symbol for comment/meta lines [#]\n");
52 fprintf(stderr, " -0 zero-based coordinate\n");
53 fprintf(stderr, " -h print the VCF header\n");
54 fprintf(stderr, " -l list chromosome names\n");
55 fprintf(stderr, " -f force to overwrite the index\n");
56 fprintf(stderr, "\n");
63 idx = ti_index_load(argv[optind]);
65 fprintf(stderr, "[main] fail to load the index file.\n");
68 names = ti_seqname(idx, &n);
69 for (i = 0; i < n; ++i) printf("%s\n", names[i]);
71 ti_index_destroy(idx);
74 if (optind + 1 == argc) {
77 char *fnidx = calloc(strlen(argv[optind]) + 5, 1);
78 strcat(strcpy(fnidx, argv[optind]), ".tbi");
79 if (stat(fnidx, &buf) == 0) {
80 fprintf(stderr, "[tabix] the index file exists. Please use '-f' to overwrite.\n");
86 if ( is_bgzipped(argv[optind])!=1 )
88 fprintf(stderr,"[tabix] was bgzip used to compress this file? %s\n", argv[optind]);
91 return ti_index_build(argv[optind], &conf);
95 if ((t = ti_open(argv[optind], 0)) == 0) {
96 fprintf(stderr, "[main] fail to open the data file.\n");
99 if (strcmp(argv[optind+1], ".") == 0) { // retrieve all
103 iter = ti_query(t, 0, 0, 0);
104 while ((s = ti_read(t, iter, &len)) != 0) {
105 fputs(s, stdout); fputc('\n', stdout);
107 ti_iter_destroy(iter);
108 } else { // retrieve from specified regions
110 if ( ti_lazy_index_load(t) )
112 fprintf(stderr,"[tabix] failed to load the index file.\n");
121 // If requested, print the header lines here
122 iter = ti_query(t, 0, 0, 0);
123 while ((s = ti_read(t, iter, &len)) != 0) {
124 if ( *s != '#' ) break;
125 fputs(s, stdout); fputc('\n', stdout);
127 ti_iter_destroy(iter);
129 for (i = optind + 1; i < argc; ++i) {
131 if (ti_parse_region(t->idx, argv[i], &tid, &beg, &end) == 0) {
132 iter = ti_queryi(t, tid, beg, end);
133 while ((s = ti_read(t, iter, &len)) != 0) {
134 fputs(s, stdout); fputc('\n', stdout);
136 ti_iter_destroy(iter);
138 // else fprintf(stderr, "[main] invalid region: unknown target name or minus interval.\n");