]> git.donarmstrong.com Git - samtools.git/blobdiff - bam_index.c
* samtools-0.1.2-22
[samtools.git] / bam_index.c
index 8c2555232772ee6571f0da19593c5b2764b04898..7670c2f3f1058af65086cd40f62f3acbd288025d 100644 (file)
@@ -374,7 +374,7 @@ static inline int reg2bins(uint32_t beg, uint32_t end, uint16_t list[MAX_BIN])
 static inline int is_overlap(uint32_t beg, uint32_t end, const bam1_t *b)
 {
        uint32_t rbeg = b->core.pos;
-       uint32_t rend = bam_calend(&b->core, bam1_cigar(b));
+       uint32_t rend = b->core.n_cigar? bam_calend(&b->core, bam1_cigar(b)) : b->core.pos + 1;
        return (rend > beg && rbeg < end);
 }
 
@@ -410,16 +410,20 @@ int bam_fetch(bamFile fp, const bam_index_t *idx, int tid, int beg, int end, voi
        free(bins);
        {
                bam1_t *b;
-               int ret, n_seeks;
+               int l, ret, n_seeks;
                uint64_t curr_off;
                b = (bam1_t*)calloc(1, sizeof(bam1_t));
                ks_introsort(off, n_off, off);
-               // resolve overlaps between adjecent blocks; this may happen due to the merge in indexing
+               // resolve completely contained adjacent blocks
+               for (i = 1, l = 0; i < n_off; ++i)
+                       if (off[l].v < off[i].v)
+                               off[++l] = off[i];
+               n_off = l + 1;
+               // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing
                for (i = 1; i < n_off; ++i)
                        if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u;
                { // merge adjacent blocks
 #if defined(BAM_TRUE_OFFSET) || defined(BAM_VIRTUAL_OFFSET16)
-                       int l;
                        for (i = 1, l = 0; i < n_off; ++i) {
 #ifdef BAM_TRUE_OFFSET
                                if (off[l].v + BAM_MIN_CHUNK_GAP > off[i].u) off[l].v = off[i].v;