hmmer-3.3/src/p7_profile.c
/* Function:  p7_profile_GetT()
 *
 * Purpose:   Convenience function that looks up a transition score in
 *            profile <gm> for a transition from state type <st1> in
 *            node <k1> to state type <st2> in node <k2>. For unique
 *            state types that aren't in nodes (<p7T_S>, for example), the
 *            <k> value is ignored, though it would be customarily passed as 0.
 *            Return the transition score in <ret_tsc>.
 *            
 *            This function would almost always be called on profile
 *            traces, of course, but it's possible to call it
 *            on core traces (for example, if you were to try to 
 *            trace_Dump() during HMM construction, and you wanted
 *            to see detailed profile scores for that trace). Core traces
 *            can contain <p7T_X> "states" used solely to signal
 *            a sequence fragment, treated as missing data. Transitions
 *            involving <p7T_X> states are assigned zero score here.
 *            Other transitions that occur only in core traces
 *            (B->I0, B->D1, I_M->E) also silently get a zero score.
 *            This is safe, because we would only ever use this number
 *            for display, not as a log probability somewhere.
 *
 * Returns:   <eslOK> on success, and <*ret_tsc> contains the requested
 *            transition score.            
 * 
 * Throws:    <eslEINVAL> if a nonexistent transition is requested. Now
 *            <*ret_tsc> is set to $-\infty$.
 *            
 */
p7_profile_GetT()
Purpose:   Convenience function that looks up a transition score in
profile  for a transition from state type  in
node  to state type  in node . For unique
state types that aren't in nodes (, for example), the
 value is ignored, though it would be customarily passed as 0.
Return the transition score in .

This function would almost always be called on profile
traces, of course, but it's possible to call it
on core traces (for example, if you were to try to
trace_Dump() during HMM construction, and you wanted
to see detailed profile scores for that trace). Core traces
can contain  "states" used solely to signal
a sequence fragment, treated as missing data. Transitions
involving  states are assigned zero score here.
Other transitions that occur only in core traces
(B->I0, B->D1, I_M->E) also silently get a zero score.
This is safe, because we would only ever use this number
for display, not as a log probability somewhere.

 on success, and <*ret_tsc> contains the requested
transition score.

 if a nonexistent transition is requested. Now
<*ret_tsc> is set to $-\infty$.
p7_profile_GetT () Purpose : Convenience function that looks up a transition score in profile for a transition from state type in node to state type in node . For unique state types that aren ' t in nodes ( for example ) the value is ignored though it would be customarily passed as 0 . Return the transition score in . This function would almost always be called on profile traces of course but it ' s possible to call it on core traces ( for example if you were to try to trace_Dump () during HMM construction and you wanted to see detailed profile scores for that trace ) . Core traces can contain " states " used solely to signal a sequence fragment treated as missing data . Transitions involving states are assigned zero score here . Other transitions that occur only in core traces ( B - > I0 B - > D1 I_M - > E ) also silently get a zero score . This is safe because we would only ever use this number for display not as a log probability somewhere . on success and < * ret_tsc > contains the requested transition score . if a nonexistent transition is requested . Now < * ret_tsc > is set to $ - \ infty$ .
int
p7_profile_GetT(const P7_PROFILE *gm, char st1, int k1, char st2, int k2, float *ret_tsc)
{
  float tsc = 0.0f;
  int   status;
  if (st1 == p7T_X || st2 == p7T_X) return eslOK;
  if (st1 == p7T_B && st2 == p7T_I) return eslOK;
  if (st1 == p7T_B && st2 == p7T_D) return eslOK;
  if (st1 == p7T_I && st2 == p7T_E) return eslOK;
  switch (st1) {
  case p7T_S:  break;
  case p7T_T:  break;
  case p7T_N:
    switch (st2) {
    case p7T_B: tsc =  gm->xsc[p7P_N][p7P_MOVE]; break;
    case p7T_N: tsc =  gm->xsc[p7P_N][p7P_LOOP]; break;
    default:    ESL_XEXCEPTION(eslEINVAL, "bad transition %s->%s", p7_hmm_DecodeStatetype(st1), p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_B:
    switch (st2) {
    case p7T_M: tsc = p7P_TSC(gm, k2-1, p7P_BM); break; 
    default:    ESL_XEXCEPTION(eslEINVAL, "bad transition %s->%s", p7_hmm_DecodeStatetype(st1), p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_M:
    switch (st2) {
    case p7T_M: tsc = p7P_TSC(gm, k1, p7P_MM); break;
    case p7T_I: tsc = p7P_TSC(gm, k1, p7P_MI); break;
    case p7T_D: tsc = p7P_TSC(gm, k1, p7P_MD); break;
    case p7T_E: 
      if (k1 != gm->M && ! p7_profile_IsLocal(gm)) ESL_EXCEPTION(eslEINVAL, "local end transition (M%d of %d) in non-local model", k1, gm->M);
      tsc = 0.0f;		
      break;
    default:    ESL_XEXCEPTION(eslEINVAL, "bad transition %s_%d->%s", p7_hmm_DecodeStatetype(st1), k1, p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_D:
    switch (st2) {
    case p7T_M: tsc = p7P_TSC(gm, k1, p7P_DM); break;
    case p7T_D: tsc = p7P_TSC(gm, k1, p7P_DD); break;
    case p7T_E: 
      if (k1 != gm->M && ! p7_profile_IsLocal(gm)) ESL_EXCEPTION(eslEINVAL, "local end transition (D%d of %d) in non-local model", k1, gm->M);
      tsc = 0.0f;		
      break;
    default:    ESL_XEXCEPTION(eslEINVAL, "bad transition %s_%d->%s", p7_hmm_DecodeStatetype(st1), k1, p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_I:
    switch (st2) {
    case p7T_M: tsc = p7P_TSC(gm, k1, p7P_IM); break;
    case p7T_I: tsc = p7P_TSC(gm, k1, p7P_II); break;
    default:    ESL_XEXCEPTION(eslEINVAL, "bad transition %s_%d->%s", p7_hmm_DecodeStatetype(st1), k1, p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_E:
    switch (st2) {
    case p7T_C: tsc = gm->xsc[p7P_E][p7P_MOVE]; break;
    case p7T_J: tsc = gm->xsc[p7P_E][p7P_LOOP]; break;
    default:     ESL_XEXCEPTION(eslEINVAL, "bad transition %s->%s", p7_hmm_DecodeStatetype(st1), p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_J:
    switch (st2) {
    case p7T_B: tsc = gm->xsc[p7P_J][p7P_MOVE]; break;
    case p7T_J: tsc = gm->xsc[p7P_J][p7P_LOOP]; break;
    default:     ESL_XEXCEPTION(eslEINVAL, "bad transition %s->%s", p7_hmm_DecodeStatetype(st1), p7_hmm_DecodeStatetype(st2));
    }
    break;
  case p7T_C:
    switch (st2) {
    case p7T_T:  tsc = gm->xsc[p7P_C][p7P_MOVE]; break;
    case p7T_C:  tsc = gm->xsc[p7P_C][p7P_LOOP]; break;
    default:     ESL_XEXCEPTION(eslEINVAL, "bad transition %s->%s", p7_hmm_DecodeStatetype(st1), p7_hmm_DecodeStatetype(st2));
    }
    break;
  default: ESL_XEXCEPTION(eslEINVAL, "bad state type %d in traceback", st1);
  }
  *ret_tsc = tsc;
  return eslOK;
 ERROR:
  *ret_tsc = -eslINFINITY;
  return status;
}
int p7_profile_GetT ( const P7_PROFILE * gm , char st1 , int k1 , char st2 , int k2 , float * ret_tsc ) { float tsc = 0.0f ; int status ; if ( st1 == p7T_X || st2 == p7T_X ) return eslOK ; if ( st1 == p7T_B && st2 == p7T_I ) return eslOK ; if ( st1 == p7T_B && st2 == p7T_D ) return eslOK ; if ( st1 == p7T_I && st2 == p7T_E ) return eslOK ; switch ( st1 ) { case p7T_S : break ; case p7T_T : break ; case p7T_N : switch ( st2 ) { case p7T_B : tsc = gm -> xsc [ p7P_N ] [ p7P_MOVE ] ; break ; case p7T_N : tsc = gm -> xsc [ p7P_N ] [ p7P_LOOP ] ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_B : switch ( st2 ) { case p7T_M : tsc = p7P_TSC ( gm , k2 - 1 , p7P_BM ) ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_M : switch ( st2 ) { case p7T_M : tsc = p7P_TSC ( gm , k1 , p7P_MM ) ; break ; case p7T_I : tsc = p7P_TSC ( gm , k1 , p7P_MI ) ; break ; case p7T_D : tsc = p7P_TSC ( gm , k1 , p7P_MD ) ; break ; case p7T_E : if ( k1 != gm -> M && ! p7_profile_IsLocal ( gm ) ) ESL_EXCEPTION ( eslEINVAL , " " , k1 , gm -> M ) ; tsc = 0.0f ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , k1 , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_D : switch ( st2 ) { case p7T_M : tsc = p7P_TSC ( gm , k1 , p7P_DM ) ; break ; case p7T_D : tsc = p7P_TSC ( gm , k1 , p7P_DD ) ; break ; case p7T_E : if ( k1 != gm -> M && ! p7_profile_IsLocal ( gm ) ) ESL_EXCEPTION ( eslEINVAL , " " , k1 , gm -> M ) ; tsc = 0.0f ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , k1 , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_I : switch ( st2 ) { case p7T_M : tsc = p7P_TSC ( gm , k1 , p7P_IM ) ; break ; case p7T_I : tsc = p7P_TSC ( gm , k1 , p7P_II ) ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , k1 , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_E : switch ( st2 ) { case p7T_C : tsc = gm -> xsc [ p7P_E ] [ p7P_MOVE ] ; break ; case p7T_J : tsc = gm -> xsc [ p7P_E ] [ p7P_LOOP ] ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_J : switch ( st2 ) { case p7T_B : tsc = gm -> xsc [ p7P_J ] [ p7P_MOVE ] ; break ; case p7T_J : tsc = gm -> xsc [ p7P_J ] [ p7P_LOOP ] ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; case p7T_C : switch ( st2 ) { case p7T_T : tsc = gm -> xsc [ p7P_C ] [ p7P_MOVE ] ; break ; case p7T_C : tsc = gm -> xsc [ p7P_C ] [ p7P_LOOP ] ; break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , p7_hmm_DecodeStatetype ( st1 ) , p7_hmm_DecodeStatetype ( st2 ) ) ; } break ; default : ESL_XEXCEPTION ( eslEINVAL , " " , st1 ) ; } * ret_tsc = tsc ; return eslOK ; ERROR : * ret_tsc = - eslINFINITY ; return status ; }
Function:  p7_profile_GetT()
 Purpose:   Convenience function that looks up a transition score in
            profile <gm> for a transition from state type <st1> in
            node <k1> to state type <st2> in node <k2>.
Function : p7_profile_GetT () Purpose : Convenience function that looks up a transition score in profile <gm > for a transition from state type <st1 > in node <k1 > to state type <st2 > in node <k2 > .
/* Detect transitions that can only come from core traces;
   * return 0.0 as a special case (this is only done for displaying
   * "scores" in trace dumps, during debugging.)
   */ /* Now we're sure this is a profile trace, as it should usually be. */ /* remember, B->Mk is stored in [k-1][p7P_BM] */ /* by def'n in H3 local alignment */ /* by def'n in H3 local alignment */