- _seqQ[K] = max;
- }
- }
- }
- // compute the likelihood given each type of indel for each read
- ref2 = calloc(right - left + 2, 1);
- query = calloc(right - left + max_rd_len + 2, 1);
- score1 = calloc(N * n_types, sizeof(int));
- for (t = 0; t < n_types; ++t) {
- int l;
- kpa_par_t apf1 = { 1e-4, 1e-2, 10 };
- apf1.bw = abs(types[t]) + 3;
- // write ref2
- for (k = 0, j = left; j < pos; ++j)
- ref2[k++] = bam_nt16_nt4_table[bam_nt16_table[(int)ref[j]]];
- for (i = 0; i < bca->indelreg; ++i, ++j)
- ref2[k++] = types[t]>>2*i&3;
- for (; j < right && ref[j]; ++j)
- ref2[k++] = bam_nt16_nt4_table[bam_nt16_table[(int)ref[j]]];
- if (j < right) right = j;
- // align each read to ref2
- for (s = K = 0; s < n; ++s) {
- for (i = 0; i < n_plp[s]; ++i, ++K) {
- bam_pileup1_t *p = plp[s] + i;
- int qbeg, qend, tbeg, tend, sc;
- uint8_t *seq = bam1_seq(p->b);
- // determine the start and end of sequences for alignment
- qbeg = tpos2qpos(&p->b->core, bam1_cigar(p->b), left, 0, &tbeg);
- qend = tpos2qpos(&p->b->core, bam1_cigar(p->b), right, 1, &tend);
- // write the query sequence
- for (l = qbeg; l < qend; ++l)
- query[l - qbeg] = bam_nt16_nt4_table[bam1_seqi(seq, l)];
- { // do realignment; this is the bottleneck
- const uint8_t *qual = bam1_qual(p->b), *bq;
- uint8_t *qq;
- qq = calloc(qend - qbeg, 1);
- bq = (uint8_t*)bam_aux_get(p->b, "ZQ");
- if (bq) ++bq; // skip type
- for (l = qbeg; l < qend; ++l) {
- qq[l - qbeg] = bq? qual[l] + (bq[l] - 64) : qual[l];
- if (qq[l - qbeg] > 30) qq[l - qbeg] = 30;
- if (qq[l - qbeg] < 7) qq[l - qbeg] = 7;
+ for (t = 0; t < n_types; ++t)
+ if (types[t] == x) break;
+ if (t == n_types) skip = 1;
+ else { // reapply BAQ
+ for (k = y = 0; k < p->b->core.n_cigar; ++k) {
+ int op = cigar[k]&0xf;
+ int len = cigar[k]>>4;
+ if (op == BAM_CMATCH) {
+ if (p->qpos >= y && p->qpos + bca->indelreg <= y + len) {
+ int left, rght;
+ for (j = y, left = 0; j <= p->qpos; ++j)
+ left = left > qq[j]? left : qq[j];
+ for (j = p->qpos + bca->indelreg - 1, rght = 0; j < y + len; ++j)
+ rght = rght > qq[j]? rght : qq[j];
+ baq = left < rght? left : rght;
+ break;
+ }
+ y += len;
+ } else if (op == BAM_CSOFT_CLIP || op == BAM_CINS) y += len;