Debian Codegraph @

hmmer/src/generic_stotrace.c

raw symbols SCIP
1 /* Stochastic traceback of a Forward matrix; generic (non-SIMD) version.
2 *
3 * Contents:
4 * 1. Stochastic traceback implementation.
5 * 2. Benchmark driver.
6 * 3. Unit tests.
7 * 4. Test driver.
8 * 5. Example.
9 *
10 * SRE, Fri Aug 15 10:50:55 2008 [Janelia]
11 */
12 #include <p7_config.h>
13
14 #include "easel.h"
15 #include "esl_alphabet.h"
16 #include "esl_random.h"
17 #include "esl_vectorops.h"
18
19 #include "hmmer.h"
20
21 /*****************************************************************
22 * 1. Stochastic traceback implementation.
23 *****************************************************************/
24
25 /* Function: p7_GStochasticTrace()
26 * Synopsis: Stochastic traceback of a Forward matrix.
27 * Incept: SRE, Thu Jan 3 15:39:20 2008 [Janelia]
28 *
29 * Purpose: Stochastic traceback of Forward matrix <gx> to
30 * sample an alignment of digital sequence <dsq>
31 * (of length <L>) to the profile <gm>.
32 *
33 * The sampled traceback is returned in <tr>, which the
34 * caller must have at least made an initial allocation of
35 * (the <tr> will be grown as needed here).
36 *
37 * Args: r - source of random numbers
38 * dsq - digital sequence aligned to, 1..L
39 * L - length of dsq
40 * gm - profile
41 * mx - Forward matrix to trace, L x M
42 * tr - storage for the recovered traceback.
43 *
44 * Returns: <eslOK> on success.
45 */
46 int
47 p7_GStochasticTrace(ESL_RANDOMNESS *r, const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, const P7_GMX *gx, P7_TRACE *tr)
48 {
49 int status;
50 int i; /* position in seq (1..L) */
51 int k; /* position in model (1..M) */
52 int M = gm->M;
53 float **dp = gx->dp;
54 float *xmx = gx->xmx;
55 float const *tsc = gm->tsc;
56 float *sc; /* scores of possible choices: up to 2M-1, in the case of exits to E */
57 int scur, sprv;
58
59 /* we'll index M states as 1..M, and D states as 2..M = M+2..2M: M0, D1 are impossibles. */
60 ESL_ALLOC(sc, sizeof(float) * (2*M+1));
61
62 k = 0;
63 i = L;
64 if ((status = p7_trace_Append(tr, p7T_T, k, i)) != eslOK) goto ERROR;
65 if ((status = p7_trace_Append(tr, p7T_C, k, i)) != eslOK) goto ERROR;
66 sprv = p7T_C;
67 while (sprv != p7T_S)
68 {
69 switch (tr->st[tr->N-1]) {
70 /* C(i) comes from C(i-1) or E(i) */
71 case p7T_C:
72 if (XMX(i,p7G_C) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible C reached at i=%d", i);
73
74 sc[0] = XMX(i-1, p7G_C) + gm->xsc[p7P_C][p7P_LOOP];
75 sc[1] = XMX(i, p7G_E) + gm->xsc[p7P_E][p7P_MOVE];
76 esl_vec_FLogNorm(sc, 2);
77 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_C : p7T_E;
78 break;
79
80 /* E connects from any M or D state. k set here */
81 case p7T_E:
82 if (XMX(i, p7G_E) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible E reached at i=%d", i);
83
84 if (p7_profile_IsLocal(gm)) { /* local models come from any M, D */
85 sc[0] = sc[M+1] = -eslINFINITY;
86 for (k = 1; k <= M; k++) sc[k] = MMX(i,k);
87 for (k = 2; k <= M; k++) sc[k+M] = DMX(i,k);
88 esl_vec_FLogNorm(sc, 2*M+1); /* now sc is a prob vector */
89 k = esl_rnd_FChoose(r, sc, 2*M+1);
90 if (k <= M) scur = p7T_M;
91 else { k -= M; scur = p7T_D; }
92 } else { /* glocal models come from M_M or D_M */
93 k = M;
94 sc[0] = MMX(i,M);
95 sc[1] = DMX(i,M);
96 esl_vec_FLogNorm(sc, 2); /* now sc is a prob vector */
97 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_M : p7T_D;
98 }
99 break;
100
101 /* M connects from {MDI} i-1,k-1, or B */
102 case p7T_M:
103 if (MMX(i,k) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible M reached at k=%d,i=%d", k,i);
104
105 sc[0] = XMX(i-1,p7G_B) + TSC(p7P_BM, k-1);
106 sc[1] = MMX(i-1,k-1) + TSC(p7P_MM, k-1);
107 sc[2] = IMX(i-1,k-1) + TSC(p7P_IM, k-1);
108 sc[3] = DMX(i-1,k-1) + TSC(p7P_DM, k-1);
109 esl_vec_FLogNorm(sc, 4);
110 switch (esl_rnd_FChoose(r, sc, 4)) {
111 case 0: scur = p7T_B; break;
112 case 1: scur = p7T_M; break;
113 case 2: scur = p7T_I; break;
114 case 3: scur = p7T_D; break;
115 }
116 k--;
117 i--;
118 break;
119
120 /* D connects from M,D at i,k-1 */
121 case p7T_D:
122 if (DMX(i, k) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible D reached at k=%d,i=%d", k,i);
123
124 sc[0] = MMX(i, k-1) + TSC(p7P_MD, k-1);
125 sc[1] = DMX(i, k-1) + TSC(p7P_DD, k-1);
126 esl_vec_FLogNorm(sc, 2);
127 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_M : p7T_D;
128 k--;
129 break;
130
131 /* I connects from M,I at i-1,k */
132 case p7T_I:
133 if (IMX(i,k) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible I reached at k=%d,i=%d", k,i);
134
135 sc[0] = MMX(i-1,k) + TSC(p7P_MI, k);
136 sc[1] = IMX(i-1,k) + TSC(p7P_II, k);
137 esl_vec_FLogNorm(sc, 2);
138 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_M : p7T_I;
139 i--;
140 break;
141
142 /* N connects from S, N */
143 case p7T_N:
144 if (XMX(i, p7G_N) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible N reached at i=%d", i);
145 scur = (i == 0) ? p7T_S : p7T_N;
146 break;
147
148 /* B connects from N, J */
149 case p7T_B:
150 if (XMX(i,p7G_B) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible B reached at i=%d", i);
151
152 sc[0] = XMX(i, p7G_N) + gm->xsc[p7P_N][p7P_MOVE];
153 sc[1] = XMX(i, p7G_J) + gm->xsc[p7P_J][p7P_MOVE];
154 esl_vec_FLogNorm(sc, 2);
155 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_N : p7T_J;
156 break;
157
158 /* J connects from E(i) or J(i-1) */
159 case p7T_J:
160 if (XMX(i,p7G_J) == -eslINFINITY) ESL_XEXCEPTION(eslFAIL, "impossible J reached at i=%d", i);
161
162 sc[0] = XMX(i-1,p7G_J) + gm->xsc[p7P_J][p7P_LOOP];
163 sc[1] = XMX(i, p7G_E) + gm->xsc[p7P_E][p7P_LOOP];
164 esl_vec_FLogNorm(sc, 2);
165 scur = (esl_rnd_FChoose(r, sc, 2) == 0) ? p7T_J : p7T_E;
166 break;
167
168 default: ESL_XEXCEPTION(eslFAIL, "bogus state in traceback");
169 } /* end switch over statetype[tpos-1] */
170
171 /* Append this state and the current i,k to be explained to the growing trace */
172 if ((status = p7_trace_Append(tr, scur, k, i)) != eslOK) goto ERROR;
173
174 /* For NCJ, we had to defer i decrement. */
175 if ( (scur == p7T_N || scur == p7T_J || scur == p7T_C) && scur == sprv) i--;
176
177 sprv = scur;
178 } /* end traceback, at S state */
179
180 if ((status = p7_trace_Reverse(tr)) != eslOK) goto ERROR;
181 tr->M = gm->M;
182 tr->L = L;
183 free(sc);
184 return eslOK;
185
186 ERROR:
187 if (sc != NULL) free(sc);
188 return status;
189 }
190 /*------------------- end, stochastic trace ---------------------*/
191
192
193
194
195
196 /*****************************************************************
197 * 2. Benchmark driver
198 *****************************************************************/
199 #ifdef p7GENERIC_STOTRACE_BENCHMARK
200 /*
201 gcc -g -O2 -o generic_stotrace_benchmark -I. -L. -I../easel -L../easel -Dp7GENERIC_STOTRACE_BENCHMARK generic_stotrace.c -lhmmer -leasel -lm
202 icc -O3 -static -o generic_stotrace_benchmark -I. -L. -I../easel -L../easel -Dp7GENERIC_STOTRACE_BENCHMARK generic_stotrace.c -lhmmer -leasel -lm
203 ./generic_stotrace_benchmark <hmmfile>
204 */
205 #include <p7_config.h>
206
207 #include "easel.h"
208 #include "esl_alphabet.h"
209 #include "esl_getopts.h"
210 #include "esl_random.h"
211 #include "esl_randomseq.h"
212 #include "esl_stopwatch.h"
213
214 #include "hmmer.h"
215
216 static ESL_OPTIONS options[] = {
217 /* name type default env range toggles reqs incomp help docgroup*/
218 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
219 { "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
220 { "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seq" , 0 },
221 { "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of sampled tracebacks", 0 },
222 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
223 };
224 static char usage[] = "[-options] <hmmfile>";
225 static char banner[] = "benchmark driver for generic stochastic trace";
226
227 int
228 main(int argc, char **argv)
229 {
230 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage);
231 char *hmmfile = esl_opt_GetArg(go, 1);
232 ESL_STOPWATCH *w = esl_stopwatch_Create();
233 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
234 ESL_ALPHABET *abc = NULL;
235 P7_HMMFILE *hfp = NULL;
236 P7_HMM *hmm = NULL;
237 P7_BG *bg = NULL;
238 P7_PROFILE *gm = NULL;
239 P7_GMX *fwd = NULL;
240 P7_TRACE *tr = NULL;
241 int L = esl_opt_GetInteger(go, "-L");
242 int N = esl_opt_GetInteger(go, "-N");
243 ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2));
244 int i;
245 float sc, fsc, vsc;
246 float bestsc = -eslINFINITY;
247
248 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
249 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
250
251 bg = p7_bg_Create(abc);
252 p7_bg_SetLength(bg, L);
253 gm = p7_profile_Create(hmm->M, abc);
254 p7_ProfileConfig(hmm, bg, gm, L, p7_UNILOCAL);
255 fwd = p7_gmx_Create(gm->M, L);
256 tr = p7_trace_Create();
257 esl_rsq_xfIID(r, bg->f, abc->K, L, dsq);
258
259 p7_GViterbi(dsq, L, gm, fwd, &vsc);
260 p7_GForward(dsq, L, gm, fwd, &fsc);
261
262 esl_stopwatch_Start(w);
263 for (i = 0; i < N; i++)
264 {
265 p7_GStochasticTrace(r, dsq, L, gm, fwd, tr);
266 p7_trace_Score(tr, dsq, gm, &sc); /* this doesn't add significantly to benchmark time */
267 bestsc = ESL_MAX(bestsc, sc);
268 p7_trace_Reuse(tr);
269 }
270 esl_stopwatch_Stop(w);
271 esl_stopwatch_Display(stdout, w, "# CPU time: ");
272
273 printf("forward sc = %.4f nats\n", fsc);
274 printf("viterbi sc = %.4f nats\n", vsc);
275 printf("max trace sc = %.4f nats\n", bestsc);
276
277 free(dsq);
278 p7_trace_Destroy(tr);
279 p7_gmx_Destroy(fwd);
280 p7_profile_Destroy(gm);
281 p7_bg_Destroy(bg);
282 p7_hmm_Destroy(hmm);
283 p7_hmmfile_Close(hfp);
284 esl_alphabet_Destroy(abc);
285 esl_stopwatch_Destroy(w);
286 esl_randomness_Destroy(r);
287 esl_getopts_Destroy(go);
288 return 0;
289 }
290 #endif /*p7GENERIC_STOTRACE_BENCHMARK*/
291 /*---------------------- end, benchmark -------------------------*/
292
293
294
295
296 /*****************************************************************
297 * 3. Unit tests
298 *****************************************************************/
299 #ifdef p7GENERIC_STOTRACE_TESTDRIVE
300 #include "esl_getopts.h"
301 /* fairly weak tests: each sampled trace must be <= viterbi trace score, and must pass validation */
302 static void
303 utest_stotrace(ESL_GETOPTS *go, ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_PROFILE *gm, ESL_DSQ *dsq, int L, int ntrace)
304 {
305 P7_GMX *gx = NULL;
306 P7_TRACE *tr = NULL;
307 char errbuf[eslERRBUFSIZE];
308 int idx;
309 float maxsc = -eslINFINITY;
310 float vsc, sc;
311
312 if ((gx = p7_gmx_Create(gm->M, L)) == NULL) esl_fatal("matrix creation failed");
313 if ((tr = p7_trace_Create()) == NULL) esl_fatal("trace creation failed");
314
315 if (p7_GViterbi(dsq, L, gm, gx, &vsc) != eslOK) esl_fatal("viterbi failed");
316 if (p7_GForward(dsq, L, gm, gx, NULL) != eslOK) esl_fatal("forward failed");
317
318 for (idx = 0; idx < ntrace; idx++)
319 {
320 if (p7_GStochasticTrace(r, dsq, L, gm, gx, tr) != eslOK) esl_fatal("stochastic trace failed");
321 if (p7_trace_Validate(tr, abc, dsq, errbuf) != eslOK) esl_fatal("trace invalid:\n%s", errbuf);
322 if (p7_trace_Score(tr, dsq, gm, &sc) != eslOK) esl_fatal("trace scoring failed");
323
324 maxsc = ESL_MAX(sc, maxsc);
325 if (sc > vsc) esl_fatal("sampled trace has score > optimal Viterbi path; not possible");
326 p7_trace_Reuse(tr);
327 }
328 if (esl_FCompare_old(maxsc, vsc, 0.001) != eslOK) esl_fatal("stochastic trace failed to sample the Viterbi path");
329
330 p7_trace_Destroy(tr);
331 p7_gmx_Destroy(gx);
332 }
333 #endif /*p7GENERIC_STOTRACE_TESTDRIVE*/
334 /*--------------------- end, unit tests -------------------------*/
335
336
337
338
339
340 /*****************************************************************
341 * 4. Test driver
342 *****************************************************************/
343 #ifdef p7GENERIC_STOTRACE_TESTDRIVE
344 /* gcc -g -Wall -Dp7GENERIC_STOTRACE_TESTDRIVE -I. -I../easel -L. -L../easel -o generic_stotrace_utest generic_stotrace.c -lhmmer -leasel -lm
345 */
346 #include "easel.h"
347 #include "esl_getopts.h"
348 #include "esl_randomseq.h"
349
350 #include <p7_config.h>
351 #include "hmmer.h"
352
353 static ESL_OPTIONS options[] = {
354 /* name type default env range toggles reqs incomp help docgroup*/
355 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
356 { "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
357 { "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "be verbose", 0 },
358 { "--vv", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "be very verbose", 0 },
359 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
360 };
361 static char usage[] = "[-options]";
362 static char banner[] = "unit test driver for stochastic Viterbi traceback (generic version)";
363
364 int
365 main(int argc, char **argv)
366 {
367 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage);
368 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
369 ESL_ALPHABET *abc = NULL;
370 P7_HMM *hmm = NULL;
371 P7_PROFILE *gm = NULL;
372 P7_BG *bg = NULL;
373 ESL_DSQ *dsq = NULL;
374 ESL_SQ *sq = NULL;
375 int M = 5;
376 int L = 10;
377 int ntrace = 1000;
378
379 if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet");
380 if (p7_hmm_Sample(r, M, abc, &hmm) != eslOK) esl_fatal("failed to sample an HMM");
381 if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model");
382 if ((gm = p7_profile_Create(hmm->M, abc)) == NULL) esl_fatal("failed to create profile");
383 if (p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL) != eslOK) esl_fatal("failed to config profile");
384
385 /* Test with randomly generated (iid) sequence */
386 if ((dsq = malloc(sizeof(ESL_DSQ) *(L+2))) == NULL) esl_fatal("malloc failed");
387 if (esl_rsq_xfIID(r, bg->f, abc->K, L, dsq) != eslOK) esl_fatal("seq generation failed");
388 utest_stotrace(go, r, abc, gm, dsq, L, ntrace);
389
390 /* Test with seq sampled from profile */
391 if ((sq = esl_sq_CreateDigital(abc)) == NULL) esl_fatal("sequence allocation failed");
392 if (p7_ProfileEmit(r, hmm, gm, bg, sq, NULL) != eslOK) esl_fatal("profile emission failed");
393 utest_stotrace(go, r, abc, gm, sq->dsq, sq->n, ntrace);
394
395 esl_sq_Destroy(sq);
396 free(dsq);
397 p7_profile_Destroy(gm);
398 p7_bg_Destroy(bg);
399 p7_hmm_Destroy(hmm);
400 esl_alphabet_Destroy(abc);
401 esl_randomness_Destroy(r);
402 esl_getopts_Destroy(go);
403 return 0;
404 }
405 #endif /*p7GENERIC_STOTRACE_TESTDRIVE*/
406 /*-------------------- end, test driver -------------------------*/
407
408
409
410
411
412 /*****************************************************************
413 * 5. Example
414 *****************************************************************/
415 #ifdef p7GENERIC_STOTRACE_EXAMPLE
416 /*
417 gcc -g -Dp7GENERIC_STOTRACE_EXAMPLE -I. -I../easel -L. -L../easel -o generic_stotrace_example generic_stotrace.c -lhmmer -leasel -lm
418 */
419 #include <p7_config.h>
420
421 #include "easel.h"
422 #include "esl_alphabet.h"
423 #include "esl_getopts.h"
424 #include "esl_random.h"
425 #include "esl_sq.h"
426 #include "esl_sqio.h"
427
428 #include "hmmer.h"
429
430 static ESL_OPTIONS options[] = {
431 /* name type default env range toggles reqs incomp help docgroup*/
432 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
433 { "-m", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump the DP matrix to stdout", 0 },
434 { "-s", eslARG_INT, "0", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 },
435 { "-t", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump the sampled trace to stdout", 0 },
436 { "-N", eslARG_INT, "1", NULL, NULL, NULL, NULL, NULL, "number of traces to sample", 0 },
437 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
438 };
439 static char usage[] = "[-options] <hmmfile> <seqfile>";
440 static char banner[] = "example of stochastic backtrace";
441
442 int
443 main(int argc, char **argv)
444 {
445 ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage);
446 ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s"));
447 char *hmmfile = esl_opt_GetArg(go, 1);
448 char *seqfile = esl_opt_GetArg(go, 2);
449 ESL_ALPHABET *abc = NULL;
450 P7_HMMFILE *hfp = NULL;
451 P7_HMM *hmm = NULL;
452 P7_BG *bg = NULL;
453 P7_PROFILE *gm = NULL;
454 P7_GMX *fwd = NULL;
455 P7_TRACE *tr = NULL;
456 ESL_SQ *sq = NULL;
457 ESL_SQFILE *sqfp = NULL;
458 int format = eslSQFILE_UNKNOWN;
459 char errbuf[eslERRBUFSIZE];
460 int N = esl_opt_GetInteger(go, "-N");
461 int i;
462 float vsc, fsc, tsc;
463 int status;
464
465 /* Read in one HMM */
466 if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile);
467 if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM");
468 p7_hmmfile_Close(hfp);
469
470 /* Read in one sequence */
471 sq = esl_sq_CreateDigital(abc);
472 status = esl_sqfile_Open(seqfile, format, NULL, &sqfp);
473 if (status == eslENOTFOUND) p7_Fail("No such file.");
474 else if (status == eslEFORMAT) p7_Fail("Format unrecognized.");
475 else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz.");
476 else if (status != eslOK) p7_Fail("Open failed, code %d.", status);
477 if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence");
478 esl_sqfile_Close(sqfp);
479
480 /* Configure a profile from the HMM */
481 bg = p7_bg_Create(abc);
482 p7_bg_SetLength(bg, sq->n);
483 gm = p7_profile_Create(hmm->M, abc);
484 p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL);
485
486 fwd = p7_gmx_Create(gm->M, sq->n);
487 tr = p7_trace_Create();
488
489 p7_GViterbi(sq->dsq, sq->n, gm, fwd, &vsc);
490 p7_GForward(sq->dsq, sq->n, gm, fwd, &fsc);
491 if (esl_opt_GetBoolean(go, "-m") == TRUE) p7_gmx_Dump(stdout, fwd, p7_DEFAULT);
492
493 for (i = 0; i < N; i++)
494 {
495 p7_GStochasticTrace(r, sq->dsq, sq->n, gm, fwd, tr);
496 p7_trace_Score(tr, sq->dsq, gm, &tsc);
497
498 if (esl_opt_GetBoolean(go, "-t") == TRUE) p7_trace_Dump(stdout, tr, gm, sq->dsq);
499 if (p7_trace_Validate(tr, abc, sq->dsq, errbuf) != eslOK) esl_fatal("trace failed validation: %s\n", errbuf);
500
501 printf("Sampled trace: %.4f nats\n", tsc);
502 p7_trace_Reuse(tr);
503 }
504 printf("Forward score: %.4f nats\n", fsc);
505 printf("Viterbi score: %.4f nats\n", vsc);
506
507
508 /* Cleanup */
509 p7_gmx_Destroy(fwd);
510 p7_trace_Destroy(tr);
511 p7_profile_Destroy(gm);
512 p7_bg_Destroy(bg);
513 p7_hmm_Destroy(hmm);
514 esl_alphabet_Destroy(abc);
515 esl_getopts_Destroy(go);
516 return 0;
517 }
518 #endif /*p7GENERIC_STOTRACE_EXAMPLE*/
519 /*----------------------- end, example --------------------------*/
520
521