struct __mc_aux_t {
int n, M;
- int ref, alt;
+ int ref, alt, alt2;
double *q2p, *pdg; // pdg -> P(D|g)
double *alpha, *beta;
double *z, *zswap; // aux for afs
if (type == MC_PTYPE_COND2) {
for (i = 0; i <= 2 * ma->n; ++i)
ma->alpha[i] = 2. * (i + 1) / (2 * ma->n + 1) / (2 * ma->n + 2);
+ } else if (type == MC_PTYPE_FLAT) {
+ for (i = 0; i <= ma->M; ++i)
+ ma->alpha[i] = 1. / (ma->M + 1);
} else {
double sum;
for (i = 0, sum = 0.; i < 2 * ma->n; ++i)
for (i = 1; i < 4; ++i) // insertion sort
for (j = i; j > 0 && sum[j] < sum[j-1]; --j)
tmp = sum[j], sum[j] = sum[j-1], sum[j-1] = tmp;
- ma->ref = sum[3]&3; ma->alt = sum[2]&3;
- if (ref == ma->alt) tmp = ma->ref, ma->ref = ma->alt, ma->alt = tmp;
- // note that ma->ref might not be ref in case of triallele
+ ma->ref = sum[3]&3; ma->alt = sum[2]&3; ma->alt2 = -1;
+ if (ma->ref != ref) {
+ if (ma->alt == ref) tmp = ma->ref, ma->ref = ma->alt, ma->alt = tmp;
+ else ma->alt2 = ma->alt, ma->alt = ma->ref, ma->ref = ref;
+ }
}
static void cal_pdg(mc_aux_t *ma)
int k, l;
double sum = 0.;
memset(ma->afs1, 0, sizeof(double) * (2 * ma->n + 1));
+ *f_map = *p_map = -1.;
for (k = 0; k <= 2 * ma->n; ++k) {
mc_cal_z(ma, k);
for (l = 0; l <= 2 * ma->n; ++l)
ma->afs1[l] += ma->alpha[k] * ma->z[l] / PD;
}
+ for (k = 0; k <= ma->M; ++k)
+ if (isnan(ma->afs1[k]) || isinf(ma->afs1[k])) return;
for (k = 0; k <= 2 * ma->n; ++k) {
ma->afs[k] += ma->afs1[k];
sum += ma->afs1[k];
set_allele(ref, ma);
cal_pdg(ma);
// set ref/major allele
- rst->ref = ma->ref; rst->alt = ma->alt;
+ rst->ref = ma->ref; rst->alt = ma->alt; rst->alt2 = ma->alt2;
// calculate naive and Nielsen's freq
rst->f_naive = mc_freq0(ma, &rst->f_nielsen);
{ // calculate f_em
++N; // number of processed lines
printf("%s\t%d\t.\t%c\t", h->target_name[tid], pos + 1, _ref0b);
if (is_var) {
- if (_ref0 == r.ref) putchar("ACGTN"[r.alt]);
- else printf("%c,%c", "ACGTN"[r.ref], "ACGTN"[r.alt]);
+ putchar("ACGTN"[r.alt]);
+ if (r.alt2 >= 0 && r.alt2 < 4) printf(",%c", "ACGT"[r.alt2]);
} else putchar('.');
printf("\t%d\t", qref);
if (!tot) printf("Q13\t");
mplp.max_mq = 60;
mplp.prior_type = MC_PTYPE_FULL;
mplp.theta = 1e-3;
- while ((c = getopt(argc, argv, "vVcF2Sf:r:l:VM:q:t:")) >= 0) {
+ while ((c = getopt(argc, argv, "vVcFSP:f:r:l:VM:q:t:")) >= 0) {
switch (c) {
case 't': mplp.theta = atof(optarg); break;
- case '2': mplp.prior_type = MC_PTYPE_COND2; break;
+ case 'P':
+ if (strcmp(optarg, "full") == 0) mplp.prior_type = MC_PTYPE_FULL;
+ else if (strcmp(optarg, "cond2") == 0) mplp.prior_type = MC_PTYPE_COND2;
+ else if (strcmp(optarg, "flat") == 0) mplp.prior_type = MC_PTYPE_FLAT;
+ else {
+ fprintf(stderr, "[%s] unrecognized prior type.\n", __func__);
+ return 1;
+ }
+ break;
case 'f':
mplp.fai = fai_load(optarg);
if (mplp.fai == 0) return 1;
fprintf(stderr, " -M INT cap mapping quality at INT [%d]\n", mplp.max_mq);
fprintf(stderr, " -q INT filter out alignment with MQ smaller than INT [%d]\n", mplp.min_mq);
fprintf(stderr, " -t FLOAT scaled mutation rate [%lg]\n", mplp.theta);
+ fprintf(stderr, " -P STR prior: full, flat, cond2 [full]");
fprintf(stderr, " -c generate VCF output (consensus calling)\n");
fprintf(stderr, " -v show variant sites only\n");
fprintf(stderr, " -S calculate AFS (slow, to stderr)\n");
- fprintf(stderr, " -2 conditional prior\n");
fprintf(stderr, "\n");
fprintf(stderr, "Notes: Assuming error independency and diploid individuals.\n\n");
return 1;