#include <stdlib.h>
#include <stdio.h>
+#include <assert.h>
#include "bam.h"
#include "ksort.h"
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;
} 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;
// 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;
}
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);
}
return bam_plbuf_push(b, tv->plbuf);
}
-int bam_lpileup_file(bamFile fp, bam_pileup_f func, void *func_data)
+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);