#include #define BAM_LITE #include "bam.h" // callback for bam_plbuf_init() static int pileup_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *pl, void *data) { bam_header_t *header = (bam_header_t*)data; printf("%s\t%d\t%d\n", header->target_name[tid], pos + 1, n); return 0; } int main(int argc, char *argv[]) { bamFile fp; bam_header_t *header; if (argc == 1) { fprintf(stderr, "Usage: calDepth \n"); return 1; } fp = bam_open(argv[1], "r"); if (fp == 0) { fprintf(stderr, "Fail to open BAM file %s\n", argv[1]); return 1; } header = bam_header_read(fp); bam_pileup_file(fp, 0, pileup_func, header); bam_header_destroy(header); bam_close(fp); return 0; }