X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bam_md.c;h=9abff46290f183fa4e6f8fdd3323b7345513a3a8;hb=b0ed19dc2d8fb84998d41d6c3588611185707137;hp=a7d2ab42f525a5a690aa89bab4f0ea56bb610b85;hpb=6762f5307ddcbc61cb6752db2371f8112f31a988;p=samtools.git diff --git a/bam_md.c b/bam_md.c index a7d2ab4..9abff46 100644 --- a/bam_md.c +++ b/bam_md.c @@ -70,7 +70,7 @@ void bam_fillmd1(bam1_t *b, char *ref, int is_equal) int bam_fillmd(int argc, char *argv[]) { - int c, is_equal = 0, tid = -1, ret, len; + int c, is_equal = 0, tid = -2, ret, len; bamFile fp, fpout = 0; bam_header_t *header; faidx_t *fai; @@ -96,12 +96,14 @@ int bam_fillmd(int argc, char *argv[]) b = bam_init1(); while ((ret = bam_read1(fp, b)) >= 0) { - if (tid != b->core.tid) { - free(ref); - ref = fai_fetch(fai, header->target_name[b->core.tid], &len); - tid = b->core.tid; + if (b->core.tid >= 0) { + if (tid != b->core.tid) { + free(ref); + ref = fai_fetch(fai, header->target_name[b->core.tid], &len); + tid = b->core.tid; + } + bam_fillmd1(b, ref, is_equal); } - bam_fillmd1(b, ref, is_equal); bam_write1(fpout, b); } bam_destroy1(b);