diff --git a/htslib/tbx.h b/htslib/tbx.h index 0a1953891..c8d184e7d 100644 --- a/htslib/tbx.h +++ b/htslib/tbx.h @@ -67,6 +67,9 @@ extern const tbx_conf_t tbx_conf_gff, tbx_conf_bed, tbx_conf_psltbl, tbx_conf_sa int tbx_readrec(BGZF *fp, void *tbxv, void *sv, int *tid, int *beg, int *end); tbx_t *tbx_index(BGZF *fp, int min_shift, const tbx_conf_t *conf); +/* + * All tbx_index_build* methods return: 0 (success), -1 (general failure) or -2 (compression not BGZF) + */ int tbx_index_build(const char *fn, int min_shift, const tbx_conf_t *conf); int tbx_index_build2(const char *fn, const char *fnidx, int min_shift, const tbx_conf_t *conf); int tbx_index_build3(const char *fn, const char *fnidx, int min_shift, int n_threads, const tbx_conf_t *conf); diff --git a/tabix.c b/tabix.c index 4ce167005..ee68ada93 100644 --- a/tabix.c +++ b/tabix.c @@ -529,6 +529,7 @@ int main(int argc, char *argv[]) } free(idx_fname); + int ret; if ( ftype==IS_CRAM ) { if ( bam_index_build(fname, min_shift)!=0 ) error("bam_index_build failed: %s\n", fname); @@ -546,12 +547,29 @@ int main(int argc, char *argv[]) if ( bam_index_build(fname, min_shift)!=0 ) error("bam_index_build failed: %s\n", fname); return 0; } - if ( tbx_index_build(fname, min_shift, &conf)!=0 ) error("tbx_index_build failed: %s\n", fname); - return 0; + + switch (ret = tbx_index_build(fname, min_shift, &conf)) + { + case 0: + return 0; + case -2: + error("[tabix] the compression of '%s' is not BGZF\n", fname); + default: + error("tbx_index_build failed: %s\n", fname); + } } else // TBI index { - if ( tbx_index_build(fname, min_shift, &conf) ) error("tbx_index_build failed: %s\n", fname); - return 0; + switch (ret = tbx_index_build(fname, min_shift, &conf)) + { + case 0: + return 0; + case -2: + error("[tabix] the compression of '%s' is not BGZF\n", fname); + default: + error("tbx_index_build failed: %s\n", fname); + } } + + return 0; } diff --git a/tbx.c b/tbx.c index ccd4cc695..36124e0ce 100644 --- a/tbx.c +++ b/tbx.c @@ -277,7 +277,7 @@ int tbx_index_build3(const char *fn, const char *fnidx, int min_shift, int n_thr int ret; if ((fp = bgzf_open(fn, "r")) == 0) return -1; if ( n_threads ) bgzf_mt(fp, n_threads, 256); - if ( bgzf_compression(fp) != bgzf ) { bgzf_close(fp); return -1; } + if ( bgzf_compression(fp) != bgzf ) { bgzf_close(fp); return -2; } tbx = tbx_index(fp, min_shift, conf); bgzf_close(fp); if ( !tbx ) return -1;