hmmer-3.3/src/p7_scoredata.c
/* Function:  p7_hmm_ScoreDataComputeRest()
 * Synopsis:  Using position-specific insert rates, compute MAXL-based prefix and suffix lengths
 *
 * Purpose:   Using position-specific insert rates, compute MAXL-based prefix
 *            and suffix lengths for each position in the model, used when
 *            establishing windows around SSV diagonals. This fleshes out
 *            the <P7_SCOREDATA> model object that was created by
 *            p7_hmmScoreDataCreate().
 *
 *            This approach of computing the prefix/suffix length, used
 *            in establishing windows around a seed diagonal, is fast
 *            because it uses a simple closed-form computation of the
 *            length L_i for each position i at which all but
 *            (1-p7_DEFAULT_WINDOW_BETA) of position i's match- and
 *            insert-state emissions are length L_i or shorter.
 *
 * Args:      om         - P7_OPROFILE containing emission/transition probabilities used to for calculations
 *            data       - P7_SCOREDATA into which the computed values are placed
 *
 * Returns:   eslEMEM on failure, else eslOK
 *
 * Throws:    <NULL> on allocation failure.
 */
p7_hmm_ScoreDataComputeRest()
Synopsis:  Using position-specific insert rates, compute MAXL-based prefix and suffix lengths

Using position-specific insert rates, compute MAXL-based prefix
and suffix lengths for each position in the model, used when
establishing windows around SSV diagonals. This fleshes out
the  model object that was created by
p7_hmmScoreDataCreate().

This approach of computing the prefix/suffix length, used
in establishing windows around a seed diagonal, is fast
because it uses a simple closed-form computation of the
length L_i for each position i at which all but
(1-p7_DEFAULT_WINDOW_BETA) of position i's match- and
insert-state emissions are length L_i or shorter.

om         - P7_OPROFILE containing emission/transition probabilities used to for calculations
data       - P7_SCOREDATA into which the computed values are placed

eslEMEM on failure, else eslOK

 on allocation failure.
p7_hmm_ScoreDataComputeRest () Synopsis : Using position - specific insert rates compute MAXL - based prefix and suffix lengths Using position - specific insert rates compute MAXL - based prefix and suffix lengths for each position in the model used when establishing windows around SSV diagonals . This fleshes out the model object that was created by p7_hmmScoreDataCreate () . This approach of computing the prefix / suffix length used in establishing windows around a seed diagonal is fast because it uses a simple closed - form computation of the length L_i for each position i at which all but ( 1 - p7_DEFAULT_WINDOW_BETA ) of position i ' s match - and insert - state emissions are length L_i or shorter . om - P7_OPROFILE containing emission / transition probabilities used to for calculations data - P7_SCOREDATA into which the computed values are placed eslEMEM on failure else eslOK on allocation failure .
int
p7_hmm_ScoreDataComputeRest(P7_OPROFILE *om, P7_SCOREDATA *data )
{
  int    status;
  int k;
  float sum;
  float *t_mis;
  float *t_iis;
  ESL_ALLOC(data->fwd_scores, sizeof(float) *  om->abc->Kp * (om->M+1));
  p7_oprofile_GetFwdEmissionScoreArray(om, data->fwd_scores);
  ESL_ALLOC(data->fwd_transitions, sizeof(float*) * p7O_NTRANS);
  for (k=0; k<p7O_NTRANS; k++) {
    ESL_ALLOC(data->fwd_transitions[k], sizeof(float) * (om->M+1));
    p7_oprofile_GetFwdTransitionArray(om, k, data->fwd_transitions[k] );
  }
  t_mis = data->fwd_transitions[p7O_MI];
  t_iis = data->fwd_transitions[p7O_II];
  ESL_ALLOC(data->prefix_lengths, (om->M+1) * sizeof(float));
  ESL_ALLOC(data->suffix_lengths, (om->M+1) * sizeof(float));
  sum = 0;
  for (k=1; k < om->M; k++) {
    if (t_mis[k] == 0)
      data->prefix_lengths[k] = 1;
    else
      data->prefix_lengths[k] = 1 + (int)(log(p7_DEFAULT_WINDOW_BETA / t_mis[k] )/log(t_iis[k]));
    sum += data->prefix_lengths[k];
  }
  data->prefix_lengths[0] = data->prefix_lengths[om->M] = 0;
  for (k=1; k < om->M; k++)
    data->prefix_lengths[k] /=  sum;
  data->suffix_lengths[om->M] = data->prefix_lengths[om->M-1];
  for (k=om->M - 1; k >= 1; k--)
    data->suffix_lengths[k] = data->suffix_lengths[k+1] + data->prefix_lengths[k-1];
  for (k=2; k < om->M; k++)
    data->prefix_lengths[k] += data->prefix_lengths[k-1];
  return eslOK;
  ERROR:
   p7_hmm_ScoreDataDestroy(data);
   return eslEMEM;
}
int p7_hmm_ScoreDataComputeRest ( P7_OPROFILE * om , P7_SCOREDATA * data ) { int status ; int k ; float sum ; float * t_mis ; float * t_iis ; ESL_ALLOC ( data -> fwd_scores , sizeof ( float ) * om -> abc -> Kp * ( om -> M + 1 ) ) ; p7_oprofile_GetFwdEmissionScoreArray ( om , data -> fwd_scores ) ; ESL_ALLOC ( data -> fwd_transitions , sizeof ( float * ) * p7O_NTRANS ) ; for ( k = 0 ; k < p7O_NTRANS ; k ++ ) { ESL_ALLOC ( data -> fwd_transitions [ k ] , sizeof ( float ) * ( om -> M + 1 ) ) ; p7_oprofile_GetFwdTransitionArray ( om , k , data -> fwd_transitions [ k ] ) ; } t_mis = data -> fwd_transitions [ p7O_MI ] ; t_iis = data -> fwd_transitions [ p7O_II ] ; ESL_ALLOC ( data -> prefix_lengths , ( om -> M + 1 ) * sizeof ( float ) ) ; ESL_ALLOC ( data -> suffix_lengths , ( om -> M + 1 ) * sizeof ( float ) ) ; sum = 0 ; for ( k = 1 ; k < om -> M ; k ++ ) { if ( t_mis [ k ] == 0 ) data -> prefix_lengths [ k ] = 1 ; else data -> prefix_lengths [ k ] = 1 + ( int ) ( log ( p7_DEFAULT_WINDOW_BETA / t_mis [ k ] ) / log ( t_iis [ k ] ) ) ; sum += data -> prefix_lengths [ k ] ; } data -> prefix_lengths [ 0 ] = data -> prefix_lengths [ om -> M ] = 0 ; for ( k = 1 ; k < om -> M ; k ++ ) data -> prefix_lengths [ k ] /= sum ; data -> suffix_lengths [ om -> M ] = data -> prefix_lengths [ om -> M - 1 ] ; for ( k = om -> M - 1 ; k >= 1 ; k -- ) data -> suffix_lengths [ k ] = data -> suffix_lengths [ k + 1 ] + data -> prefix_lengths [ k - 1 ] ; for ( k = 2 ; k < om -> M ; k ++ ) data -> prefix_lengths [ k ] += data -> prefix_lengths [ k - 1 ] ; return eslOK ; ERROR : p7_hmm_ScoreDataDestroy ( data ) ; return eslEMEM ; }
Function:  p7_hmm_ScoreDataComputeRest()
 Synopsis:  Using position-specific insert rates, compute MAXL-based prefix and suffix lengths
Function : p7_hmm_ScoreDataComputeRest () Synopsis : Using position - specific insert rates compute MAXL - based prefix and suffix lengths
//2D array, holding all the transition scores/costs /*
   * Elsewhere, we compute the MAXL of a given model, which is the length L
   * such that only a minute fraction (BETA = 1e-7) of emitted sequence are length > L.
   *
   * In the DNA search pipeline, when a high-scoring SSV alignment is identified,
   * we extract a window around that seed. The length of the window is based on
   * MAXL, but we need to figure out how much the window should precede the seed
   * (the prefix of the window) and how much should follow the seed (the suffix).
   *
   * Our heuristic strategy is to estimate how much of that MAXL is likely to have
   * come from each position.  Using these relative contributions of each position,
   * we can compute the length of extracted window prior to the seed as
   *    MAXL * (sum of the expected fractional contributions of preceding positions),
   * and do the same for the extracted window following the seed (suffix sum). This
   * code supports that process, by computing prefix-sum and suffix-sum values for
   * these relative contributions.
   *
   * We estimate the relative contributions of a position k by computing for position
   * k, the minimum length l_k at which the tail probability mass for sequences
   * emitted by position k (match and insert states)  P(L>l_k) < BETA.
   * These per-position lengths are summed, and the relative contribution of a
   * position is it's l_k normalized by the sum of all lengths
   */