-int bam_pileup(int argc, char *argv[])
-{
- int c, is_SAM = 0;
- char *fn_list = 0, *fn_fa = 0, *fn_pos = 0;
- pu_data_t *d = (pu_data_t*)calloc(1, sizeof(pu_data_t));
- d->max_depth = 0;
- d->tid = -1; d->mask = BAM_DEF_MASK;
- d->c = bam_maqcns_init();
- d->c->is_soap = 1; // change the default model
- d->ido = bam_maqindel_opt_init();
- while ((c = getopt(argc, argv, "st:f:cT:N:r:l:d:im:gI:G:vM:S2aR:P")) >= 0) {
- switch (c) {
- case 'a': d->c->is_soap = 0; break;
- case 's': d->format |= BAM_PLF_SIMPLE; break;
- case 't': fn_list = strdup(optarg); break;
- case 'l': fn_pos = strdup(optarg); break;
- case 'f': fn_fa = strdup(optarg); break;
- case 'T': d->c->theta = atof(optarg); break;
- case 'N': d->c->n_hap = atoi(optarg); break;
- case 'r': d->c->het_rate = atof(optarg); break;
- case 'M': d->c->cap_mapQ = atoi(optarg); break;
- case 'd': d->max_depth = atoi(optarg); break;
- case 'c': d->format |= BAM_PLF_CNS; break;
- case 'i': d->format |= BAM_PLF_INDEL_ONLY; break;
- case 'v': d->format |= BAM_PLF_VAR_ONLY; break;
- case 'm': d->mask = strtol(optarg, 0, 0); break;
- case 'g': d->format |= BAM_PLF_GLF; break;
- case '2': d->format |= BAM_PLF_2ND; break;
- case 'P': d->format |= BAM_PLF_READPOS; break;
- case 'I': d->ido->q_indel = atoi(optarg); break;
- case 'G': d->ido->r_indel = atof(optarg); break;
- case 'S': is_SAM = 1; break;
- case 'R':
- if (strcmp(optarg, "random") == 0) d->format |= BAM_PLF_RANBASE;
- else if (strcmp(optarg, "first") == 0) d->format |= BAM_PLF_1STBASE;
- else if (strcmp(optarg, "all") == 0) d->format |= BAM_PLF_ALLBASE;
- else fprintf(stderr, "[bam_pileup] unrecognized -R\n");
- break;
- default: fprintf(stderr, "Unrecognizd option '-%c'.\n", c); return 1;
- }
- }
- if (fn_list) is_SAM = 1;
- if (optind == argc) {
- fprintf(stderr, "\n");
- fprintf(stderr, "Usage: samtools pileup [options] <in.bam>|<in.sam>\n\n");
- fprintf(stderr, "Option: -s simple (yet incomplete) pileup format\n");
- fprintf(stderr, " -S the input is in SAM\n");
- fprintf(stderr, " -a use the MAQ model for SNP calling\n");
- fprintf(stderr, " -2 output the 2nd best call and quality\n");
- fprintf(stderr, " -i only show lines/consensus with indels\n");
- fprintf(stderr, " -m INT filtering reads with bits in INT [%d]\n", d->mask);
- fprintf(stderr, " -M INT cap mapping quality at INT [%d]\n", d->c->cap_mapQ);
- fprintf(stderr, " -d INT limit maximum depth for indels [unlimited]\n");
- fprintf(stderr, " -t FILE list of reference sequences (force -S)\n");
- fprintf(stderr, " -l FILE list of sites at which pileup is output\n");
- fprintf(stderr, " -f FILE reference sequence in the FASTA format\n\n");
- fprintf(stderr, " -c output the maq consensus sequence\n");
- fprintf(stderr, " -v print variants only (for -c)\n");
- fprintf(stderr, " -g output in the GLFv3 format (suppressing -c/-i/-s)\n");
- fprintf(stderr, " -T FLOAT theta in maq consensus calling model (for -c/-g) [%f]\n", d->c->theta);
- fprintf(stderr, " -N INT number of haplotypes in the sample (for -c/-g) [%d]\n", d->c->n_hap);
- fprintf(stderr, " -r FLOAT prior of a difference between two haplotypes (for -c/-g) [%f]\n", d->c->het_rate);
- fprintf(stderr, " -G FLOAT prior of an indel between two haplotypes (for -c/-g) [%f]\n", d->ido->r_indel);
- fprintf(stderr, " -I INT phred prob. of an indel in sequencing/prep. (for -c/-g) [%d]\n", d->ido->q_indel);
- fprintf(stderr, "\n");
- free(fn_list); free(fn_fa); free(d);
- return 1;
- }
- if (d->format & (BAM_PLF_RANBASE|BAM_PLF_1STBASE|BAM_PLF_ALLBASE)) d->format |= BAM_PLF_CNS;
- if (fn_fa) d->fai = fai_load(fn_fa);
- if (d->format & (BAM_PLF_CNS|BAM_PLF_GLF)) bam_maqcns_prepare(d->c); // consensus calling
- if (d->format & BAM_PLF_GLF) { // for glf output
- glf3_header_t *h;
- h = glf3_header_init();
- d->fp_glf = bgzf_fdopen(fileno(stdout), "w");
- glf3_header_write(d->fp_glf, h);
- glf3_header_destroy(h);
- }
- if (d->fai == 0 && (d->format & (BAM_PLF_CNS|BAM_PLF_INDEL_ONLY)))
- fprintf(stderr, "[bam_pileup] indels will not be called when -f is absent.\n");
- if (fn_fa && is_SAM && fn_list == 0) fn_list = samfaipath(fn_fa);