X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=blobdiff_plain;f=bam_lpileup.c;h=d4dd63b99b85dd4c5811758153a56757c908a52c;hp=368028766842db8b9b71c82c4fc85a2eb3a87092;hb=307c147168f7154e3755712797078c513e0b242a;hpb=635998cfe030da5f3dbec42a6daa3ca82fa5c871 diff --git a/bam_lpileup.c b/bam_lpileup.c index 3680287..d4dd63b 100644 --- a/bam_lpileup.c +++ b/bam_lpileup.c @@ -1,5 +1,6 @@ #include #include +#include #include "bam.h" #include "ksort.h" @@ -102,7 +103,7 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl } else tv->cur_level[i] = ++tv->max_level; } else { tv->cur_level[i] = tv->pre_level[l++]; - if (p->qpos == p->b->core.l_qseq - 1) { // then return a free slot + if (p->is_tail) { // then return a free slot tv->tail->level = tv->cur_level[i]; tv->tail->next = mp_alloc(tv->mp); tv->tail = tv->tail->next; @@ -150,6 +151,16 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl tv->pre_level[l++] = tv->pre_level[i]; } tv->n_pre = l; +/* + fprintf(stderr, "%d\t", pos+1); + for (i = 0; i < n; ++i) { + const bam_pileup1_t *p = pl + i; + if (p->is_head) fprintf(stderr, "^"); + if (p->is_tail) fprintf(stderr, "$"); + fprintf(stderr, "%d,", p->level); + } + fprintf(stderr, "\n"); +*/ return 0; } @@ -167,11 +178,17 @@ bam_lplbuf_t *bam_lplbuf_init(bam_pileup_f func, void *data) void bam_lplbuf_destroy(bam_lplbuf_t *tv) { - mp_free(tv->mp, tv->head); - mp_destroy(tv->mp); + freenode_t *p, *q; free(tv->cur_level); free(tv->pre_level); bam_plbuf_destroy(tv->plbuf); free(tv->aux); + for (p = tv->head; p->next;) { + q = p->next; + mp_free(tv->mp, p); p = q; + } + mp_free(tv->mp, p); + assert(tv->mp->cnt == 0); + mp_destroy(tv->mp); free(tv); } @@ -179,19 +196,3 @@ int bam_lplbuf_push(const bam1_t *b, bam_lplbuf_t *tv) { return bam_plbuf_push(b, tv->plbuf); } - -int bam_lpileup_file(bamFile fp, int mask, bam_pileup_f func, void *func_data) -{ - bam_lplbuf_t *buf; - int ret; - bam1_t *b; - b = (bam1_t*)calloc(1, sizeof(bam1_t)); - buf = bam_lplbuf_init(func, func_data); - bam_plbuf_set_mask(buf->plbuf, mask); - while ((ret = bam_read1(fp, b)) >= 0) - bam_lplbuf_push(b, buf); - bam_lplbuf_push(0, buf); - bam_lplbuf_destroy(buf); - free(b->data); free(b); - return 0; -}