Debian Codegraph @

hmmer/src/impl_neon/optacc.c

raw symbols SCIP
1 /* Optimal accuracy alignment; NEON version.
2 *
3 * Contents:
4 * 1. Optimal accuracy alignment, DP fill
5 * 2. OA traceback
6 * 3. Benchmark driver
7 * 4. Unit tests
8 * 5. Test driver
9 * 6. Example
10 *
11 * SRE, Mon Aug 18 20:01:01 2008 [Casa de Gatos]
12 */
13 #include <p7_config.h>
14
15 #include <float.h>
16
17 #include <arm_neon.h>
18
19 #include "easel.h"
20 #include "esl_neon.h"
21 #include "esl_vectorops.h"
22
23 #include "hmmer.h"
24
25
26 /*****************************************************************
27 * 1. Optimal accuracy alignment, DP fill
28 *****************************************************************/
29
30 /* Function: p7_OptimalAccuracy()
31 * Synopsis: DP fill of an optimal accuracy alignment calculation.
32 * Incept: SRE, Mon Aug 18 11:04:48 2008 [Janelia]
33 *
34 * Purpose: Calculates the fill step of the optimal accuracy decoding
35 * algorithm \citep{Kall05}.
36 *
37 * Caller provides the posterior decoding matrix <pp>,
38 * which was calculated by Forward/Backward on a target sequence
39 * of length <pp->L> using the query model <om>.
40 *
41 * Caller also provides a DP matrix <ox>, allocated for a full
42 * <om->M> by <L> comparison. The routine fills this in
43 * with OA scores.
44 *
45 * Args: gm - query profile
46 * pp - posterior decoding matrix created by <p7_GPosteriorDecoding()>
47 * gx - RESULT: caller provided DP matrix for <gm->M> by <L>
48 * ret_e - RETURN: expected number of correctly decoded positions
49 *
50 * Returns: <eslOK> on success, and <*ret_e> contains the final OA
51 * score, which is the expected number of correctly decoded
52 * positions in the target sequence (up to <L>).
53 *
54 * Throws: (no abnormal error conditions)
55 */
56 int
57 p7_OptimalAccuracy(const P7_OPROFILE *om, const P7_OMX *pp, P7_OMX *ox, float *ret_e)
58 {
59 register float32x4_t mpv, dpv, ipv; /* previous row values */
60 register float32x4_t sv; /* temp storage of 1 curr row value in progress */
61 register float32x4_t xEv; /* E state: keeps max for Mk->E as we go */
62 register float32x4_t xBv; /* B state: splatted vector of B[i-1] for B->Mk calculations */
63 register float32x4_t dcv;
64 float *xmx = ox->xmx;
65 float32x4_t *dpc = ox->dpf[0]; /* current row, for use in {MDI}MO(dpp,q) access macro */
66 float32x4_t *dpp; /* previous row, for use in {MDI}MO(dpp,q) access macro */
67 float32x4_t *ppp; /* quads in the <pp> posterior probability matrix */
68 float32x4_t *tp; /* quads in the <om->tfv> transition scores */
69 float32x4_t zerov = vmovq_n_f32(0.0);
70 float32x4_t infv = vmovq_n_f32(-eslINFINITY);
71 int M = om->M;
72 int Q = p7O_NQF(M);
73 int q;
74 int j;
75 int i;
76 float t1, t2;
77
78 ox->M = om->M;
79 ox->L = pp->L;
80 for (q = 0; q < Q; q++) MMO(dpc, q) = IMO(dpc,q) = DMO(dpc,q) = infv;
81 XMXo(0, p7X_E) = -eslINFINITY;
82 XMXo(0, p7X_N) = 0.;
83 XMXo(0, p7X_J) = -eslINFINITY;
84 XMXo(0, p7X_B) = 0.;
85 XMXo(0, p7X_C) = -eslINFINITY;
86
87 for (i = 1; i <= pp->L; i++)
88 {
89 dpp = dpc; /* previous DP row in OA matrix */
90 dpc = ox->dpf[i]; /* current DP row in OA matrix */
91 ppp = pp->dpf[i]; /* current row in the posterior probabilities per position */
92 tp = om->tfv; /* transition probabilities */
93 dcv = infv;
94 xEv = infv;
95 xBv = vmovq_n_f32(XMXo(i-1, p7X_B));
96
97 mpv = esl_neon_rightshift_float((esl_neon_128f_t) MMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4; /* Right shifts by 4 bytes. 4,8,12,x becomes x,4,8,12. */
98 dpv = esl_neon_rightshift_float((esl_neon_128f_t) DMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4;
99 ipv = esl_neon_rightshift_float((esl_neon_128f_t) IMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4;
100 for (q = 0; q < Q; q++)
101 {
102 sv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(xBv))); tp++;
103 sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(mpv)))); tp++;
104 sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(ipv)))); tp++;
105 sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(dpv)))); tp++;
106 sv = vaddq_f32(sv, *ppp); ppp += 2;
107 xEv = vmaxq_f32(xEv, sv);
108
109 mpv = MMO(dpp,q);
110 dpv = DMO(dpp,q);
111 ipv = IMO(dpp,q);
112
113 MMO(dpc,q) = sv;
114 DMO(dpc,q) = dcv;
115
116 dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(sv))); tp++;
117
118 sv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(mpv))); tp++;
119 sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(ipv)))); tp++;
120 IMO(dpc,q) = vaddq_f32(sv, *ppp); ppp++;
121 }
122
123 /* dcv has carried through from end of q loop above; store it
124 * in first pass, we add M->D and D->D path into DMX
125 */
126 dcv = esl_neon_rightshift_float((esl_neon_128f_t) dcv, (esl_neon_128f_t) infv).f32x4;
127 tp = om->tfv + 7*Q; /* set tp to start of the DD's */
128 for (q = 0; q < Q; q++)
129 {
130 DMO(dpc, q) = vmaxq_f32(dcv, DMO(dpc, q));
131 dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(DMO(dpc,q)))); tp++;
132 }
133
134 /* fully serialized D->D; can optimize later */
135 for (j = 1; j < 4; j++)
136 {
137 dcv = esl_neon_rightshift_float((esl_neon_128f_t) dcv, (esl_neon_128f_t) infv).f32x4;
138 tp = om->tfv + 7*Q;
139 for (q = 0; q < Q; q++)
140 {
141 DMO(dpc, q) = vmaxq_f32(dcv, DMO(dpc, q));
142 dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(dcv))); tp++;
143 }
144 }
145
146 /* D->E paths */
147 for (q = 0; q < Q; q++) xEv = vmaxq_f32(xEv, DMO(dpc,q));
148
149 /* Specials */
150 XMXo(i,p7X_E) = esl_neon_hmax_f32((esl_neon_128f_t) xEv);
151
152 t1 = ( (om->xf[p7O_J][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_J] + pp->xmx[i*p7X_NXCELLS+p7X_J]);
153 t2 = ( (om->xf[p7O_E][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[ i *p7X_NXCELLS+p7X_E]);
154 ox->xmx[i*p7X_NXCELLS+p7X_J] = ESL_MAX(t1, t2);
155
156 t1 = ( (om->xf[p7O_C][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_C] + pp->xmx[i*p7X_NXCELLS+p7X_C]);
157 t2 = ( (om->xf[p7O_E][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[ i *p7X_NXCELLS+p7X_E]);
158 ox->xmx[i*p7X_NXCELLS+p7X_C] = ESL_MAX(t1, t2);
159
160 ox->xmx[i*p7X_NXCELLS+p7X_N] = ((om->xf[p7O_N][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_N] + pp->xmx[i*p7X_NXCELLS+p7X_N]);
161
162 t1 = ( (om->xf[p7O_N][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[i*p7X_NXCELLS+p7X_N]);
163 t2 = ( (om->xf[p7O_J][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[i*p7X_NXCELLS+p7X_J]);
164 ox->xmx[i*p7X_NXCELLS+p7X_B] = ESL_MAX(t1, t2);
165 }
166
167 *ret_e = ox->xmx[pp->L*p7X_NXCELLS+p7X_C];
168 return eslOK;
169 }
170 /*------------------- end, OA DP fill ---------------------------*/
171
172
173
174
175
176 /*****************************************************************
177 * 2. OA traceback
178 *****************************************************************/
179
180 static inline float get_postprob(const P7_OMX *pp, int scur, int sprv, int k, int i);
181
182 static inline int select_m(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k);
183 static inline int select_d(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k);
184 static inline int select_i(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k);
185 static inline int select_n(int i);
186 static inline int select_c(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i);
187 static inline int select_j(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i);
188 static inline int select_e(const P7_OPROFILE *om, const P7_OMX *ox, int i, int *ret_k);
189 static inline int select_b(const P7_OPROFILE *om, const P7_OMX *ox, int i);
190
191
192 /* Function: p7_OATrace()
193 * Synopsis: Optimal accuracy decoding: traceback.
194 * Incept: SRE, Mon Aug 18 13:53:33 2008 [Janelia]
195 *
196 * Purpose: The traceback stage of the optimal accuracy decoding algorithm
197 * \citep{Kall05}.
198 *
199 * Caller provides the OA DP matrix <ox> that was just
200 * calculated by <p7_OptimalAccuracyDP()>, as well as the
201 * posterior decoding matrix <pp>, which was calculated by
202 * Forward/Backward on a target sequence using the query
203 * model <gm>. Because the calculation depends only on
204 * <pp>, the target sequence itself need not be provided.
205 *
206 * The resulting optimal accuracy decoding traceback is put
207 * in a caller-provided traceback structure <tr>, which the
208 * caller has allocated for optional posterior probability
209 * annotation on residues (with <p7_trace_CreateWithPP()>,
210 * generally). This structure will be reallocated
211 * internally if necessary.
212 *
213 * Args: om - profile
214 * pp - posterior probability matrix
215 * ox - OA matrix to trace, LxM
216 * tr - storage for the recovered traceback
217 *
218 * Returns: <eslOK> on success.
219 *
220 * Throws: <eslEMEM> on allocation error.
221 * <eslEINVAL> if the trace <tr> isn't empty (needs to be Reuse()'d).
222 */
223 int
224 p7_OATrace(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, P7_TRACE *tr)
225 {
226 int i = ox->L; /* position in sequence 1..L */
227 int k = 0; /* position in model 1..M */
228 int s0, s1; /* choice of a state */
229 float postprob;
230 int status;
231
232 if (tr->N != 0) ESL_EXCEPTION(eslEINVAL, "trace not empty; needs to be Reuse()'d?");
233
234 if ((status = p7_trace_AppendWithPP(tr, p7T_T, k, i, 0.0)) != eslOK) return status;
235 if ((status = p7_trace_AppendWithPP(tr, p7T_C, k, i, 0.0)) != eslOK) return status;
236
237 s0 = tr->st[tr->N-1];
238 while (s0 != p7T_S)
239 {
240 switch (s0) {
241 case p7T_M: s1 = select_m(om, ox, i, k); k--; i--; break;
242 case p7T_D: s1 = select_d(om, ox, i, k); k--; break;
243 case p7T_I: s1 = select_i(om, ox, i, k); i--; break;
244 case p7T_N: s1 = select_n(i); break;
245 case p7T_C: s1 = select_c(om, pp, ox, i); break;
246 case p7T_J: s1 = select_j(om, pp, ox, i); break;
247 case p7T_E: s1 = select_e(om, ox, i, &k); break;
248 case p7T_B: s1 = select_b(om, ox, i); break;
249 default: ESL_EXCEPTION(eslEINVAL, "bogus state in traceback");
250 }
251 if (s1 == -1) ESL_EXCEPTION(eslEINVAL, "OA traceback choice failed");
252
253 postprob = get_postprob(pp, s1, s0, k, i);
254 if ((status = p7_trace_AppendWithPP(tr, s1, k, i, postprob)) != eslOK) return status;
255
256 if ( (s1 == p7T_N || s1 == p7T_J || s1 == p7T_C) && s1 == s0) i--;
257 s0 = s1;
258 } /* end traceback, at S state */
259 tr->M = om->M;
260 tr->L = ox->L;
261 return p7_trace_Reverse(tr);
262 }
263
264 static inline float
265 get_postprob(const P7_OMX *pp, int scur, int sprv, int k, int i)
266 {
267 int Q = p7O_NQF(pp->M);
268 int q = (k-1) % Q; /* (q,r) is position of the current DP cell M(i,k) */
269 int r = (k-1) / Q;
270 union { float32x4_t v; float p[4]; } u;
271
272 switch (scur) {
273 case p7T_M: u.v = MMO(pp->dpf[i], q); return u.p[r];
274 case p7T_I: u.v = IMO(pp->dpf[i], q); return u.p[r];
275 case p7T_N: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_N];
276 case p7T_C: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_C];
277 case p7T_J: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_J];
278 default: return 0.0;
279 }
280 }
281
282 /* M(i,k) is reached from B(i-1), M(i-1,k-1), D(i-1,k-1), or I(i-1,k-1). */
283 static inline int
284 select_m(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k)
285 {
286 int Q = p7O_NQF(ox->M);
287 int q = (k-1) % Q; /* (q,r) is position of the current DP cell M(i,k) */
288 int r = (k-1) / Q;
289 float32x4_t *tp = om->tfv + 7*q; /* *tp now at start of transitions to cur cell M(i,k) */
290 float32x4_t xBv = vmovq_n_f32(ox->xmx[(i-1)*p7X_NXCELLS+p7X_B]);
291 float32x4_t zerov = vmovq_n_f32(0.0);
292 float32x4_t mpv, dpv, ipv;
293 union { float32x4_t v; float p[4]; } u, tv;
294 float path[4];
295 int state[4] = { p7T_M, p7T_I, p7T_D, p7T_B };
296
297 if (q > 0) {
298 mpv = ox->dpf[i-1][(q-1)*3 + p7X_M];
299 dpv = ox->dpf[i-1][(q-1)*3 + p7X_D];
300 ipv = ox->dpf[i-1][(q-1)*3 + p7X_I];
301 } else {
302 mpv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_M], (esl_neon_128f_t) zerov).f32x4;
303 dpv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_D], (esl_neon_128f_t) zerov).f32x4;
304 ipv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_I], (esl_neon_128f_t) zerov).f32x4;
305 }
306
307 /* paths are numbered so that most desirable choice in case of tie is first. */
308 u.v = xBv; tv.v = *tp; path[3] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++;
309 u.v = mpv; tv.v = *tp; path[0] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++;
310 u.v = ipv; tv.v = *tp; path[1] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++;
311 u.v = dpv; tv.v = *tp; path[2] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]);
312 return state[esl_vec_FArgMax(path, 4)];
313 }
314
315
316 /* D(i,k) is reached from M(i, k-1) or D(i,k-1). */
317 static inline int
318 select_d(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k)
319 {
320 int Q = p7O_NQF(ox->M);
321 int q = (k-1) % Q; /* (q,r) is position of the current DP cell D(i,k) */
322 int r = (k-1) / Q;
323 float32x4_t zerov = vmovq_n_f32(0.0);
324 union { float32x4_t v; float p[4]; } mpv, dpv, tmdv, tddv;
325 float path[2];
326
327 if (q > 0) {
328 mpv.v = ox->dpf[i][(q-1)*3 + p7X_M];
329 dpv.v = ox->dpf[i][(q-1)*3 + p7X_D];
330 tmdv.v = om->tfv[7*(q-1) + p7O_MD];
331 tddv.v = om->tfv[7*Q + (q-1)];
332 } else {
333 mpv.v = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i][(Q-1)*3 + p7X_M], (esl_neon_128f_t) zerov).f32x4;
334 dpv.v = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i][(Q-1)*3 + p7X_D], (esl_neon_128f_t) zerov).f32x4;
335 tmdv.v = esl_neon_rightshift_float((esl_neon_128f_t) om->tfv[7*(Q-1) + p7O_MD], (esl_neon_128f_t) zerov).f32x4;
336 tddv.v = esl_neon_rightshift_float((esl_neon_128f_t) om->tfv[8*Q-1], (esl_neon_128f_t) zerov).f32x4;
337 }
338
339 path[0] = ((tmdv.p[r] == 0.0) ? -eslINFINITY : mpv.p[r]);
340 path[1] = ((tddv.p[r] == 0.0) ? -eslINFINITY : dpv.p[r]);
341 return ((path[0] >= path[1]) ? p7T_M : p7T_D);
342 }
343
344 /* I(i,k) is reached from M(i-1, k) or I(i-1,k). */
345 static inline int
346 select_i(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k)
347 {
348 int Q = p7O_NQF(ox->M);
349 int q = (k-1) % Q; /* (q,r) is position of the current DP cell D(i,k) */
350 int r = (k-1) / Q;
351 float32x4_t *tp = om->tfv + 7*q + p7O_MI;
352 union { float32x4_t v; float p[4]; } tv, mpv, ipv;
353 float path[2];
354
355 mpv.v = ox->dpf[i-1][q*3 + p7X_M]; tv.v = *tp; path[0] = ((tv.p[r] == 0.0) ? -eslINFINITY : mpv.p[r]); tp++;
356 ipv.v = ox->dpf[i-1][q*3 + p7X_I]; tv.v = *tp; path[1] = ((tv.p[r] == 0.0) ? -eslINFINITY : ipv.p[r]);
357 return ((path[0] >= path[1]) ? p7T_M : p7T_I);
358 }
359
360 /* N(i) must come from N(i-1) for i>0; else it comes from S */
361 static inline int
362 select_n(int i)
363 {
364 return ((i==0) ? p7T_S : p7T_N);
365 }
366
367 /* C(i) is reached from E(i) or C(i-1). */
368 static inline int
369 select_c(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i)
370 {
371 float path[2];
372 path[0] = ( (om->xf[p7O_C][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[(i-1)*p7X_NXCELLS+p7X_C] + pp->xmx[i*p7X_NXCELLS+p7X_C]);
373 path[1] = ( (om->xf[p7O_E][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[ i *p7X_NXCELLS+p7X_E]);
374 return ((path[0] > path[1]) ? p7T_C : p7T_E);
375 }
376
377 /* J(i) is reached from E(i) or J(i-1). */
378 static inline int
379 select_j(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i)
380 {
381 float path[2];
382
383 path[0] = ( (om->xf[p7O_J][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[(i-1)*p7X_NXCELLS+p7X_J] + pp->xmx[i*p7X_NXCELLS+p7X_J]);
384 path[1] = ( (om->xf[p7O_E][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[ i *p7X_NXCELLS+p7X_E]);
385 return ((path[0] > path[1]) ? p7T_J : p7T_E);
386 }
387
388 /* E(i) is reached from any M(i, k=1..M) or D(i, k=2..M). */
389 /* This assumes all M_k->E, D_k->E are 1.0 */
390 static inline int
391 select_e(const P7_OPROFILE *om, const P7_OMX *ox, int i, int *ret_k)
392 {
393 int Q = p7O_NQF(ox->M);
394 float32x4_t *dp = ox->dpf[i];
395 union { float32x4_t v; float p[4]; } u;
396 float max = -eslINFINITY;
397 int smax, kmax;
398 int q,r;
399
400 /* precedence rules in case of ties here are a little tricky: M beats D: note the >= max! */
401 for (q = 0; q < Q; q++)
402 {
403 u.v = *dp; dp++; for (r = 0; r < 4; r++) if (u.p[r] >= max) { max = u.p[r]; smax = p7T_M; kmax = r*Q + q + 1; }
404 u.v = *dp; dp+=2; for (r = 0; r < 4; r++) if (u.p[r] > max) { max = u.p[r]; smax = p7T_D; kmax = r*Q + q + 1; }
405 }
406 *ret_k = kmax;
407 return smax;
408 }
409
410
411 /* B(i) is reached from N(i) or J(i). */
412 static inline int
413 select_b(const P7_OPROFILE *om, const P7_OMX *ox, int i)
414 {
415 float path[2];
416
417 path[0] = ( (om->xf[p7O_N][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[i*p7X_NXCELLS+p7X_N]);
418 path[1] = ( (om->xf[p7O_J][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[i*p7X_NXCELLS+p7X_J]);
419 return ((path[0] > path[1]) ? p7T_N : p7T_J);
420 }
421 /*---------------------- end, OA traceback ----------------------*/
422
423
424
425
426 /*****************************************************************
427 * 3. Benchmark driver
428 *****************************************************************/
429 #ifdef p7OPTACC_BENCHMARK
430 /*
431 icc -O3 -static -o optacc_benchmark -I.. -L.. -I../../easel -L../../easel -Dp7OPTACC_BENCHMARK optacc.c -lhmmer -leasel -lm
432
433 ./optacc_benchmark <hmmfile> runs benchmark on optimal accuracy fill and trace
434 ./optacc_benchmark -c -N1 <hmmfile> compare scores of NEON version to generic impl
435 ./optacc_benchmark -x -N1 <hmmfile> test that scores match trusted implementation.
436
437 RRM_1 (M=72) Caudal_act (M=136) SMC_N (M=1151)
438 ----------------- ------------------ ---------------
439 20 Aug 08: 13.11u (110 Mc/s) 23.39u (116 Mc/s) 332.62u (69 Mc/s)
440
441 */
442 #include <p7_config.h>
443
444 #include "easel.h"
445 #include "esl_alphabet.h"
446 #include "esl_getopts.h"
447 #include "esl_random.h"
448 #include "esl_randomseq.h"
449 #include "esl_stopwatch.h"
450
451 #include "hmmer.h"
452 #include "impl_neon.h"
453
454 static ESL_OPTIONS options[] = {
455 /* name type default env range toggles reqs incomp help docgroup*/
456 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
457 { "-c", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-x", "compare scores to generic implementation (debug)", 0 },
458 { "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
459 { "-x", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-c", "equate scores to trusted implementation (debug)", 0 },
460 { "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 },
461 { "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 },
462 { "--notrace", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only benchmark the DP fill stage", 0 },
463 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
464 };
465 static char usage[] = "[-options] <hmmfile>";
466 static char banner[] = "benchmark driver for optimal accuracy alignment, NEON version";
467
468 int
469 main(int argc, char **argv)
470 {
471 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage);
472 char *hmmfile = esl_opt_GetArg(go, 1);
473 ESL_STOPWATCH *w = esl_stopwatch_Create();
474 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
475 ESL_ALPHABET *abc = NULL;
476 P7_HMMFILE *hfp = NULL;
477 P7_HMM *hmm = NULL;
478 P7_BG *bg = NULL;
479 P7_PROFILE *gm = NULL;
480 P7_OPROFILE *om = NULL;
481 P7_GMX *gx1 = NULL;
482 P7_GMX *gx2 = NULL;
483 P7_OMX *ox1 = NULL;
484 P7_OMX *ox2 = NULL;
485 P7_TRACE *tr = NULL;
486 int L = esl_opt_GetInteger(go, "-L");
487 int N = esl_opt_GetInteger(go, "-N");
488 ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2));
489 int i;
490 float fsc, bsc, accscore;
491 float fsc_g, bsc_g, accscore_g;
492 double Mcs;
493
494 p7_FLogsumInit();
495
496 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
497 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
498
499 bg = p7_bg_Create(abc); p7_bg_SetLength(bg, L);
500 gm = p7_profile_Create(hmm->M, abc); p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL);
501 om = p7_oprofile_Create(gm->M, abc); p7_oprofile_Convert(gm, om);
502 p7_oprofile_ReconfigLength(om, L);
503
504 if (esl_opt_GetBoolean(go, "-x") && p7_FLogsumError(-0.4, -0.5) > 0.0001)
505 p7_Fail("-x here requires p7_Logsum() recompiled in slow exact mode");
506
507 ox1 = p7_omx_Create(gm->M, L, L);
508 ox2 = p7_omx_Create(gm->M, L, L);
509 tr = p7_trace_CreateWithPP();
510
511 esl_rsq_xfIID(r, bg->f, abc->K, L, dsq);
512 p7_Forward (dsq, L, om, ox1, &fsc);
513 p7_Backward(dsq, L, om, ox1, ox2, &bsc);
514 p7_Decoding(om, ox1, ox2, ox2);
515
516 esl_stopwatch_Start(w);
517 for (i = 0; i < N; i++)
518 {
519 p7_OptimalAccuracy(om, ox2, ox1, &accscore);
520
521 if (! esl_opt_GetBoolean(go, "--notrace"))
522 {
523 p7_OATrace(om, ox2, ox1, tr);
524 p7_trace_Reuse(tr);
525 }
526 }
527 esl_stopwatch_Stop(w);
528
529 Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) w->user;
530 esl_stopwatch_Display(stdout, w, "# CPU time: ");
531 printf("# M = %d\n", gm->M);
532 printf("# %.1f Mc/s\n", Mcs);
533
534 if (esl_opt_GetBoolean(go, "-c") || esl_opt_GetBoolean(go, "-x") )
535 {
536 gx1 = p7_gmx_Create(gm->M, L);
537 gx2 = p7_gmx_Create(gm->M, L);
538
539 p7_GForward (dsq, L, gm, gx1, &fsc_g);
540 p7_GBackward(dsq, L, gm, gx2, &bsc_g);
541 p7_GDecoding(gm, gx1, gx2, gx2);
542 p7_GOptimalAccuracy(gm, gx2, gx1, &accscore_g);
543
544 printf("generic: fwd=%8.4f bck=%8.4f acc=%8.4f\n", fsc_g, bsc_g, accscore_g);
545 printf("NEON: fwd=%8.4f bck=%8.4f acc=%8.4f\n", fsc, bsc, accscore);
546
547 p7_gmx_Destroy(gx1);
548 p7_gmx_Destroy(gx2);
549 }
550
551 free(dsq);
552 p7_omx_Destroy(ox1);
553 p7_omx_Destroy(ox2);
554 p7_trace_Destroy(tr);
555 p7_oprofile_Destroy(om);
556 p7_profile_Destroy(gm);
557 p7_bg_Destroy(bg);
558 p7_hmm_Destroy(hmm);
559 p7_hmmfile_Close(hfp);
560 esl_alphabet_Destroy(abc);
561 esl_stopwatch_Destroy(w);
562 esl_randomness_Destroy(r);
563 esl_getopts_Destroy(go);
564 return 0;
565 }
566 #endif /*p7OPTACC_BENCHMARK*/
567 /*---------------- end, benchmark driver ------------------------*/
568
569
570
571
572 /*****************************************************************
573 * 4. Unit tests
574 *****************************************************************/
575 #ifdef p7OPTACC_TESTDRIVE
576 #include "esl_alphabet.h"
577 #include "esl_getopts.h"
578 #include "esl_random.h"
579 /*
580 * 1. Compare accscore to GOptimalAccuracy().
581 * 2. Compare trace to GOATrace().
582 *
583 * Note: This test is subject to some expected noise and can fail
584 * for entirely innocent reasons. Generic Forward/Backward calculations with
585 * p7_GForward(), p7_GBackward() use coarse-grain table lookups to sum
586 * log probabilities, and sufficient roundoff error can accumulate to
587 * change the optimal accuracy traceback, causing this test to fail.
588 * So, if optacc_utest fails, before you go looking for bugs, first
589 * go to ../logsum.c, change the #ifdef to activate the slow/accurate
590 * version, recompile and rerun optacc_utest. If the failure goes away,
591 * you can ignore it. - SRE, Wed Dec 17 09:45:31 2008
592 */
593 static void
594 utest_optacc(ESL_GETOPTS *go, ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_BG *bg, int M, int L, int N)
595 {
596 char *msg = "optimal accuracy unit test failed";
597 P7_HMM *hmm = NULL;
598 P7_PROFILE *gm = NULL;
599 P7_OPROFILE *om = NULL;
600 ESL_SQ *sq = esl_sq_CreateDigital(abc);
601 P7_OMX *ox1 = p7_omx_Create(M, L, L);
602 P7_OMX *ox2 = p7_omx_Create(M, L, L);
603 P7_GMX *gx1 = p7_gmx_Create(M, L);
604 P7_GMX *gx2 = p7_gmx_Create(M, L);
605 P7_TRACE *tr = p7_trace_CreateWithPP();
606 P7_TRACE *trg = p7_trace_CreateWithPP();
607 P7_TRACE *tro = p7_trace_CreateWithPP();
608 float accscore_o;
609 float fsc, bsc, accscore;
610 float fsc_g, bsc_g, accscore_g, accscore_g2;
611 float pptol = 0.01;
612 float sctol = 0.001;
613 float gtol;
614
615 p7_FLogsumInit();
616 gtol = ( (p7_FLogsumError(-0.4, -0.5) > 0.0001) ? 0.1 : 0.001);
617
618 if (p7_oprofile_Sample(r, abc, bg, M, L, &hmm, &gm, &om)!= eslOK) esl_fatal(msg);
619 while (N--)
620 {
621 if (p7_ProfileEmit(r, hmm, gm, bg, sq, tro) != eslOK) esl_fatal(msg);
622
623 if (p7_omx_GrowTo(ox1, M, sq->n, sq->n) != eslOK) esl_fatal(msg);
624 if (p7_omx_GrowTo(ox2, M, sq->n, sq->n) != eslOK) esl_fatal(msg);
625 if (p7_gmx_GrowTo(gx1, M, sq->n) != eslOK) esl_fatal(msg);
626 if (p7_gmx_GrowTo(gx2, M, sq->n) != eslOK) esl_fatal(msg);
627
628 if (p7_Forward (sq->dsq, sq->n, om, ox1, &fsc) != eslOK) esl_fatal(msg);
629 if (p7_Backward(sq->dsq, sq->n, om, ox1, ox2, &bsc) != eslOK) esl_fatal(msg);
630 if (p7_Decoding(om, ox1, ox2, ox2) != eslOK) esl_fatal(msg);
631 if (p7_OptimalAccuracy(om, ox2, ox1, &accscore) != eslOK) esl_fatal(msg);
632
633 #if 0
634 p7_omx_FDeconvert(ox1, gx1);
635 p7_gmx_Dump(stdout, gx1, p7_DEFAULT);
636 p7_omx_FDeconvert(ox2, gx1);
637 p7_gmx_Dump(stdout, gx1, p7_DEFAULT);
638 #endif
639 if (p7_OATrace(om, ox2, ox1, tr) != eslOK) esl_fatal(msg);
640
641 if (p7_GForward (sq->dsq, sq->n, gm, gx1, &fsc_g) != eslOK) esl_fatal(msg);
642 if (p7_GBackward(sq->dsq, sq->n, gm, gx2, &bsc_g) != eslOK) esl_fatal(msg);
643
644 #if 0
645 p7_gmx_Dump(stdout, gx1, p7_DEFAULT); /* fwd */
646 p7_gmx_Dump(stdout, gx2, p7_DEFAULT); /* bck */
647 #endif
648
649 if (p7_GDecoding(gm, gx1, gx2, gx2) != eslOK) esl_fatal(msg);
650 if (p7_GOptimalAccuracy(gm, gx2, gx1, &accscore_g) != eslOK) esl_fatal(msg);
651
652 #if 0
653 p7_gmx_Dump(stdout, gx1, p7_DEFAULT); /* oa */
654 p7_gmx_Dump(stdout, gx2, p7_DEFAULT); /* pp */
655 #endif
656 if (p7_GOATrace(gm, gx2, gx1, trg) != eslOK) esl_fatal(msg);
657
658 if (p7_trace_SetPP(tro, gx2) != eslOK) esl_fatal(msg);
659
660 if (esl_opt_GetBoolean(go, "--traces"))
661 {
662 p7_trace_Dump(stdout, tro, gm, sq->dsq);
663 p7_trace_Dump(stdout, tr, gm, sq->dsq);
664 p7_trace_Dump(stdout, trg, gm, sq->dsq);
665 }
666
667 if (p7_trace_Validate(tr, abc, sq->dsq, NULL) != eslOK) esl_fatal(msg);
668 if (p7_trace_Validate(trg, abc, sq->dsq, NULL) != eslOK) esl_fatal(msg);
669 if (p7_trace_Compare(tr, trg, pptol) != eslOK) esl_fatal(msg);
670
671 accscore_o = p7_trace_GetExpectedAccuracy(tro); /* according to gx2; see p7_trace_SetPP() call above */
672 accscore_g2 = p7_trace_GetExpectedAccuracy(trg);
673
674 #if 0
675 printf("%f %f %f %f\n", accscore, accscore_g, accscore_g2, accscore_o);
676 #endif
677
678 if (esl_FCompare_old(fsc, bsc, sctol) != eslOK) esl_fatal(msg);
679 if (esl_FCompare_old(fsc_g, bsc_g, gtol) != eslOK) esl_fatal(msg);
680 if (esl_FCompare_old(fsc, fsc_g, gtol) != eslOK) esl_fatal(msg);
681 if (esl_FCompare_old(accscore, accscore_g, gtol) != eslOK) esl_fatal(msg);
682 if (esl_FCompare_old(accscore_g, accscore_g2, gtol) != eslOK) esl_fatal(msg);
683 if (accscore_g2 < accscore_o) esl_fatal(msg);
684 /* the above deserves explanation:
685 * - accscore_o is the accuracy of the originally emitted trace, according
686 * to the generic posterior decoding matrix <gx2>. This is a lower bound
687 * on the expected # of accurately aligned residues found by a DP
688 * optimization.
689 * - accscore is the accuracy found by the fast (vector) code DP implementation.
690 * - accscore_g is the accuracy found by the generic DP implementation.
691 * accscore and accscore_g should be nearly identical,
692 * within tolerance of roundoff error accumulation and
693 * the imprecision of Logsum() tables.
694 * - accscore_g2 is the accuracy of the traceback identified by the generic
695 * DP implementation. It should be identical (within order-of-evaluation
696 * roundoff error) to accscore_g.
697 *
698 * the "accscore_g2 < accscore_o" test is carefully contrived.
699 * accscore_o is a theoretical lower bound but because of fp error,
700 * accscore and (much more rarely) even accscore_g can exceed accscore_o.
701 * accscore_g2, however, is calculated with identical order of evaluation
702 * as accscore_o if the optimal trace does turn out to be identical to
703 * the originally emitted trace. It should be extremely unlikely (though
704 * not impossible) for accscore_o to exceed accscore_g2. (The DP algorithm
705 * would have to identify a trace that was different than the original trace,
706 * which the DP algorithm, by order-of-evaluation, assigned higher accuracy,
707 * but order-of-evaluation in traceback dependent code assigned lower accuracy.
708 * [xref J5/29]
709 */
710
711 esl_sq_Reuse(sq);
712 p7_trace_Reuse(tr);
713 p7_trace_Reuse(trg);
714 p7_trace_Reuse(tro);
715 }
716
717 p7_trace_Destroy(tro);
718 p7_trace_Destroy(trg);
719 p7_trace_Destroy(tr);
720 p7_gmx_Destroy(gx2);
721 p7_gmx_Destroy(gx1);
722 p7_omx_Destroy(ox2);
723 p7_omx_Destroy(ox1);
724 esl_sq_Destroy(sq);
725 p7_oprofile_Destroy(om);
726 p7_profile_Destroy(gm);
727 p7_hmm_Destroy(hmm);
728 }
729
730 #endif /*p7OPTACC_TESTDRIVE*/
731 /*------------------- end, unit tests ---------------------------*/
732
733
734
735
736 /*****************************************************************
737 * 5. Test driver
738 *****************************************************************/
739 #ifdef p7OPTACC_TESTDRIVE
740
741 /* Failures in this test are to be expected, if you change the defaults.
742 * The default RNG seed of 41 is very carefully chosen! Most seeds will
743 * cause this test to fail. (Only 13 and 41 work for seeds 1..50.)
744 *
745 * The generic fwd/bck algorithms work in log space and suffer from a
746 * small amount of imprecision, not only from the use of FLogsum()'s
747 * table-driven approximation, but even (apparently) inherent in log()
748 * and exp(). To minimize this, the generic decoding algorithm burns
749 * time renormalizing each row. Still, it's a problem. See notes at
750 * the header of utest_optacc() for more info.
751 *
752 * Another expected failure mode is when a fwd, bck nat score are close to
753 * 0.0; FCompare() can evaluate two close-to-zero numbers as "different"
754 * even if their absolute diff is negligible. (I suppose I could fix this.)
755 */
756
757 /*
758 ./optacc_utest
759 */
760 #include <p7_config.h>
761
762 #include "easel.h"
763 #include "esl_alphabet.h"
764 #include "esl_getopts.h"
765
766 #include "hmmer.h"
767 #include "impl_neon.h"
768
769 static ESL_OPTIONS options[] = {
770 /* name type default env range toggles reqs incomp help docgroup*/
771 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
772 { "-s", eslARG_INT, "41", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
773 { "-L", eslARG_INT, "50", NULL, NULL, NULL, NULL, NULL, "size of random sequences to sample", 0 },
774 { "-M", eslARG_INT, "45", NULL, NULL, NULL, NULL, NULL, "size of random models to sample", 0 },
775 { "-N", eslARG_INT, "20", NULL, NULL, NULL, NULL, NULL, "number of random sequences to sample", 0 },
776 { "--traces", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump all tracebacks", 0 },
777 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
778 };
779 static char usage[] = "[-options]";
780 static char banner[] = "test driver for NEON Forward, Backward implementations";
781
782 int
783 main(int argc, char **argv)
784 {
785 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage);
786 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
787 ESL_ALPHABET *abc = NULL;
788 P7_BG *bg = NULL;
789 int M = esl_opt_GetInteger(go, "-M");
790 int L = esl_opt_GetInteger(go, "-L");
791 int N = esl_opt_GetInteger(go, "-N");
792
793 /* first round of tests for DNA alphabets. */
794 if ((abc = esl_alphabet_Create(eslDNA)) == NULL) esl_fatal("failed to create alphabet");
795 if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model");
796
797 utest_optacc(go, r, abc, bg, M, L, N); /* normal sized models */
798 utest_optacc(go, r, abc, bg, 1, L, 10); /* size 1 models */
799 utest_optacc(go, r, abc, bg, M, 1, 10); /* size 1 sequences */
800
801 esl_alphabet_Destroy(abc);
802 p7_bg_Destroy(bg);
803
804 /* Second round of tests for amino alphabets. */
805 if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet");
806 if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model");
807
808 utest_optacc(go, r, abc, bg, M, L, N);
809 utest_optacc(go, r, abc, bg, 1, L, 10);
810 utest_optacc(go, r, abc, bg, M, 1, 10);
811
812 esl_alphabet_Destroy(abc);
813 p7_bg_Destroy(bg);
814
815 esl_getopts_Destroy(go);
816 esl_randomness_Destroy(r);
817 return eslOK;
818 }
819 #endif /*p7OPTACC_TESTDRIVE*/
820 /*------------------ end, test driver ---------------------------*/
821
822
823
824
825 /*****************************************************************
826 * 6. Example
827 *****************************************************************/
828 #ifdef p7OPTACC_EXAMPLE
829 /*
830 gcc -g -Wall -o optacc_example -Dp7OPTACC_EXAMPLE -I.. -I../../easel -L.. -L../../easel optacc.c -lhmmer -leasel -lm
831 ./optacc_example <hmmfile> <seqfile>
832 */
833 #include <p7_config.h>
834
835 #include "easel.h"
836 #include "esl_alphabet.h"
837 #include "esl_getopts.h"
838 #include "esl_sq.h"
839 #include "esl_sqio.h"
840
841 #include "hmmer.h"
842 #include "impl_neon.h"
843
844 static ESL_OPTIONS options[] = {
845 /* name type default env range toggles reqs incomp help docgroup*/
846 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
847 { "-d", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump posterior residue decoding matrix", 0 },
848 { "-m", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump OA matrix", 0 },
849 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
850 };
851 static char usage[] = "[-options] <hmmfile> <seqfile>";
852 static char banner[] = "example of optimal accuracy alignment, NEON implementation";
853
854 int
855 main(int argc, char **argv)
856 {
857 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage);
858 char *hmmfile = esl_opt_GetArg(go, 1);
859 char *seqfile = esl_opt_GetArg(go, 2);
860 ESL_ALPHABET *abc = NULL;
861 P7_HMMFILE *hfp = NULL;
862 P7_HMM *hmm = NULL;
863 P7_BG *bg = NULL;
864 P7_PROFILE *gm = NULL;
865 P7_OPROFILE *om = NULL;
866 P7_OMX *ox1 = NULL;
867 P7_OMX *ox2 = NULL;
868 P7_GMX *gx = NULL;
869 ESL_SQ *sq = NULL;
870 ESL_SQFILE *sqfp = NULL;
871 P7_TRACE *tr = NULL;
872 int format = eslSQFILE_UNKNOWN;
873 char errbuf[eslERRBUFSIZE];
874 float fsc, bsc;
875 float accscore;
876 int status;
877
878 /* Read in one HMM */
879 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
880 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
881 p7_hmmfile_Close(hfp);
882
883 /* Read in one sequence */
884 sq = esl_sq_CreateDigital(abc);
885 status = esl_sqfile_OpenDigital(abc, seqfile, format, NULL, &sqfp);
886 if (status == eslENOTFOUND) p7_Fail("No such file.");
887 else if (status == eslEFORMAT) p7_Fail("Format unrecognized.");
888 else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz.");
889 else if (status != eslOK) p7_Fail("Open failed, code %d.", status);
890 if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence");
891 esl_sqfile_Close(sqfp);
892
893 /* Configure a profile from the HMM */
894 bg = p7_bg_Create(abc); p7_bg_SetLength(bg, sq->n);
895 gm = p7_profile_Create(hmm->M, abc); p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL); /* multihit local: H3 default */
896 om = p7_oprofile_Create(gm->M, abc); p7_oprofile_Convert(gm, om);
897
898 /* Allocations */
899 ox1 = p7_omx_Create(gm->M, sq->n, sq->n);
900 ox2 = p7_omx_Create(gm->M, sq->n, sq->n);
901 gx = p7_gmx_Create(gm->M, sq->n);
902 tr = p7_trace_CreateWithPP();
903 p7_FLogsumInit();
904
905 /* Run Forward, Backward; do OA fill and trace */
906 p7_Forward (sq->dsq, sq->n, om, ox1, &fsc);
907 p7_Backward(sq->dsq, sq->n, om, ox1, ox2, &bsc);
908 p7_Decoding(om, ox1, ox2, ox2); /* <gx2> is now the posterior decoding matrix */
909 p7_OptimalAccuracy(om, ox2, ox1, &accscore); /* <gx1> is now the OA matrix */
910 p7_OATrace(om, ox2, ox1, tr);
911
912 if (esl_opt_GetBoolean(go, "-d")) { p7_omx_FDeconvert(ox2, gx); p7_gmx_Dump(stdout, gx, p7_DEFAULT); }
913 if (esl_opt_GetBoolean(go, "-m")) { p7_omx_FDeconvert(ox1, gx); p7_gmx_Dump(stdout, gx, p7_DEFAULT); }
914
915 p7_trace_Dump(stdout, tr, gm, sq->dsq);
916
917 if (p7_trace_Validate(tr, abc, sq->dsq, errbuf) != eslOK) p7_Die("trace fails validation:\n%s\n", errbuf);
918
919 printf("fwd = %.4f nats\n", fsc);
920 printf("bck = %.4f nats\n", bsc);
921 printf("acc = %.4f (%.2f%%)\n", accscore, accscore * 100. / (float) sq->n);
922
923 /* Cleanup */
924 esl_sq_Destroy(sq);
925 p7_trace_Destroy(tr);
926 p7_omx_Destroy(ox1);
927 p7_omx_Destroy(ox2);
928 p7_gmx_Destroy(gx);
929 p7_oprofile_Destroy(om);
930 p7_profile_Destroy(gm);
931 p7_bg_Destroy(bg);
932 p7_hmm_Destroy(hmm);
933 esl_alphabet_Destroy(abc);
934 esl_getopts_Destroy(go);
935 return 0;
936 }
937 #endif /*p7OPTACC_EXAMPLE*/
938 /*-------------------- end, example -----------------------------*/