]> git.donarmstrong.com Git - samtools.git/commitdiff
* fixed a bug in capQ
authorHeng Li <lh3@live.co.uk>
Thu, 16 Sep 2010 20:54:48 +0000 (20:54 +0000)
committerHeng Li <lh3@live.co.uk>
Thu, 16 Sep 2010 20:54:48 +0000 (20:54 +0000)
 * valgrind identifies a use of uninitialised value, but I have not fixed it.

bam.c
bam_md.c
bam_pileup.c

diff --git a/bam.c b/bam.c
index 94b0aa8bb85bef4ae4a787af3337f1765ed8899e..41850bab46e190f33c0b279ec20e4bec663bb86f 100644 (file)
--- a/bam.c
+++ b/bam.c
@@ -245,7 +245,11 @@ char *bam_format1_core(const bam_header_t *header, const bam1_t *b, int of)
                kputc('\t', &str);
        }
        if (c->tid < 0) kputsn("*\t", 2, &str);
-       else { kputs(header->target_name[c->tid], &str); kputc('\t', &str); }
+       else {
+               if (header) kputs(header->target_name[c->tid] , &str);
+               else kputw(c->tid, &str);
+               kputc('\t', &str);
+       }
        kputw(c->pos + 1, &str); kputc('\t', &str); kputw(c->qual, &str); kputc('\t', &str);
        if (c->n_cigar == 0) kputc('*', &str);
        else {
@@ -257,7 +261,11 @@ char *bam_format1_core(const bam_header_t *header, const bam1_t *b, int of)
        kputc('\t', &str);
        if (c->mtid < 0) kputsn("*\t", 2, &str);
        else if (c->mtid == c->tid) kputsn("=\t", 2, &str);
-       else { kputs(header->target_name[c->mtid], &str); kputc('\t', &str); }
+       else {
+               if (header) kputs(header->target_name[c->mtid], &str);
+               else kputw(c->mtid, &str);
+               kputc('\t', &str);
+       }
        kputw(c->mpos + 1, &str); kputc('\t', &str); kputw(c->isize, &str); kputc('\t', &str);
        if (c->l_qseq) {
                for (i = 0; i < c->l_qseq; ++i) kputc(bam_nt16_rev_table[bam1_seqi(s, i)], &str);
index d2c84dcccd084c3399bf94ac6085af8902eb8532..f3f7e228a62c18e5d1beba2686cb2095da385002 100644 (file)
--- a/bam_md.c
+++ b/bam_md.c
@@ -200,7 +200,7 @@ int bam_realn(bam1_t *b, const char *ref)
                } else if (op == BAM_CSOFT_CLIP) y += ol;
                else if (op == BAM_CREF_SKIP) x += ol;
        }
-       if (score < 0) return -1; // no high scoring segments
+       if (q[1] < 0) return -1; // no high scoring segments
        endx = x - 1;
        // find the left boundary
        for (k = c->n_cigar - 1, score = max = 0, x = x-1, y = y-1; k >= 0; --k) {
@@ -229,7 +229,7 @@ int bam_realn(bam1_t *b, const char *ref)
                } else if (op == BAM_CSOFT_CLIP) y -= ol;
                else if (op == BAM_CREF_SKIP) x -= ol;
        }
-       if (q[1] - q[0] < 15) return -1; // the high-scoring segment is too short
+       if (q[0] < 0 || q[1] - q[0] < 15) return -1; // the high-scoring segment is too short
        // modify CIGAR
        n_cigar = 0;
        cigar = calloc(c->n_cigar + 4, 4);
index db170e8f15114e21c63cd11849b2d78a05996ea6..266b96673713e3800001624bbf0f0a3baed78637 100644 (file)
@@ -391,7 +391,7 @@ int bam_mplp_auto(bam_mplp_t iter, int *_tid, int *_pos, int *n_plp, const bam_p
        if (new_min == (uint64_t)-1) return 0;
        *_tid = new_min>>32; *_pos = (uint32_t)new_min;
        for (i = 0; i < iter->n; ++i) {
-               if (iter->pos[i] == iter->min) {
+               if (iter->pos[i] == iter->min) { // FIXME: valgrind reports "uninitialised value(s) at this line"
                        n_plp[i] = iter->n_plp[i], plp[i] = iter->plp[i];
                        ++ret;
                } else n_plp[i] = 0, plp[i] = 0;