Skip to content

Commit

Permalink
Truncated files can be indexed only with the -f option. Resolved #659
Browse files Browse the repository at this point in the history
  • Loading branch information
pd3 committed Sep 14, 2017
1 parent d0f5845 commit e3e265d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vcfindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DEALINGS IN THE SOFTWARE. */
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <htslib/kstring.h>
#include <htslib/bgzf.h>
#include "bcftools.h"

#define BCF_LIDX_SHIFT 14
Expand Down Expand Up @@ -208,6 +209,12 @@ int main_vcfindex(int argc, char *argv[])
return 1;
}
}

// check for truncated files, allow only with -f
BGZF *fp = bgzf_open(fname, "r");
if ( !fp ) error("index: failed to open %s\n", fname);
if ( bgzf_check_EOF(fp)!=1 ) error("index: the input is probably truncated, use -f to index anyway: %s\n", fname);
if ( bgzf_close(fp)!=0 ) error("index: close failed: %s\n", fname);
}

int ret = bcf_index_build3(fname, idx_fname.s, min_shift, n_threads);
Expand Down

0 comments on commit e3e265d

Please sign in to comment.