Skip to content

Commit

Permalink
Merge pull request #850 from valeriuo/tabix-gz-841
Browse files Browse the repository at this point in the history
Display an error message about the compression mismatch
  • Loading branch information
valeriuo authored and daviesrob committed Apr 10, 2019
1 parent 089eb16 commit 75be032
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions htslib/tbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 22 additions & 4 deletions tabix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion tbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 75be032

Please sign in to comment.