Debian Codegraph @

hmmer/src/impl_vmx/vitscore.c

raw symbols SCIP
1 /* Viterbi score implementation; VMX version.
2 *
3 * This is a SIMD vectorized, striped, interleaved, one-row O(M)
4 * memory implementation of the Viterbi algorithm, for calculating an
5 * accurate Viterbi score, without traceback.
6 *
7 * This implementation has full range and precision, so it may be used
8 * in any alignment mode (not just local), and on any target sequence
9 * (not excluding high-scoring ones).
10 *
11 * The optimized profile must be configured to contain lspace float
12 * scores, not its normal pspace float scores.
13 *
14 * Contents:
15 * 1. Viterbi score implementation.
16 * 2. Benchmark driver.
17 * 3. Unit tests.
18 * 4. Test driver.
19 * 5. Example.
20 *
21 * SRE, Sun Aug 3 13:10:24 2008 [St. Louis]
22 */
23 #include <p7_config.h>
24
25 #include <stdio.h>
26 #include <math.h>
27
28 #ifndef __APPLE_ALTIVEC__
29 #include <altivec.h>
30 #endif
31
32 #include "easel.h"
33 #include "esl_vmx.h"
34
35 #include "hmmer.h"
36 #include "impl_vmx.h"
37
38 /*****************************************************************
39 * 1. Viterbi score implementation
40 *****************************************************************/
41
42 /* Function: p7_ViterbiScore()
43 * Synopsis: Calculates Viterbi score, correctly, and vewy vewy fast.
44 * Incept: SRE, Tue Nov 27 09:15:24 2007 [Janelia]
45 *
46 * Purpose: Calculates the Viterbi score for sequence <dsq> of length <L>
47 * residues, using optimized profile <om>, and a preallocated
48 * one-row DP matrix <ox>. Return the Viterbi score (in nats)
49 * in <ret_sc>.
50 *
51 * The model <om> must be configured specially to have
52 * lspace float scores, not its usual pspace float scores for
53 * <p7_ForwardFilter()>.
54 *
55 * As with all <*Score()> implementations, the score is
56 * accurate (full range and precision) and can be
57 * calculated on models in any mode, not only local modes.
58 *
59 * Args: dsq - digital target sequence, 1..L
60 * L - length of dsq in residues
61 * om - optimized profile
62 * ox - DP matrix
63 * ret_sc - RETURN: Viterbi score (in nats)
64 *
65 * Returns: <eslOK> on success.
66 *
67 * Throws: <eslEINVAL> if <ox> allocation is too small.
68 */
69 int
70 p7_ViterbiScore(const ESL_DSQ *dsq, int L, const P7_OPROFILE *om, P7_OMX *ox, float *ret_sc)
71 {
72 vector float mpv, dpv, ipv; /* previous row values */
73 vector float sv; /* temp storage of 1 curr row value in progress */
74 vector float dcv; /* delayed storage of D(i,q+1) */
75 vector float xEv; /* E state: keeps max for Mk->E as we go */
76 vector float xBv; /* B state: splatted vector of B[i-1] for B->Mk calculations */
77 vector float Dmaxv; /* keeps track of maximum D cell on row */
78 vector float infv; /* -eslINFINITY in a vector */
79 float xN, xE, xB, xC, xJ; /* special states' scores */
80 float Dmax; /* maximum D cell on row */
81 int i; /* counter over sequence positions 1..L */
82 int q; /* counter over vectors 0..nq-1 */
83 int Q = p7O_NQF(om->M); /* segment length: # of vectors */
84 vector float *dp = ox->dpf[0]; /* using {MDI}MX(q) macro requires initialization of <dp> */
85 vector float *rsc; /* will point at om->rf[x] for residue x[i] */
86 vector float *tsc; /* will point into (and step thru) om->tf */
87
88 /* Check that the DP matrix is ok for us. */
89 if (Q > ox->allocQ4) ESL_EXCEPTION(eslEINVAL, "DP matrix allocated too small");
90 ox->M = om->M;
91
92 /* Initialization. */
93 infv = esl_vmx_set_float(-eslINFINITY);
94 for (q = 0; q < Q; q++)
95 MMXo(q) = IMXo(q) = DMXo(q) = infv;
96 xN = 0.;
97 xB = om->xf[p7O_N][p7O_MOVE];
98 xE = -eslINFINITY;
99 xJ = -eslINFINITY;
100 xC = -eslINFINITY;
101
102 #if eslDEBUGLEVEL > 0
103 if (ox->debugging) p7_omx_DumpFloatRow(ox, FALSE, 0, 5, 2, xE, xN, xJ, xB, xC); /* logify=FALSE, <rowi>=0, width=5, precision=2*/
104 #endif
105
106 for (i = 1; i <= L; i++)
107 {
108 rsc = om->rf[dsq[i]];
109 tsc = om->tf;
110 dcv = infv;
111 xEv = infv;
112 Dmaxv = infv;
113 xBv = esl_vmx_set_float(xB);
114
115 mpv = vec_sld(infv, MMXo(Q-1), 12); /* Right shifts by 4 bytes. 4,8,12,x becomes x,4,8,12. */
116 dpv = vec_sld(infv, DMXo(Q-1), 12);
117 ipv = vec_sld(infv, IMXo(Q-1), 12);
118 for (q = 0; q < Q; q++)
119 {
120 /* Calculate new MMXo(i,q); don't store it yet, hold it in sv. */
121 sv = vec_add(xBv, *tsc); tsc++;
122 sv = vec_max(sv, vec_add(mpv, *tsc)); tsc++;
123 sv = vec_max(sv, vec_add(ipv, *tsc)); tsc++;
124 sv = vec_max(sv, vec_add(dpv, *tsc)); tsc++;
125 sv = vec_add(sv, *rsc); rsc++;
126 xEv = vec_max(xEv, sv);
127
128 /* Load {MDI}(i-1,q) into mpv, dpv, ipv;
129 * {MDI}MX(q) is then the current, not the prev row
130 */
131 mpv = MMXo(q);
132 dpv = DMXo(q);
133 ipv = IMXo(q);
134
135 /* Do the delayed stores of {MD}(i,q) now that memory is usable */
136 MMXo(q) = sv;
137 DMXo(q) = dcv;
138
139 /* Calculate the next D(i,q+1) partially: M->D only;
140 * delay storage, holding it in dcv
141 */
142 dcv = vec_add(sv, *tsc); tsc++;
143 Dmaxv = vec_max(dcv, Dmaxv);
144
145 /* Calculate and store I(i,q) */
146 sv = vec_add(mpv, *tsc); tsc++;
147 sv = vec_max(sv, vec_add(ipv, *tsc)); tsc++;
148 IMXo(q) = vec_add(sv, *rsc); rsc++;
149 }
150
151 /* Now the "special" states, which start from Mk->E (->C, ->J->B) */
152 xE = esl_vmx_hmax_float(xEv);
153 xN = xN + om->xf[p7O_N][p7O_LOOP];
154 xC = ESL_MAX(xC + om->xf[p7O_C][p7O_LOOP], xE + om->xf[p7O_E][p7O_MOVE]);
155 xJ = ESL_MAX(xJ + om->xf[p7O_J][p7O_LOOP], xE + om->xf[p7O_E][p7O_LOOP]);
156 xB = ESL_MAX(xJ + om->xf[p7O_J][p7O_MOVE], xN + om->xf[p7O_N][p7O_MOVE]);
157 /* and now xB will carry over into next i, and xC carries over after i=L */
158
159 /* Finally the "lazy F" loop (sensu [Farrar07]). We can often
160 * prove that we don't need to evaluate any D->D paths at all.
161 *
162 * The observation is that if we can show that on the next row,
163 * B->M(i+1,k) paths always dominate M->D->...->D->M(i+1,k) paths
164 * for all k, then we don't need any D->D calculations.
165 *
166 * The test condition is:
167 * max_k D(i,k) + max_k ( TDD(k-2) + TDM(k-1) - TBM(k) ) < xB(i)
168 * So:
169 * max_k (TDD(k-2) + TDM(k-1) - TBM(k)) is precalc'ed in om->dd_bound;
170 * max_k D(i,k) is why we tracked Dmaxv;
171 * xB(i) was just calculated above.
172 */
173 Dmax = esl_vmx_hmax_float(Dmaxv);
174 if (Dmax + om->ddbound_f > xB)
175 {
176 /* Now we're obligated to do at least one complete DD path to be sure. */
177 /* dcv has carried through from end of q loop above */
178 dcv = vec_sld(infv, dcv, 12);
179 tsc = om->tf + 7*Q; /* set tsc to start of the DD's */
180 for (q = 0; q < Q; q++)
181 {
182 DMXo(q) = vec_max(dcv, DMXo(q));
183 dcv = vec_add(DMXo(q), *tsc); tsc++;
184 }
185
186 /* We may have to do up to three more passes; the check
187 * is for whether crossing a segment boundary can improve
188 * our score.
189 */
190 do {
191 dcv = vec_sld(infv, dcv, 12);
192 tsc = om->tf + 7*Q; /* set tsc to start of the DD's */
193 for (q = 0; q < Q; q++)
194 {
195 if (! vec_any_gt(dcv, DMXo(q))) break;
196 DMXo(q) = vec_max(dcv, DMXo(q));
197 dcv = vec_add(DMXo(q), *tsc); tsc++;
198 }
199 } while (q == Q);
200 }
201 else
202 { /* not calculating DD? then just store that last MD vector we calc'ed. */
203 dcv = vec_sld(infv, dcv, 12);
204 DMXo(0) = dcv;
205 }
206
207 #if eslDEBUGLEVEL > 0
208 if (ox->debugging) p7_omx_DumpFloatRow(ox, FALSE, i, 5, 2, xE, xN, xJ, xB, xC); /* logify=FALSE, <rowi>=i, width=5, precision=2*/
209 #endif
210 } /* end loop over sequence residues 1..L */
211
212 /* finally C->T */
213 *ret_sc = xC + om->xf[p7O_C][p7O_MOVE];
214 return eslOK;
215 }
216 /*------------------ end, p7_ViterbiScore() ---------------------*/
217
218
219
220 /*****************************************************************
221 * 2. Benchmark driver.
222 *****************************************************************/
223 #ifdef p7VITSCORE_BENCHMARK
224 /* -c, -x are used for debugging, testing. See msvfilter.c for
225 * an explanation. Here -c and -x are the same: both compare
226 * to p7_GViterbi() scores.
227 */
228 /*
229 gcc -o benchmark-vitscore -std=gnu99 -g -Wall -maltivec -I.. -L.. -I../../easel -L../../easel -Dp7VITSCORE_BENCHMARK vitscore.c -lhmmer -leasel -lm
230 icc -o benchmark-vitscore -O3 -static -I.. -L.. -I../../easel -L../../easel -Dp7VITSCORE_BENCHMARK vitscore.c -lhmmer -leasel -lm
231
232 ./benchmark-vitscore <hmmfile> runs benchmark
233 ./benchmark-vitscore -N100 -c <hmmfile> compare scores to generic impl
234 ./benchmark-vitscore -N100 -x <hmmfile> equate scores to exact emulation
235 */
236 #include <p7_config.h>
237
238 #include "easel.h"
239 #include "esl_alphabet.h"
240 #include "esl_getopts.h"
241 #include "esl_random.h"
242 #include "esl_randomseq.h"
243 #include "esl_stopwatch.h"
244
245 #include "hmmer.h"
246 #include "impl_vmx.h"
247
248 static ESL_OPTIONS options[] = {
249 /* name type default env range toggles reqs incomp help docgroup*/
250 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
251 { "-c", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-x", "compare scores to generic implementation (debug)", 0 },
252 { "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
253 { "-x", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-c", "equate scores to trusted implementation (debug)", 0 },
254 { "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 },
255 { "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 },
256 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
257 };
258 static char usage[] = "[-options] <hmmfile>";
259 static char banner[] = "benchmark driver for VMX ViterbiScore()";
260
261 int
262 main(int argc, char **argv)
263 {
264 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage);
265 char *hmmfile = esl_opt_GetArg(go, 1);
266 ESL_STOPWATCH *w = esl_stopwatch_Create();
267 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
268 ESL_ALPHABET *abc = NULL;
269 P7_HMMFILE *hfp = NULL;
270 P7_HMM *hmm = NULL;
271 P7_BG *bg = NULL;
272 P7_PROFILE *gm = NULL;
273 P7_OPROFILE *om = NULL;
274 P7_OMX *ox = NULL;
275 P7_GMX *gx = NULL;
276 int L = esl_opt_GetInteger(go, "-L");
277 int N = esl_opt_GetInteger(go, "-N");
278 ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2));
279 int i;
280 float sc1, sc2;
281 double base_time, bench_time, Mcs;
282
283 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
284 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
285
286 bg = p7_bg_Create(abc);
287 p7_bg_SetLength(bg, L);
288 gm = p7_profile_Create(hmm->M, abc);
289 p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL);
290 om = p7_oprofile_Create(gm->M, abc);
291 p7_oprofile_Convert(gm, om);
292 p7_oprofile_ReconfigLength(om, L);
293 p7_oprofile_Logify(om);
294
295 ox = p7_omx_Create(gm->M, 0, 0);
296 gx = p7_gmx_Create(gm->M, L);
297
298 /* Get a baseline time: how long it takes just to generate the sequences */
299 esl_stopwatch_Start(w);
300 for (i = 0; i < N; i++)
301 esl_rsq_xfIID(r, bg->f, abc->K, L, dsq);
302 esl_stopwatch_Stop(w);
303 base_time = w->user;
304
305 /* Run the benchmark */
306 esl_stopwatch_Start(w);
307 for (i = 0; i < N; i++)
308 {
309 esl_rsq_xfIID(r, bg->f, abc->K, L, dsq);
310 p7_ViterbiScore (dsq, L, om, ox, &sc1);
311
312 if (esl_opt_GetBoolean(go, "-c") || esl_opt_GetBoolean(go, "-x"))
313 {
314 p7_GViterbi(dsq, L, gm, gx, &sc2);
315 printf("%.4f %.4f\n", sc1, sc2);
316 }
317 }
318 esl_stopwatch_Stop(w);
319 bench_time = w->user - base_time;
320 Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) bench_time;
321 esl_stopwatch_Display(stdout, w, "# CPU time: ");
322 printf("# M = %d\n", gm->M);
323 printf("# %.1f Mc/s\n", Mcs);
324
325 free(dsq);
326 p7_omx_Destroy(ox);
327 p7_gmx_Destroy(gx);
328 p7_oprofile_Destroy(om);
329 p7_profile_Destroy(gm);
330 p7_bg_Destroy(bg);
331 p7_hmm_Destroy(hmm);
332 p7_hmmfile_Close(hfp);
333 esl_alphabet_Destroy(abc);
334 esl_stopwatch_Destroy(w);
335 esl_randomness_Destroy(r);
336 esl_getopts_Destroy(go);
337 return 0;
338 }
339 #endif /*p7VITSCORE_BENCHMARK*/
340 /*------------------- end, benchmark driver ---------------------*/
341
342
343
344 /*****************************************************************
345 * 3. Unit tests.
346 *****************************************************************/
347 #ifdef p7VITSCORE_TESTDRIVE
348 #include "esl_random.h"
349 #include "esl_randomseq.h"
350
351 /* ViterbiScore() unit test
352 *
353 * We can compare these scores to GViterbi() almost exactly; the only
354 * differences should be negligible roundoff errors. Must convert
355 * the optimized profile to lspace, though, rather than pspace.
356 */
357 static void
358 utest_viterbi_score(ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_BG *bg, int M, int L, int N)
359 {
360 P7_HMM *hmm = NULL;
361 P7_PROFILE *gm = NULL;
362 P7_OPROFILE *om = NULL;
363 ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2));
364 P7_OMX *ox = p7_omx_Create(M, 0, 0);
365 P7_GMX *gx = p7_gmx_Create(M, L);
366 float sc1, sc2;
367
368 p7_oprofile_Sample(r, abc, bg, M, L, &hmm, &gm, &om);
369 p7_oprofile_Logify(om);
370 while (N--)
371 {
372 esl_rsq_xfIID(r, bg->f, abc->K, L, dsq);
373
374 p7_ViterbiScore(dsq, L, om, ox, &sc1);
375 p7_GViterbi (dsq, L, gm, gx, &sc2);
376
377 if (fabs(sc1-sc2) > 0.001) esl_fatal("viterbi score unit test failed: scores differ");
378 }
379
380 free(dsq);
381 p7_hmm_Destroy(hmm);
382 p7_omx_Destroy(ox);
383 p7_gmx_Destroy(gx);
384 p7_profile_Destroy(gm);
385 p7_oprofile_Destroy(om);
386 }
387 #endif /*p7VITSCORE_TESTDRIVE*/
388 /*-------------------- end, unit tests --------------------------*/
389
390 /*****************************************************************
391 * 4. Test driver
392 *****************************************************************/
393 #ifdef p7VITSCORE_TESTDRIVE
394 /*
395 gcc -g -Wall -maltivec -std=gnu99 -I.. -L.. -I../../easel -L../../easel -o vitscore_utest -Dp7VITSCORE_TESTDRIVE vitscore.c -lhmmer -leasel -lm
396 ./vitscore_utest
397 */
398 #include <p7_config.h>
399
400 #include "easel.h"
401 #include "esl_alphabet.h"
402 #include "esl_getopts.h"
403
404 #include "hmmer.h"
405 #include "impl_vmx.h"
406
407 static ESL_OPTIONS options[] = {
408 /* name type default env range toggles reqs incomp help docgroup*/
409 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
410 { "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
411 { "-L", eslARG_INT, "200", NULL, NULL, NULL, NULL, NULL, "size of random sequences to sample", 0 },
412 { "-M", eslARG_INT, "145", NULL, NULL, NULL, NULL, NULL, "size of random models to sample", 0 },
413 { "-N", eslARG_INT, "100", NULL, NULL, NULL, NULL, NULL, "number of random sequences to sample", 0 },
414 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
415 };
416 static char usage[] = "[-options]";
417 static char banner[] = "test driver for the VMX implementation";
418
419 int
420 main(int argc, char **argv)
421 {
422 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage);
423 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
424 ESL_ALPHABET *abc = NULL;
425 P7_BG *bg = NULL;
426 int M = esl_opt_GetInteger(go, "-M");
427 int L = esl_opt_GetInteger(go, "-L");
428 int N = esl_opt_GetInteger(go, "-N");
429
430 /* First round of tests for DNA alphabets. */
431 if ((abc = esl_alphabet_Create(eslDNA)) == NULL) esl_fatal("failed to create alphabet");
432 if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model");
433
434 utest_viterbi_score(r, abc, bg, M, L, N);
435 utest_viterbi_score(r, abc, bg, 1, L, 10);
436 utest_viterbi_score(r, abc, bg, M, 1, 10);
437
438 esl_alphabet_Destroy(abc);
439 p7_bg_Destroy(bg);
440
441 /* Second round of tests for amino alphabets. */
442 if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet");
443 if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model");
444
445 utest_viterbi_score(r, abc, bg, M, L, N);
446 utest_viterbi_score(r, abc, bg, 1, L, 10);
447 utest_viterbi_score(r, abc, bg, M, 1, 10);
448
449 esl_alphabet_Destroy(abc);
450 p7_bg_Destroy(bg);
451
452 esl_getopts_Destroy(go);
453 esl_randomness_Destroy(r);
454 return eslOK;
455 }
456 #endif /*VITSCORE_TESTDRIVE*/
457 /*--------------------- end, test driver ------------------------*/
458
459
460 /*****************************************************************
461 * 5. Example
462 *****************************************************************/
463 #ifdef p7VITSCORE_EXAMPLE
464 /* A minimal example.
465 Also useful for debugging on small HMMs and sequences.
466
467 gcc -g -Wall -maltivec -std=gnu99 -I.. -L.. -I../../easel -L../../easel -o example -Dp7VITSCORE_EXAMPLE vitscore.c -lhmmer -leasel -lm
468 ./example <hmmfile> <seqfile>
469 */
470 #include <p7_config.h>
471
472 #include "easel.h"
473 #include "esl_alphabet.h"
474 #include "esl_sq.h"
475 #include "esl_sqio.h"
476
477 #include "hmmer.h"
478 #include "impl_vmx.h"
479
480 int
481 main(int argc, char **argv)
482 {
483 char *hmmfile = argv[1];
484 char *seqfile = argv[2];
485 ESL_ALPHABET *abc = NULL;
486 P7_HMMFILE *hfp = NULL;
487 P7_HMM *hmm = NULL;
488 P7_BG *bg = NULL;
489 P7_PROFILE *gm = NULL;
490 P7_OPROFILE *om = NULL;
491 P7_OMX *ox = NULL;
492 P7_GMX *gx = NULL;
493 ESL_SQ *sq = NULL;
494 ESL_SQFILE *sqfp = NULL;
495 int format = eslSQFILE_UNKNOWN;
496 float sc;
497 int status;
498
499 /* Read in one HMM */
500 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
501 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
502
503 /* Read in one sequence */
504 sq = esl_sq_CreateDigital(abc);
505 status = esl_sqfile_Open(seqfile, format, NULL, &sqfp);
506 if (status == eslENOTFOUND) p7_Fail("No such file.");
507 else if (status == eslEFORMAT) p7_Fail("Format unrecognized.");
508 else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz.");
509 else if (status != eslOK) p7_Fail("Open failed, code %d.", status);
510 if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence");
511
512 /* create default null model, then create and optimize profile */
513 bg = p7_bg_Create(abc);
514 p7_bg_SetLength(bg, sq->n);
515 gm = p7_profile_Create(hmm->M, abc);
516 p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL);
517 om = p7_oprofile_Create(gm->M, abc);
518 p7_oprofile_Convert(gm, om);
519 p7_oprofile_Logify(om);
520
521 /* allocate DP matrices, both a generic and an optimized one */
522 ox = p7_omx_Create(gm->M, 0, sq->n);
523 gx = p7_gmx_Create(gm->M, sq->n);
524
525 /* Useful to place and compile in for debugging:
526 p7_oprofile_Dump(stdout, om); dumps the optimized profile
527 p7_omx_SetDumpMode(ox, TRUE); makes the fast DP algorithms dump their matrices
528 p7_gmx_Dump(stdout, gx, p7_DEFAULT); dumps a generic DP matrix
529 */
530
531 p7_ViterbiScore(sq->dsq, sq->n, om, ox, &sc); printf("viterbi score (VMX): %.2f nats\n", sc);
532 p7_GViterbi (sq->dsq, sq->n, gm, gx, &sc); printf("viterbi (generic): %.2f nats\n", sc);
533
534 /* now in a real app, you'd need to convert raw nat scores to final bit
535 * scores, by subtracting the null model score and rescaling.
536 */
537
538 /* cleanup */
539 esl_sq_Destroy(sq);
540 esl_sqfile_Close(sqfp);
541 p7_omx_Destroy(ox);
542 p7_gmx_Destroy(gx);
543 p7_oprofile_Destroy(om);
544 p7_profile_Destroy(gm);
545 p7_bg_Destroy(bg);
546 p7_hmm_Destroy(hmm);
547 p7_hmmfile_Close(hfp);
548 esl_alphabet_Destroy(abc);
549 return 0;
550 }
551 #endif /*p7VITSCORE_EXAMPLE*/
552 /*-------------------------- end, example ------------------------------*/
553