X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=blobdiff_plain;f=bam_lpileup.c;h=d4dd63b99b85dd4c5811758153a56757c908a52c;hp=83f91c2d3edb39ffce3212ee1751e0fcec36d43f;hb=307c147168f7154e3755712797078c513e0b242a;hpb=f93dae0d03856955f9424e8b2aaf261304ca647e diff --git a/bam_lpileup.c b/bam_lpileup.c index 83f91c2..d4dd63b 100644 --- a/bam_lpileup.c +++ b/bam_lpileup.c @@ -1,5 +1,6 @@ #include #include +#include #include "bam.h" #include "ksort.h" @@ -92,7 +93,7 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl max_level = 0; for (i = l = 0; i < n; ++i) { const bam_pileup1_t *p = pl + i; - if (p->qpos == 0) { + if (p->is_head) { if (tv->head->next && tv->head->cnt == 0) { // then take a free slot freenode_t *p = tv->head->next; tv->cur_level[i] = tv->head->level; @@ -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; @@ -146,10 +147,20 @@ static int tview_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl // squeeze out terminated levels for (i = l = 0; i < n; ++i) { const bam_pileup1_t *p = pl + i; - if (p->qpos != p->b->core.l_qseq - 1) + if (!p->is_tail) 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,18 +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, 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); - 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; -}