]> git.donarmstrong.com Git - samtools.git/commitdiff
* fixed an out-of-boundary bug
authorHeng Li <lh3@live.co.uk>
Wed, 2 Feb 2011 16:28:24 +0000 (16:28 +0000)
committerHeng Li <lh3@live.co.uk>
Wed, 2 Feb 2011 16:28:24 +0000 (16:28 +0000)
 * improved sorting order checking in index

bam2bcf.c
bam_index.c

index 46f534ee7553182f790384921c8c667417838b75..98acb5dd2ff051eacb86f8efd72c00c370798617 100644 (file)
--- a/bam2bcf.c
+++ b/bam2bcf.c
@@ -79,7 +79,7 @@ int bcf_call_glfgen(int _n, const bam_pileup1_t *pl, int ref_base, bcf_callaux_t
                }
                bca->bases[n++] = q<<5 | (int)bam1_strand(p->b)<<4 | b;
                // collect annotations
-               r->qsum[b] += q;
+               if (b < 4) r->qsum[b] += q;
                ++r->anno[0<<2|is_diff<<1|bam1_strand(p->b)];
                min_dist = p->b->core.l_qseq - 1 - p->qpos;
                if (min_dist > p->qpos) min_dist = p->qpos;
index 328f011c16ccf4a9a558702317ecdecfbcc5212a..51c27014da0f9f010b563db92112f71d7ad6bdd6 100644 (file)
@@ -217,8 +217,15 @@ bam_index_t *bam_index_core(bamFile fp)
        }
        merge_chunks(idx);
        fill_missing(idx);
-       if (ret >= 0)
-               while ((ret = bam_read1(fp, b)) >= 0) ++n_no_coor;
+       if (ret >= 0) {
+               while ((ret = bam_read1(fp, b)) >= 0) {
+                       ++n_no_coor;
+                       if (c->tid >= 0 && n_no_coor) {
+                               fprintf(stderr, "[bam_index_core] the alignment is not sorted: reads without coordinates prior to reads with coordinates.\n");
+                               exit(1);
+                       }
+               }
+       }
        if (ret < -1) fprintf(stderr, "[bam_index_core] truncated file? Continue anyway. (%d)\n", ret);
        free(b->data); free(b);
        idx->n_no_coor = n_no_coor;