Debian Codegraph @

src/impl_sse/cm_optimized.c

raw symbols SCIP
1 #include "easel.h"
2 #include "esl_alphabet.h"
3 #include "esl_hmm.h"
4 #include "esl_stack.h"
5 #include "esl_vectorops.h"
6
7 #include "hmmer.h"
8
9 #include "infernal.h"
10
11 #include "impl_sse.h"
12
13 #define SCALE_W 500.0 /* set a default scaling factor for 16-bit int scores */
14
15 /* External API
16 * int cm_optimized_Convert(const CM_t *cm, CM_OPTIMIZED *ocm);
17 * void cm_optimized_Free(CM_OPTIMIZED *ocm);
18 * int16_t wordify(float scale_w, float sc);
19 */
20
21 /* Internal funcs */
22
23 /* Fuction: cm_optimized_Convert()
24 * Author: DLK, Tue May 05 2009
25 */
26 CM_OPTIMIZED*
27 cm_optimized_Convert(const CM_t *cm)
28 {
29 int status;
30 int v, y, yoffset;
31 int npairs = 0;
32 int nsinglets = 0;
33 int16_t *oesc_start;
34 int cur_cell;
35 CM_OPTIMIZED *ocm;
36
37 ESL_ALLOC(ocm, sizeof(CM_OPTIMIZED));
38
39 /* Copy basic information */
40 ocm->M = cm->M;
41 ocm->sttype = cm->sttype; /* careful, these point at the external resource */
42 ocm->cfirst = cm->cfirst;
43 ocm->cnum = cm->cnum;
44 ocm->plast = cm->plast;
45 ocm->pnum = cm->pnum;
46 ocm->abc = cm->abc;
47
48 /* count pairs, singlets */
49 for(v = 0; v < cm->M; v++) {
50 switch(ocm->sttype[v]) {
51 case IL_st:
52 case ML_st:
53 case IR_st:
54 case MR_st:
55 nsinglets++;
56 break;
57 case MP_st:
58 npairs++;
59 break;
60 }
61 }
62
63 /* Allocate memory */
64 ESL_ALLOC(ocm->tsc, sizeof(int16_t *) * ocm->M);
65 ESL_ALLOC(ocm->oesc, sizeof(int16_t *) * ocm->M);
66 ESL_ALLOC(ocm->beginsc, sizeof(int16_t ) * ocm->M);
67 ESL_ALLOC(ocm->endsc, sizeof(int16_t ) * ocm->M);
68
69 ESL_ALLOC(ocm->tsc[0], sizeof(int16_t ) * ocm->M * MAXCONNECT);
70 ESL_ALLOC(oesc_start, sizeof(int16_t ) * (nsinglets * ocm->abc->Kp + npairs * ocm->abc->Kp * ocm->abc->Kp));
71 for (v = 1; v<ocm->M; v++) {
72 //ocm->tsc[v] = ocm->tsc[v-1] + sizeof(int16_t) * MAXCONNECT;
73 ocm->tsc[v] = ocm->tsc[v-1] + MAXCONNECT;
74 }
75 cur_cell = 0;
76 for (v = 0; v<ocm->M; v++) {
77 switch(ocm->sttype[v]) {
78 case ML_st:
79 case IL_st:
80 case MR_st:
81 case IR_st:
82 ocm->oesc[v] = oesc_start + cur_cell;
83 cur_cell += ocm->abc->Kp;
84 break;
85 case MP_st:
86 ocm->oesc[v] = oesc_start + cur_cell;
87 cur_cell += ocm->abc->Kp * ocm->abc->Kp;
88 break;
89 default:
90 ocm->oesc[v] = NULL;
91 break;
92 }
93 }
94
95 /* Scale score values */
96 ocm->scale_w = SCALE_W;
97 for (v = 0; v<ocm->M; v++) {
98 if (ocm->sttype[v] == B_st) {
99 for (yoffset = 0; yoffset < MAXCONNECT; yoffset++) {
100 ocm->tsc[v][yoffset] = wordify(ocm->scale_w, -eslINFINITY);
101 }
102 }
103 else {
104 for (yoffset = 0; yoffset < ocm->cnum[v]; yoffset++) {
105 ocm->tsc[v][yoffset] = wordify(ocm->scale_w, cm->tsc[v][yoffset]);
106 }
107 for ( ; yoffset < MAXCONNECT; yoffset++) {
108 ocm->tsc[v][yoffset] = wordify(ocm->scale_w, -eslINFINITY);
109 }
110 }
111
112 if (ocm->sttype[v] == MP_st) {
113 for (y = 0; y < (ocm->abc->Kp * ocm->abc->Kp); y++) {
114 ocm->oesc[v][y] = wordify(ocm->scale_w, cm->oesc[v][y]);
115 }
116 }
117 else if (ocm->sttype[v] == ML_st || ocm->sttype[v] == IL_st ||
118 ocm->sttype[v] == MR_st || ocm->sttype[v] == IR_st ) {
119 for (y = 0; y < ocm->abc->Kp; y++) {
120 ocm->oesc[v][y] = wordify(ocm->scale_w, cm->oesc[v][y]);
121 }
122 }
123
124 ocm->beginsc[v] = wordify(ocm->scale_w, cm->beginsc[v]);
125 if (v == 0) { ocm->beginsc[v] = 0x0000; }
126 ocm->endsc[v] = wordify(ocm->scale_w, cm->endsc[v]);
127 }
128 ocm->el_selfsc = wordify(ocm->scale_w, cm->el_selfsc);
129
130 return ocm;
131
132 ERROR:
133 cm_Fail("Memory allocation error.\n");
134 return NULL; /* never reached */
135 }
136
137 /* Function: cm_optimized_Free()
138 * Author: DLK, Tue May 05 2009
139 */
140 void
141 cm_optimized_Free(CM_OPTIMIZED *ocm)
142 {
143 int v = 0;
144
145 if (ocm->tsc[0] != NULL) free(ocm->tsc[0]);
146 while (ocm->oesc[v] == NULL && v < ocm->M) { v++; }
147 if (ocm->oesc[v] != NULL) free(ocm->oesc[v]);
148
149 if (ocm->endsc != NULL) free(ocm->endsc);
150 if (ocm->beginsc != NULL) free(ocm->beginsc);
151 if (ocm->oesc != NULL) free(ocm->oesc);
152 if (ocm->tsc != NULL) free(ocm->tsc);
153
154 return;
155 }
156
157 /* Fuction: cm_consensus_Convert()
158 * Author: DLK, Thu May 14 2009
159 */
160 CM_CONSENSUS*
161 cm_consensus_Convert(CM_t *cm)
162 {
163 int status;
164 int v, w, x, y, z;
165 int offset;
166 int pairs, singlets;
167 int nstates, nfrags, total_frags;
168 int rec_frags, tot_rec_frags; /* Recursive fragments (those not ending in E_st */
169 int ebases, q;
170 float **exp_res = NULL;
171 uint8_t *oesc_next;
172 float max = 0.0;
173 CM_CONSENSUS *ccm = NULL;
174
175 ESL_STACK *oldstate;
176 ESL_STACK *newstate;
177
178 oldstate = esl_stack_ICreate();
179 newstate = esl_stack_ICreate();
180
181 ESL_ALLOC(ccm, sizeof(CM_CONSENSUS));
182
183 /* Set alphabet */
184 if (cm->abc->type == eslNONSTANDARD) { cm_Fail("Failed to handle nonstandard alphabet\n"); }
185 ccm->abc = esl_alphabet_Create(cm->abc->type);
186 ESL_ALLOC(ccm->mcompo, sizeof(float) * ccm->abc->K);
187 esl_vec_FSet(ccm->mcompo, ccm->abc->K, 0.);
188 ESL_ALLOC(ccm->fcompo, sizeof(float) * ccm->abc->K);
189 esl_vec_FSet(ccm->fcompo, ccm->abc->K, 0.);
190
191 /* Set initial background */
192 ccm->bg = ccm_bg_CreateUniform(ccm);
193
194 /* Set number of consensus states */
195 pairs = CMCountNodetype(cm, MATP_nd);
196 singlets= CMCountNodetype(cm, MATL_nd) + CMCountNodetype(cm, MATR_nd);
197 /*
198 pairs = CMCountStatetype(cm, MP_st);
199 singlets= CMCountStatetype(cm, ML_st) + CMCountStatetype(cm, MR_st);
200 */
201 /*
202 ccm->M = 0;
203 ccm->M += CMCountStatetype(cm, MP_st);
204 ccm->M += CMCountStatetype(cm, ML_st);
205 ccm->M += CMCountStatetype(cm, MR_st);
206 */
207 ccm->M = pairs + singlets;
208 ccm->M += CMCountStatetype(cm, S_st);
209 ccm->M += CMCountStatetype(cm, B_st);
210 ccm->M += CMCountStatetype(cm, E_st);
211
212 //FIXME - taking these defaults directly from HMMER - need to be checked!!!
213 for (v = 0; v < cm->M; v++) {
214 switch(cm->sttype[v]) {
215 case ML_st:
216 case MR_st:
217 max = ESL_MAX(max, esl_vec_FMax(cm->oesc[v], cm->abc->Kp));
218 break;
219 case MP_st:
220 max = ESL_MAX(max, esl_vec_FMax(cm->oesc[v], cm->abc->Kp*cm->abc->Kp));
221 break;
222 default:
223 break;
224 }
225 }
226 ccm->scale_b = 3.0 / eslCONST_LOG2;
227 ccm->base_b = 195;
228 ccm->bias_b = -1 * unbiased_byteify(ccm, max);
229
230 ESL_ALLOC(exp_res, sizeof(float *) * ccm->M);
231 ESL_ALLOC(exp_res[0], sizeof(float) * ccm->M * ccm->abc->K);
232 for (x = 1; x < ccm->M; x++) {
233 exp_res[x] = exp_res[0] + x*ccm->abc->K;
234 }
235
236 /* Set state connection */
237 ESL_ALLOC(ccm->next, sizeof(int ) * ccm->M);
238 ESL_ALLOC(ccm->sttype, sizeof(char) * ccm->M);
239 x = v = 0;
240
241 /* Setup emissions */
242 ESL_ALLOC(ccm->oesc, sizeof(uint8_t *) * ccm->M);
243 ESL_ALLOC(ccm->oesc[0], sizeof(uint8_t ) * (singlets * ccm->abc->Kp + pairs * ccm->abc->Kp * ccm->abc->Kp));
244 oesc_next = ccm->oesc[0];
245
246 nstates = nfrags = total_frags = 0;
247 rec_frags = tot_rec_frags = 0;
248 ebases = 0;
249 while (v != -1) {
250 ccm->sttype[x] = cm->sttype[v];
251 if (cm->sttype[v] == E_st) {
252 ccm->next[x] = -1;
253 ccm->oesc[x] = NULL;
254
255 esl_vec_FSet(exp_res[x], ccm->abc->K, 0.);
256
257 rec_frags = nstates*(nstates+1)/2;
258 tot_rec_frags += rec_frags;
259 nstates++; /* Part of modified E-state treatment, add E to state count */
260 nfrags = nstates*(nstates+1)/2;
261 nfrags--; /* Part of modified E-state treatment, subtract E-E fragment (not allowed) */
262 total_frags += nfrags;
263 for (q = 0; q < nstates; q++) {
264 /* Part of modified E-state treatment, old loop was q=1 to q <= nstates
265 although nstates was one smaller and thus stopped at the same range */
266 ebases += q*(nstates-q+1)*StateDelta(ccm->sttype[x-q]);
267 esl_vec_FAddScaled(ccm->mcompo, exp_res[x-q], q*(nstates-q-1), ccm->abc->K);
268 }
269 nstates = 0;
270
271 /* pop next x and v off stack */
272 if (esl_stack_IPop(oldstate, &v) == eslEOD) { v = -1; }
273 if (esl_stack_IPop(newstate, &x) == eslEOD) { x = -1; }
274 }
275 else if (cm->sttype[v] == B_st) {
276 w = cm->cfirst[v];
277 y = cm->cnum[v];
278
279 offset = CMSubtreeCountStatetype(cm, w, MP_st);
280 offset += CMSubtreeCountNodetype(cm, w, MATL_ML);
281 offset += CMSubtreeCountNodetype(cm, w, MATR_MR);
282 offset += CMSubtreeCountStatetype(cm, w, S_st);
283 offset += CMSubtreeCountStatetype(cm, w, B_st);
284 offset += CMSubtreeCountStatetype(cm, w, E_st);
285
286 ccm->next[x] = x+offset+1;
287 ccm->oesc[x] = NULL;
288
289 esl_vec_FSet(exp_res[x], ccm->abc->K, 0.);
290
291 nfrags = nstates*(nstates+1)/2;
292 total_frags += nfrags;
293 tot_rec_frags += nfrags;
294 for (q = 1; q <= nstates; q++) {
295 ebases += q*(nstates-q+1)*StateDelta(ccm->sttype[x-q]);
296 esl_vec_FAddScaled(ccm->mcompo, exp_res[x-q], q*(nstates-q-1), ccm->abc->K);
297 }
298 nstates = 0;
299
300 /* push y and x+offset on stacks */
301 esl_stack_IPush(oldstate, y);
302 esl_stack_IPush(newstate, x+offset+1);
303
304 x++;
305 v = w;
306 }
307 else {
308 y = cm->cfirst[v];
309
310 while (y<cm->M && (cm->sttype[y] == D_st || cm->sttype[y] == IL_st || cm->sttype[y] == IR_st || cm->stid[y] == MATP_ML || cm->stid[y] == MATP_MR)) { y++; }
311 //if (y == cm->M) y = -1;
312
313 ccm->next[x] = x+1;
314 ccm->oesc[x] = oesc_next;
315 if (cm->sttype[v] == MP_st) {
316 nstates++;
317 for (z = 0; z < (ccm->abc->Kp * ccm->abc->Kp); z++) {
318 ccm->oesc[x][z] = biased_byteify(ccm, cm->oesc[v][z]);
319 }
320 oesc_next += ccm->abc->Kp * ccm->abc->Kp;
321
322 esl_vec_FSet(exp_res[x], ccm->abc->K, 0.);
323 for (z = 0; z < ccm->abc->K; z++) {
324 esl_vec_FAdd(exp_res[x], &(cm->e[v][z*ccm->abc->K]), ccm->abc->K);
325 exp_res[x][z] += esl_vec_FSum(&(cm->e[v][z*ccm->abc->K]), ccm->abc->K);
326 }
327 }
328 else if (cm->stid[v] == MATL_ML || cm->stid[v] == MATR_MR) {
329 nstates++;
330 for (z = 0; z < ccm->abc->Kp; z++) {
331 ccm->oesc[x][z] = biased_byteify(ccm, cm->oesc[v][z]);
332 }
333 oesc_next += ccm->abc->Kp;
334
335 esl_vec_FCopy(cm->e[v], ccm->abc->K, exp_res[x]);
336 }
337 x++;
338 v = y;
339 }
340
341 }
342
343 esl_vec_FNorm(ccm->mcompo,ccm->abc->K);
344
345 ccm->p_rfrag = ((float) tot_rec_frags)/total_frags;
346 ccm->sc_frag = sreLOG2(1./total_frags);
347 ccm->e_fraglen = ((float) ebases)/total_frags;
348
349 esl_stack_Destroy(oldstate);
350 esl_stack_Destroy(newstate);
351 free(exp_res[0]);
352 free(exp_res);
353
354 return ccm;
355
356 ERROR:
357 cm_Fail("Memory allocation error.\n");
358 return NULL;
359 }
360
361 /* Function: cm_consensus_Free()
362 Author: DLK, Thu May 14 2009
363 */
364 void
365 cm_consensus_Free(CM_CONSENSUS *ccm)
366 {
367 if (ccm->next != NULL) free(ccm->next);
368 if (ccm->sttype != NULL) free(ccm->sttype);
369 if (ccm->oesc[0] != NULL) free(ccm->oesc[0]);
370 if (ccm->oesc != NULL) free(ccm->oesc);
371 if (ccm->bg != NULL) ccm_bg_Destroy(ccm->bg);
372 if (ccm->mcompo != NULL) free(ccm->mcompo);
373 if (ccm->fcompo != NULL) free(ccm->fcompo);
374
375 esl_alphabet_Destroy(ccm->abc);
376
377 free(ccm); ccm = NULL;
378
379 return;
380 }
381
382 /* Function: MSCYK_explen()
383 Author: DLK
384
385 Purpose: Calculate the expected lenght of hits under the MSCYK model,
386 given a particular (consensus) CM
387
388 Args: fraglen - expected length of hits in consensus CM (usually ccm->e_fraglen)
389 t1 - probability of S->Sa transition
390 t2 - probability of S->SM transition
391 t3 - probability of S->null transition
392 */
393 float
394 ccm_explen(CM_CONSENSUS *ccm, float t1, float t2, float t3)
395 {
396 float elen;
397
398 elen = (t1+ccm->e_fraglen*t2)/(t3-ccm->p_rfrag*t2); /* Reference NBpg63, 24 Nov 2009 */
399
400 if (elen < 0) {
401 fprintf(stderr,"Warning: non-terminating grammar parameters. Expected hit length infinite\n");
402 elen = eslINFINITY;
403 }
404
405 return elen;
406 }
407
408 /* biased_byteify()
409 * Converts original log-odds residue score to a rounded biased uchar cost.
410 * e.g. a score of +3.2, with scale 3.0 and bias 12, becomes 2.
411 * 3.2*3 = 9.6; rounded = 10; bias-10 = 2.
412 * When used, we add the bias, then subtract this cost.
413 * (A cost of +255 is our -infinity "prohibited event")
414 */
415 uint8_t
416 biased_byteify(CM_CONSENSUS *ccm, float sc)
417 {
418 uint8_t b;
419
420 sc = -1.0f * roundf(ccm->scale_b * sc); /* ugh. sc is now an integer cost represented in a float...
421 */
422 b = (sc > 255 - ccm->bias_b) ? 255 : (uint8_t) sc + ccm->bias_b; /* and now we cast, saturate, and bias it to an unsigned char cost
423 ... */
424 return b;
425 }
426
427 /* unbiased_byteify()
428 * Convert original transition score to a rounded uchar cost
429 * e.g. a score of -2.1, with scale 3.0, becomes a cost of 6.
430 * (A cost of +255 is our -infinity "prohibited event")
431 */
432 uint8_t
433 unbiased_byteify(CM_CONSENSUS *ccm, float sc)
434 {
435 uint8_t b;
436
437 sc = -1.0f * roundf(ccm->scale_b * sc); /* ugh. sc is now an integer cost represented in a float... */
438 b = (sc > 255.) ? 255 : (uint8_t) sc; /* and now we cast and saturate it to an unsigned char cost... */
439 return b;
440 }
441
442 /*****************************************************************
443 * Filter null model
444 *****************************************************************/
445
446 /* Function: cm_SetCompo()
447 * Synposis: Set full MSCYK model composition
448 *
449 * Purpose: Given meta-model parameters, and assuming ccm->mcompo
450 * is already set with match-only composition, determine
451 * weighting of aligned to unaligned positions, and
452 * calculate appropriate weighted average for ccm->fcompo
453 *
454 * Returns: <eslOK> on success
455 */
456
457 int
458 ccm_SetCompo(CM_CONSENSUS *ccm, float f_S_Sa, float f_S_SM, float f_S_e)
459 {
460 float n_aligned, p_aligned;
461
462 n_aligned = f_S_SM * ccm->e_fraglen / (f_S_e - ccm->p_rfrag * f_S_SM);
463 p_aligned = n_aligned / ccm_explen(ccm, f_S_Sa, f_S_SM, f_S_e);
464
465 esl_vec_FSet(ccm->fcompo, ccm->abc->K, 0.0);
466 esl_vec_FAddScaled(ccm->fcompo, ccm->mcompo, p_aligned, ccm->abc->K);
467 esl_vec_FAddScaled(ccm->fcompo, ccm->bg->f, 1.-p_aligned, ccm->abc->K);
468
469 return eslOK;
470 }
471
472 /* Function: ccm_bg_CreateUniform()
473 */
474 CCM_BG*
475 ccm_bg_CreateUniform(CM_CONSENSUS *ccm)
476 {
477 CCM_BG *bg = NULL;
478 int status;
479
480 ESL_ALLOC(bg, sizeof(CCM_BG));
481 bg->f = NULL;
482 bg->fhmm = NULL;
483
484 ESL_ALLOC(bg->f, sizeof(float) * ccm->abc->K);
485 if ((bg->fhmm = esl_hmm_Create(ccm->abc, 2)) == NULL) goto ERROR;
486
487 esl_vec_FSet(bg->f, ccm->abc->K, 1. / (float) ccm->abc->K);
488
489 return bg;
490
491 ERROR:
492 ccm_bg_Destroy(bg);
493 return NULL;
494 }
495
496 /* Function: ccm_bg_Destroy()
497 */
498 void
499 ccm_bg_Destroy(CCM_BG *bg)
500 {
501 if (bg != NULL) {
502 if (bg->f != NULL) free(bg->f);
503 if (bg->fhmm != NULL) esl_hmm_Destroy(bg->fhmm);
504 free(bg);
505 }
506 return;
507 }
508
509 /* Function: ccm_bg_NullOne()
510 */
511 int
512 ccm_bg_NullOne(const CCM_BG *bg, int L, float *ret_sc)
513 {
514 *ret_sc = (float) L * log(bg->p1) + log(1.-bg->p1);
515 return eslOK;
516 }
517
518 /* Function: cm_bg_SetFilter()
519 * Synopsis: Configure filter HMM with new model composition.
520 *
521 * NOTE: Very closely base on P7_bg_SetFilter from H3
522 *
523 * Purpose: The "filter HMM" is an experimental filter in the
524 * acceleration pipeline for avoiding biased composition
525 * sequences. It has no effect on final scoring, if a
526 * sequence passes all steps of the pipeline; it is only
527 * used to eliminate biased sequences from further
528 * consideration early in the pipeline, before the big guns
529 * of domain postprocessing are applied.
530 *
531 * At least at present, it doesn't actually work as well as
532 * one would hope. This will be an area of future work.
533 * What we really want to do is make a better null model of
534 * real protein sequences (and their biases), and incorporate
535 * that model into the flanks (NCJ states) of the profile.
536 *
537 * <compo> is the average model residue composition, from
538 * either the HMM or the copy in a profile or optimized
539 * profile. <M> is the length of the model in nodes.
540 *
541 * Returns: <eslOK> on success.
542 */
543 int
544 ccm_bg_SetFilter(CM_CONSENSUS *ccm, float mL, float sL)
545 {
546 float L0 = sL; /* mean length in state 0 of filter HMM (normal background) */
547 float L1 = mL / 2.0; /* mean length in state 1 of filter HMM (biased segment) */
548
549 /* State 0 is the normal iid model. */
550 ccm->bg->fhmm->t[0][0] = L0 / (L0+1.0f);
551 ccm->bg->fhmm->t[0][1] = 1.0f / (L0+1.0f);
552 ccm->bg->fhmm->t[0][2] = 1.0f; /* 1.0 transition to E means we'll set length distribution externally. */
553 esl_vec_FCopy(ccm->bg->f, ccm->abc->K, ccm->bg->fhmm->e[0]);
554
555 /* State 1 is the potentially biased model composition. */
556 ccm->bg->fhmm->t[1][0] = 1.0f / (L1+1.0f);
557 ccm->bg->fhmm->t[1][1] = L1 / (L1+1.0f);
558 ccm->bg->fhmm->t[1][2] = 1.0f; /* 1.0 transition to E means we'll set length distribution externally. */
559 esl_vec_FCopy(ccm->fcompo, ccm->abc->K, ccm->bg->fhmm->e[1]);
560
561 ccm->bg->fhmm->pi[0] = 0.999;
562 ccm->bg->fhmm->pi[1] = 0.001;
563
564 esl_hmm_Configure(ccm->bg->fhmm, ccm->bg->f);
565 return eslOK;
566 }
567
568 /* Function: cm_bg_FilterScore()
569 * Synopsis: Calculates the filter null model score.
570 *
571 * NOTE: Very closely base on p7_bg_FilterScore from H3
572 *
573 * Purpose: Calculates the filter null model <bg> score for sequence
574 * <dsq> of length <L>, and return it in
575 * <*ret_sc>.
576 *
577 * The score is calculated as an HMM Forward score using
578 * the two-state filter null model. It is a log-odds ratio,
579 * relative to the iid background frequencies, in nats:
580 * same as main model Forward scores.
581 *
582 * The filter null model has no length distribution of its
583 * own; the same geometric length distribution (controlled
584 * by <bg->p1>) that the null1 model uses is imposed.
585 */
586 int
587 ccm_bg_FilterScore(CCM_BG *bg, ESL_DSQ *dsq, int L, float *ret_sc)
588 {
589 ESL_HMX *hmx = esl_hmx_Create(L, bg->fhmm->M); /* optimization target: this can be a 2-row matrix, and it can be stored in <bg>. */
590 float nullsc; /* (or it could be passed in as an arg, but for sure it shouldn't be alloc'ed here */
591
592 esl_hmm_Forward(dsq, L, bg->fhmm, hmx, &nullsc);
593
594 /* impose the length distribution */
595 *ret_sc = nullsc + (float) L * logf(bg->p1) + logf(1.-bg->p1);
596 esl_hmx_Destroy(hmx);
597 return eslOK;
598 }