]> git.donarmstrong.com Git - samtools.git/blobdiff - bam_index.c
allow to set seed in view-subsampling
[samtools.git] / bam_index.c
index c65d512320289a98c8bd6c75ecbe0ddebded2bc1..66d8eb8a896ab5a0a4decf612e65eac158e92cbf 100644 (file)
@@ -176,14 +176,14 @@ 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 (last_tid > c->tid) {
+               } else if ((uint32_t)last_tid > (uint32_t)c->tid) {
                        fprintf(stderr, "[bam_index_core] the alignment is not sorted (%s): %d-th chr > %d-th chr\n",
                                        bam1_qname(b), last_tid+1, c->tid+1);
                        return NULL;
-               } else if (last_coor > c->pos) {
+               } else if ((int32_t)c->tid >= 0 && last_coor > c->pos) {
                        fprintf(stderr, "[bam_index_core] the alignment is not sorted (%s): %u > %u in %d-th chr\n",
                                        bam1_qname(b), last_coor, c->pos, c->tid+1);
                        return NULL;