#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-#include "bam.h"
+#include "sam.h"
typedef struct __linkbuf_t {
bam1_t b;
int bam_plbuf_push(const bam1_t *b, bam_plbuf_t *buf)
{
if (b) { // fill buffer
+ if (b->core.tid < 0) return 0;
if (b->core.flag & buf->flag_mask) return 0;
bam_copy1(&buf->tail->b, b);
buf->tail->beg = b->core.pos; buf->tail->end = bam_calend(&b->core, bam1_cigar(b));
abort();
}
buf->max_tid = b->core.tid; buf->max_pos = buf->tail->beg;
- if (buf->tail->end > buf->pos) {
+ if (buf->tail->end > buf->pos || buf->tail->b.core.tid > buf->tid) {
buf->tail->next = mp_alloc(buf->mp);
buf->tail = buf->tail->next;
}
}
return 0;
}
-
-int bam_pileup_file(bamFile fp, int mask, bam_pileup_f func, void *func_data)
-{
- bam_plbuf_t *buf;
- int ret;
- bam1_t *b;
- b = (bam1_t*)calloc(1, sizeof(bam1_t));
- buf = bam_plbuf_init(func, func_data);
- bam_plbuf_set_mask(buf, mask);
- while ((ret = bam_read1(fp, b)) >= 0)
- bam_plbuf_push(b, buf);
- bam_plbuf_push(0, buf);
- bam_plbuf_destroy(buf);
- free(b->data); free(b);
- return 0;
-}