Debian Codegraph @

hmmer/src/impl_sse/vitscore.c

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