+ if ( !conf_ptr )
+ {
+ int l = strlen(argv[optind]);
+ int strcasecmp(const char *s1, const char *s2);
+ if (l>=7 && strcasecmp(argv[optind]+l-7, ".gff.gz") == 0) conf_ptr = &ti_conf_gff;
+ else if (l>=7 && strcasecmp(argv[optind]+l-7, ".bed.gz") == 0) conf_ptr = &ti_conf_bed;
+ else if (l>=7 && strcasecmp(argv[optind]+l-7, ".sam.gz") == 0) conf_ptr = &ti_conf_sam;
+ else if (l>=7 && strcasecmp(argv[optind]+l-7, ".vcf.gz") == 0) conf_ptr = &ti_conf_vcf;
+ else if (l>=10 && strcasecmp(argv[optind]+l-10, ".psltbl.gz") == 0) conf_ptr = &ti_conf_psltbl;
+ }
+ if ( conf_ptr )
+ conf = *conf_ptr;
+
+ if (skip >= 0) conf.line_skip = skip;
+ if (meta >= 0) conf.meta_char = meta;
+ if (list_chrms) {
+ ti_index_t *idx;
+ int i, n;
+ const char **names;
+ idx = ti_index_load(argv[optind]);
+ if (idx == 0) {
+ fprintf(stderr, "[main] fail to load the index file.\n");
+ return 1;
+ }
+ names = ti_seqname(idx, &n);
+ for (i = 0; i < n; ++i) printf("%s\n", names[i]);
+ free(names);
+ ti_index_destroy(idx);
+ return 0;
+ }
+ if (reheader)
+ return reheader_file(reheader,argv[optind],conf.meta_char);
+
+ struct stat stat_tbi,stat_vcf;
+ char *fnidx = calloc(strlen(argv[optind]) + 5, 1);
+ strcat(strcpy(fnidx, argv[optind]), ".tbi");
+
+ if (optind + 1 == argc && !print_only_header) {
+ if (force == 0) {
+ if (stat(fnidx, &stat_tbi) == 0)
+ {
+ // Before complaining, check if the VCF file isn't newer. This is a common source of errors,
+ // people tend not to notice that tabix failed
+ stat(argv[optind], &stat_vcf);
+ if ( stat_vcf.st_mtime <= stat_tbi.st_mtime )
+ {
+ fprintf(stderr, "[tabix] the index file exists. Please use '-f' to overwrite.\n");
+ free(fnidx);
+ return 1;
+ }
+ }
+ }
+ if ( bgzf_is_bgzf(argv[optind])!=1 )
+ {
+ fprintf(stderr,"[tabix] was bgzip used to compress this file? %s\n", argv[optind]);
+ free(fnidx);
+ return 1;
+ }
+ if ( !conf_ptr )
+ {
+ // Building the index but the file type was neither recognised nor given. If no custom change
+ // has been made, warn the user that GFF is used
+ if ( conf.preset==ti_conf_gff.preset
+ && conf.sc==ti_conf_gff.sc
+ && conf.bc==ti_conf_gff.bc
+ && conf.ec==ti_conf_gff.ec
+ && conf.meta_char==ti_conf_gff.meta_char
+ && conf.line_skip==ti_conf_gff.line_skip )
+ fprintf(stderr,"[tabix] The file type not recognised and -p not given, using the preset [gff].\n");
+ }