- if (conf->vcf) {
- double f0, f, pref = -1.0; // the reference allele frequency
- int j, _ref, _alt, _ref0, depth, rms_q, _ref0b, is_var = 0, qref = 0;
- uint64_t sqr_sum;
- _ref0 = _ref0b = (ref && pos < ref_len)? ref[pos] : 'N';
- _ref0 = bam_nt16_nt4_table[bam_nt16_table[_ref0]];
- f = f0 = mc_freq0(_ref0, n_plp, plp, ma, &_ref, &_alt);
- if (f >= 0.0) {
- double q, flast = f;
- for (j = 0; j < 10; ++j) {
- f = mc_freq_iter(flast, ma);
-// printf("%lg->%lg\n", flast, f);
- if (fabs(f - flast) < 1e-3) break;
- flast = f;
- }
- if (1. - f < 1e-4) f = 1.;
- pref = mc_ref_prob(ma);
- is_var = (pref < .5);
- q = is_var? pref : 1. - pref;
- if (q < 1e-308) q = 1e-308;
- qref = (int)(-3.434 * log(q) + .499);
- if (qref > 99) qref = 99;
- }
- if (conf->var_only && !is_var) continue;
- printf("%s\t%d\t.\t%c\t", h->target_name[tid], pos + 1, _ref0b);
- if (is_var) {
- if (_ref0 == _ref) putchar("ACGTN"[_alt]);
- else printf("%c,%c", "ACGTN"[_ref], "ACGTN"[_alt]);
- } else putchar('.');
- printf("\t%d\t", qref);
- if (f0 < 0.) printf("Q13\t");
- else printf(".\t");
- for (i = depth = 0, sqr_sum = 0; i < n; ++i) {
- depth += n_plp[i];
- for (j = 0; j < n_plp[i]; ++j) {
- int q = plp[i][j].b->core.qual;
- if (q > conf->max_mq) q = conf->max_mq;
- sqr_sum += q * q;
- }
- }
- rms_q = (int)(sqrt((double)sqr_sum / depth) + .499);
- printf("DP=%d;MQ=%d;AF=%.3lg", depth, rms_q, f0<0.?0.:1.-f);
- printf("\tGT:GQ:DP");
- // output genotype information; FIXME: to be implmented...
- for (i = 0; i < n; ++i) {
- int x = mc_call_gt(ma, f, i);
- printf("\t%c/%c:%d:%d", "10"[((x&3)==2)], "10"[((x&3)>0)], x>>2, n_plp[i]);
- }
- putchar('\n');
+ if (conf->flag & MPLP_GLF) {
+ int _ref0, ref16;
+ bcf1_t *b = calloc(1, sizeof(bcf1_t));
+ group_smpl(&gplp, sm, &buf, n, fn, n_plp, plp);
+ _ref0 = (ref && pos < ref_len)? ref[pos] : 'N';
+ ref16 = bam_nt16_table[_ref0];
+ for (i = 0; i < gplp.n; ++i)
+ bcf_call_glfgen(gplp.n_plp[i], gplp.plp[i], ref16, bca, bcr + i);
+ bcf_call_combine(gplp.n, bcr, ref16, &bc);
+ bcf_call2bcf(tid, pos, &bc, b);
+ bcf_write(bp, bh, b);
+ bcf_destroy(b);