x = call->n_alleles * (call->n_alleles + 1) / 2;
// get the possible genotypes
for (i = z = 0; i < call->n_alleles; ++i)
- for (j = i; j < call->n_alleles; ++j)
- g[z++] = call->a[i] * 5 + call->a[j];
+ for (j = 0; j <= i; ++j)
+ g[z++] = call->a[j] * 5 + call->a[i];
for (i = 0; i < n; ++i) {
uint8_t *PL = call->PL + x * i;
const bcf_callret1_t *r = calls + i;
#endif
#ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.12-11 (r896:110)"
+#define PACKAGE_VERSION "0.1.12-11 (r921:118)"
#endif
int bam_taf2baf(int argc, char *argv[]);
b->gi[i].len = b->n_alleles * (b->n_alleles + 1) / 2;
} else if (b->gi[i].fmt == bcf_str2int("DP", 2) || b->gi[i].fmt == bcf_str2int("HQ", 2)) {
b->gi[i].len = 2;
- } else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("GT", 2)
- || b->gi[i].fmt == bcf_str2int("SP", 2))
- {
+ } else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("GT", 2)) {
b->gi[i].len = 1;
+ } else if (b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ b->gi[i].len = 4;
} else if (b->gi[i].fmt == bcf_str2int("GL", 2)) {
b->gi[i].len = b->n_alleles * (b->n_alleles + 1) / 2 * 4;
}
}
} else if (b->gi[i].fmt == bcf_str2int("DP", 2)) {
kputw(((uint16_t*)b->gi[i].data)[j], s);
- } else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ } else if (b->gi[i].fmt == bcf_str2int("GQ", 2)) {
kputw(((uint8_t*)b->gi[i].data)[j], s);
+ } else if (b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ kputw(((int32_t*)b->gi[i].data)[j], s);
} else if (b->gi[i].fmt == bcf_str2int("GT", 2)) {
int y = ((uint8_t*)b->gi[i].data)[j];
if (y>>7&1) {
{\tt PL} & {\tt uint8\_t[n*G]} & {Phred-scaled likelihood of data}\\
{\tt PS} & {\tt uint32\_t[n]} & {Phase set}\\
%{\tt SP} & {\tt uint8\_t[n]} & {Strand bias P-value (bcftools only)}\\
-\emph{Integer} & {\tt int32\_t[n*X]} & {Fix-sized custom Integer; $X$ can be $1$, $A$ or $G$.}\\
-\emph{Numeric} & {\tt double[n*X]} & {Fix-sized custom Numeric; $X$ can be $1$, $A$ or $G$.}\\
+\emph{Integer} & {\tt int32\_t[n*X]} & {Fix-sized custom Integer; $X$ defined in the header}\\
+\emph{Numeric} & {\tt double[n*X]} & {Fix-sized custom Numeric}\\
\emph{String} & {\tt uint32\_t+char*} & {\tt NULL} padded concat. strings (int equals to the length) \\
\hline
\end{tabular}
for (k = j = 0; k < 4; ++k) {
for (l = k; l < 4; ++l) {
int t, x = map[k], y = map[l];
- if (x > y) t = x, x = y, y = t;
- g[j++] = p[x * b->n_alleles - x * (x-1) / 2 + (y - x)];
+ if (x > y) t = x, x = y, y = t; // swap
+ g[j++] = p[y * (y+1) / 2 + x];
}
}
printf("%s\t%d\t%c", h->ns[b->tid], b->pos+1, *b->ref);
int bcf_shrink_alt(bcf1_t *b, int n)
{
char *p;
- int i, j, k, *z, n_smpl = b->n_smpl;
+ int i, j, k, n_smpl = b->n_smpl;
if (b->n_alleles <= n) return -1;
+ // update ALT
if (n > 1) {
for (p = b->alt, k = 1; *p; ++p)
if (*p == ',' && ++k == n) break;
++p;
memmove(p, b->flt, b->str + b->l_str - b->flt);
b->l_str -= b->flt - p;
- z = alloca(sizeof(int) / 2 * n * (n+1));
- for (i = k = 0; i < n; ++i)
- for (j = 0; j < n - i; ++j)
- z[k++] = i * b->n_alleles + j;
+ // update PL
for (i = 0; i < b->n_gi; ++i) {
bcf_ginfo_t *g = b->gi + i;
if (g->fmt == bcf_str2int("PL", 2)) {
g->len = n * (n + 1) / 2;
for (l = k = 0; l < n_smpl; ++l) {
uint8_t *dl = d + l * x;
- for (j = 0; j < g->len; ++j) d[k++] = dl[z[j]];
+ for (j = 0; j < g->len; ++j) d[k++] = dl[j];
}
} // FIXME: to add GL
}
{
int k, max_gq, max_sp, n_het;
kstring_t str;
- uint8_t *gt, *gq, *sp;
+ uint8_t *gt, *gq;
+ int32_t *sp;
max_gq = max_sp = n_het = 0;
gt = locate_field(b, "GT", 2);
if (gt == 0) return -1;
for (i = 0; i < n_smpl; ++i) {
const uint8_t *pi = PL[j] + i * PL_len[j];
double *p = pdg[j] + i * 3;
- p[0] = g_q2p[pi[b[j]->n_alleles]]; p[1] = g_q2p[pi[1]]; p[2] = g_q2p[pi[0]];
+ p[0] = g_q2p[pi[2]]; p[1] = g_q2p[pi[1]]; p[2] = g_q2p[pi[0]];
}
}
// iteration
static int cal_pdg(const bcf1_t *b, bcf_p1aux_t *ma)
{
- int i, j, k;
+ int i, j;
long *p, tmp;
p = alloca(b->n_alleles * sizeof(long));
memset(p, 0, sizeof(long) * b->n_alleles);
for (j = 0; j < ma->n; ++j) {
const uint8_t *pi = ma->PL + j * ma->PL_len;
double *pdg = ma->pdg + j * 3;
- pdg[0] = ma->q2p[pi[b->n_alleles]]; pdg[1] = ma->q2p[pi[1]]; pdg[2] = ma->q2p[pi[0]];
- for (i = k = 0; i < b->n_alleles; ++i) {
- p[i] += (int)pi[k];
- k += b->n_alleles - i;
- }
+ pdg[0] = ma->q2p[pi[2]]; pdg[1] = ma->q2p[pi[1]]; pdg[2] = ma->q2p[pi[0]];
+ for (i = 0; i < b->n_alleles; ++i)
+ p[i] += (int)pi[(i+1)*(i+2)/2-1];
}
for (i = 0; i < b->n_alleles; ++i) p[i] = p[i]<<4 | i;
for (i = 1; i < b->n_alleles; ++i) // insertion sort
for (i = 0; i < b->n_gi; ++i) {
if (b->gi[i].fmt == bcf_str2int("GT", 2)) {
((uint8_t*)b->gi[i].data)[k-9] = 1<<7;
- } else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ } else if (b->gi[i].fmt == bcf_str2int("GQ", 2)) {
((uint8_t*)b->gi[i].data)[k-9] = 0;
+ } else if (b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ ((int32_t*)b->gi[i].data)[k-9] = 0;
} else if (b->gi[i].fmt == bcf_str2int("DP", 2)) {
((uint16_t*)b->gi[i].data)[k-9] = 0;
} else if (b->gi[i].fmt == bcf_str2int("PL", 2)) {
for (q = kstrtok(p, ":", &a2), i = 0; q && i < b->n_gi; q = kstrtok(0, 0, &a2), ++i) {
if (b->gi[i].fmt == bcf_str2int("GT", 2)) {
((uint8_t*)b->gi[i].data)[k-9] = (q[0] - '0')<<3 | (q[2] - '0') | (q[1] == '/'? 0 : 1) << 6;
- } else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ } else if (b->gi[i].fmt == bcf_str2int("GQ", 2)) {
double _x = strtod(q, &q);
int x = (int)(_x + .499);
if (x > 255) x = 255;
((uint8_t*)b->gi[i].data)[k-9] = x;
+ } else if (b->gi[i].fmt == bcf_str2int("SP", 2)) {
+ int x = strtol(q, &q, 10);
+ if (x > 0xffff) x = 0xffff;
+ ((uint32_t*)b->gi[i].data)[k-9] = x;
} else if (b->gi[i].fmt == bcf_str2int("DP", 2)) {
int x = strtol(q, &q, 10);
if (x > 0xffff) x = 0xffff;
b = bam_nt16_nt4_table[bam1_seqi(seq, p->qpos)];
if (b > 3) continue;
q = baseQ < p->b->core.qual? baseQ : p->b->core.qual;
+ if (q < 4) q = 4;
+ if (q > 63) q = 63;
g->bases[k++] = q<<5 | bam1_strand(p->b)<<4 | b;
}
if (k == 0) return 0;