X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bamtk.c;h=67dec9ed14f49ff614fd9fe654092a85cb370229;hb=646ba487102664734fb7d57778cb50cb050b2d8c;hp=aeb7d0a77ecca4a0faef75eff8c559f87ff06cb3;hpb=5af1150d241e56b349f7d61fd228c67b475b3c19;p=samtools.git diff --git a/bamtk.c b/bamtk.c index aeb7d0a..67dec9e 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.2-20" +#define PACKAGE_VERSION "0.1.3" #endif int bam_taf2baf(int argc, char *argv[]); @@ -51,6 +51,10 @@ int bam_view(int argc, char *argv[]) fp = strcmp(argv[optind], "-")? bam_open(argv[optind], "r") : bam_dopen(fileno(stdin), "r"); assert(fp); header = bam_header_read(fp); + if (header == 0) { + fprintf(stderr, "[bam_view] fail to read the BAM header. Abort!\n"); + return 1; + } if (is_bam) { assert(fpout = bam_dopen(fileno(stdout), "w")); bam_header_write(fpout, header); @@ -82,7 +86,10 @@ int bam_view(int argc, char *argv[]) for (i = optind + 1; i < argc; ++i) { int tid, beg, end; bam_parse_region(header, argv[i], &tid, &beg, &end); - if (tid < 0) return 0; + if (tid < 0) { + fprintf(stderr, "[bam_view] fail to get the reference name. Abort!\n"); + return 1; + } if (is_bam) bam_fetch(fp, idx, tid, beg, end, fpout, view_auxb); else bam_fetch(fp, idx, tid, beg, end, header, view_aux); }