From: Heng Li Date: Wed, 15 Apr 2009 13:31:32 +0000 (+0000) Subject: * samtools-0.1.2-28 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5fa181a401f891a049e3c43d03917e9452d1d739;p=samtools.git * samtools-0.1.2-28 * make samtools more robust to weird input such as empty file --- diff --git a/bam_plcmd.c b/bam_plcmd.c index 5f20c1e..38680df 100644 --- a/bam_plcmd.c +++ b/bam_plcmd.c @@ -280,7 +280,7 @@ int bam_pileup(int argc, char *argv[]) fprintf(stderr, " -l FILE list of sites at which pileup is output\n"); fprintf(stderr, " -f FILE reference sequence in the FASTA format\n\n"); fprintf(stderr, " -c output the maq consensus sequence\n"); - fprintf(stderr, " -g output in the extended GLT format (suppressing -c/-i/-s)\n"); + fprintf(stderr, " -g output in the GLFv3 format (suppressing -c/-i/-s)\n"); fprintf(stderr, " -T FLOAT theta in maq consensus calling model (for -c/-g) [%f]\n", d->c->theta); fprintf(stderr, " -N INT number of haplotypes in the sample (for -c/-g) [%d]\n", d->c->n_hap); fprintf(stderr, " -r FLOAT prior of a difference between two haplotypes (for -c/-g) [%f]\n", d->c->het_rate); @@ -292,7 +292,7 @@ int bam_pileup(int argc, char *argv[]) } if (fn_fa) d->fai = fai_load(fn_fa); free(fn_fa); - bam_maqcns_prepare(d->c); + if (d->format & (BAM_PLF_CNS|BAM_PLF_GLF)) bam_maqcns_prepare(d->c); if (d->format & BAM_PLF_GLF) { glf3_header_t *h; h = glf3_header_init(); @@ -300,7 +300,7 @@ int bam_pileup(int argc, char *argv[]) glf3_header_write(d->fp, h); glf3_header_destroy(h); } - if (d->fai == 0) + if (d->fai == 0 && (d->format & (BAM_PLF_CNS|BAM_PLF_INDEL_ONLY))) fprintf(stderr, "[bam_pileup] indels will not be called when -f is absent.\n"); if (fn_list) { // the input is SAM tamFile fp; @@ -322,6 +322,10 @@ int bam_pileup(int argc, char *argv[]) bamFile fp; fp = (strcmp(argv[optind], "-") == 0)? bam_dopen(fileno(stdin), "r") : bam_open(argv[optind], "r"); d->h = bam_header_read(fp); + if (d->h == 0) { + fprintf(stderr, "[bam_pileup] fail to read the BAM header. Abort!\n"); + return 1; + } if (fn_pos) d->hash = load_pos(fn_pos, d->h); bam_pileup_file(fp, d->mask, pileup_func, d); bam_close(fp); diff --git a/bamtk.c b/bamtk.c index 1c8c7b1..2bdc00a 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.2-27" +#define PACKAGE_VERSION "0.1.2-28" #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); }