+ if (c->tid >= 0) {
+ if (c->n_cigar) {
+ recalculated_bin = bam_reg2bin(c->pos, bam_calend(c, bam1_cigar(b)));
+ } else {
+ recalculated_bin = bam_reg2bin(c->pos, c->pos + 1);
+ }
+ if (c->bin != recalculated_bin) {
+ fprintf(stderr, "[bam_index_core] read '%s' mapped to '%s' at POS %d to %d has BIN %d but should be %d\n",
+ bam1_qname(b), h->target_name[c->tid], c->pos + 1, bam_calend(c, bam1_cigar(b)), c->bin, recalculated_bin);
+ fprintf(stderr, "[bam_index_core] Fix it by using BAM->SAM->BAM to force a recalculation of the BIN field\n");
+ return NULL;
+ }
+ }
+ if (c->tid >= 0 && !(c->flag & BAM_FUNMAP)) insert_offset2(&idx->index2[b->core.tid], b, last_off);