X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bam_index.c;h=9610a2656031657b796abc68bf32c1b6f1564745;hb=cb5f44947629a68d16a48d32eef6e42a66e482fe;hp=9b71bdbac9167ec38719be411ee6d42a276c927f;hpb=4d48006473298b62ee54f13d706f9f2e512e02bd;p=samtools.git diff --git a/bam_index.c b/bam_index.c index 9b71bdb..9610a26 100644 --- a/bam_index.c +++ b/bam_index.c @@ -176,7 +176,7 @@ bam_index_t *bam_index_core(bamFile fp) off_beg = off_end = bam_tell(fp); while ((ret = bam_read1(fp, b)) >= 0) { if (c->tid < 0) ++n_no_coor; - if (last_tid < c->tid) { // change of chromosomes + if (last_tid < c->tid || (last_tid >= 0 && c->tid < 0)) { // change of chromosomes last_tid = c->tid; last_bin = 0xffffffffu; } else if ((uint32_t)last_tid > (uint32_t)c->tid) { @@ -188,7 +188,7 @@ bam_index_t *bam_index_core(bamFile fp) bam1_qname(b), last_coor, c->pos, c->tid+1); return NULL; } - if (c->tid >= 0) insert_offset2(&idx->index2[b->core.tid], b, last_off); + if (c->tid >= 0 && !(c->flag & BAM_FUNMAP)) insert_offset2(&idx->index2[b->core.tid], b, last_off); if (c->bin != last_bin) { // then possibly write the binning index if (save_bin != 0xffffffffu) // save_bin==0xffffffffu only happens to the first record insert_offset(idx->index[save_tid], save_bin, save_off, last_off);