hmmer-3.3/src/p7_hmm.c
/* Function:  p7_hmm_Validate()
 * Synopsis:  Validate a <P7_HMM> data structuure.
 *
 * Purpose:   Validates the internals of the HMM structure <hmm>.
 * 
 *            Probability vectors are validated to sum up to
 *            within a fractional tolerance <tol> of 1.0.
 *
 *            Probably only useful for debugging and development,
 *            not production code.
 *
 * Returns:   <eslOK> if <hmm> internals look fine.
 *            Returns <eslFAIL> if something is wrong.
 */
p7_hmm_Validate()
Synopsis:  Validate a  data structuure.

Validates the internals of the HMM structure .

Probability vectors are validated to sum up to
within a fractional tolerance  of 1.0.

Probably only useful for debugging and development,
not production code.

 if  internals look fine.
Returns  if something is wrong.
p7_hmm_Validate () Synopsis : Validate a data structuure . Validates the internals of the HMM structure . Probability vectors are validated to sum up to within a fractional tolerance of 1 . 0 . Probably only useful for debugging and development not production code . if internals look fine . Returns if something is wrong .
int
p7_hmm_Validate(P7_HMM *hmm, char *errbuf, float tol)
{
  int status;
  int k;
  if (hmm            == NULL)       ESL_XFAIL(eslFAIL, errbuf, "HMM is a null pointer");
  if (hmm->M         <  1)          ESL_XFAIL(eslFAIL, errbuf, "HMM has M < 1");
  if (hmm->abc       == NULL)       ESL_XFAIL(eslFAIL, errbuf, "HMM has no alphabet reference");
  if (hmm->abc->type == eslUNKNOWN) ESL_XFAIL(eslFAIL, errbuf, "HMM's alphabet is set to unknown");
  for (k = 0; k <= hmm->M; k++)
    {
      if (esl_vec_FValidate(hmm->mat[k], hmm->abc->K, tol, NULL) != eslOK) ESL_XFAIL(eslFAIL, errbuf, "mat[%d] fails pvector validation", k);
      if (esl_vec_FValidate(hmm->ins[k], hmm->abc->K, tol, NULL) != eslOK) ESL_XFAIL(eslFAIL, errbuf, "ins[%d] fails pvector validation", k);
      if (esl_vec_FValidate(hmm->t[k],   3,           tol, NULL) != eslOK) ESL_XFAIL(eslFAIL, errbuf, "t_M[%d] fails pvector validation", k);
      if (esl_vec_FValidate(hmm->t[k]+3, 2,           tol, NULL) != eslOK) ESL_XFAIL(eslFAIL, errbuf, "t_I[%d] fails pvector validation", k);
      if (esl_vec_FValidate(hmm->t[k]+5, 2,           tol, NULL) != eslOK) ESL_XFAIL(eslFAIL, errbuf, "t_D[%d] fails pvector validation", k);
    }
  if (hmm->t[hmm->M][p7H_MD] != 0.0)                       ESL_XFAIL(eslFAIL, errbuf, "TMD should be 0 for last node");
  if (hmm->t[hmm->M][p7H_DM] != 1.0)                       ESL_XFAIL(eslFAIL, errbuf, "TDM should be 1 for last node");
  if (hmm->t[hmm->M][p7H_DD] != 0.0)                       ESL_XFAIL(eslFAIL, errbuf, "TDD should be 0 for last node");
  if (hmm->name == NULL)                                   ESL_XFAIL(eslFAIL, errbuf, "name is NULL: this field is mandatory");
  if ( (hmm->nseq     != -1)     && hmm->nseq     <= 0)    ESL_XFAIL(eslFAIL, errbuf, "invalid nseq");
  if ( (hmm->eff_nseq != -1.0f)  && hmm->eff_nseq <= 0.0f) ESL_XFAIL(eslFAIL, errbuf, "invalid eff_nseq");
  if (!(hmm->flags & p7H_CHKSUM) && hmm->checksum != 0 )   ESL_XFAIL(eslFAIL, errbuf, "p7H_CHKSUM flag down, but nonzero checksum present"); 
  if (hmm->flags & p7H_RF)   { if (hmm->rf == NULL        || strlen(hmm->rf)        != hmm->M+1) ESL_XFAIL(eslFAIL, errbuf, "p7H_RF flag up, but rf string is invalid");            }
  else if (hmm->rf)          {                                                                   ESL_XFAIL(eslFAIL, errbuf, "p7H_RF flag down, but rf string is present");          }
  if (hmm->flags & p7H_MMASK) { if (hmm->mm == NULL        || strlen(hmm->mm)        != hmm->M+1) ESL_XFAIL(eslFAIL, errbuf, "p7H_MMASK flag up, but mm string is invalid");            }
  else if (hmm->mm)           {                                                                   ESL_XFAIL(eslFAIL, errbuf, "p7H_MMASK flag down, but mm string is present");          }
  if (hmm->flags & p7H_CONS) { if (hmm->consensus == NULL || strlen(hmm->consensus) != hmm->M+1) ESL_XFAIL(eslFAIL, errbuf, "p7H_CONS flag up, but consensus string is invalid");   } 
  else if (hmm->consensus)   {                                                                   ESL_XFAIL(eslFAIL, errbuf, "p7H_CONS flag down, but consensus string is present"); }
  if (hmm->flags & p7H_CS)   { if (hmm->cs == NULL        || strlen(hmm->cs)        != hmm->M+1) ESL_XFAIL(eslFAIL, errbuf, "p7H_CS flag up, but cs string is invalid");   }
  else if (hmm->cs)          {                                                                   ESL_XFAIL(eslFAIL, errbuf, "p7H_CS flag down, but cs string is present"); }
  if (hmm->flags & p7H_CA)   { if (hmm->ca == NULL        || strlen(hmm->ca)        != hmm->M+1) ESL_XFAIL(eslFAIL, errbuf, "p7H_CA flag up, but ca string is invalid");   }
  else if (hmm->ca)          {                                                                   ESL_XFAIL(eslFAIL, errbuf, "p7H_CA flag down, but ca string is present"); }
  if (  (hmm->flags & p7H_MAP) && hmm->map == NULL)  ESL_XFAIL(eslFAIL, errbuf, "p7H_MAP flag up, but map string is null");
  if (! (hmm->flags & p7H_MAP) && hmm->map != NULL)  ESL_XFAIL(eslFAIL, errbuf, "p7H_MAP flag down, but map string is present");
  if (hmm->flags & p7H_STATS) {
    if (hmm->evparam[p7_MLAMBDA] <= 0.) ESL_XFAIL(eslFAIL, errbuf, "lambda parameter can't be negative");
    if (hmm->evparam[p7_VLAMBDA] <= 0.) ESL_XFAIL(eslFAIL, errbuf, "lambda parameter can't be negative");
    if (hmm->evparam[p7_FLAMBDA] <= 0.) ESL_XFAIL(eslFAIL, errbuf, "lambda parameter can't be negative");
  }
  if (hmm->flags & p7H_COMPO && esl_vec_FValidate(hmm->compo, hmm->abc->K, tol, NULL) != eslOK)
    ESL_XFAIL(eslFAIL, errbuf, "composition fails pvector validation");
  return eslOK;
 ERROR:
  return status;
}
int p7_hmm_Validate ( P7_HMM * hmm , char * errbuf , float tol ) { int status ; int k ; if ( hmm == NULL ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> M < 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> abc == NULL ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> abc -> type == eslUNKNOWN ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; for ( k = 0 ; k <= hmm -> M ; k ++ ) { if ( esl_vec_FValidate ( hmm -> mat [ k ] , hmm -> abc -> K , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " , k ) ; if ( esl_vec_FValidate ( hmm -> ins [ k ] , hmm -> abc -> K , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " , k ) ; if ( esl_vec_FValidate ( hmm -> t [ k ] , 3 , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " , k ) ; if ( esl_vec_FValidate ( hmm -> t [ k ] + 3 , 2 , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " , k ) ; if ( esl_vec_FValidate ( hmm -> t [ k ] + 5 , 2 , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " , k ) ; } if ( hmm -> t [ hmm -> M ] [ p7H_MD ] != 0.0 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> t [ hmm -> M ] [ p7H_DM ] != 1.0 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> t [ hmm -> M ] [ p7H_DD ] != 0.0 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> name == NULL ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( ( hmm -> nseq != -1 ) && hmm -> nseq <= 0 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( ( hmm -> eff_nseq != -1.0f ) && hmm -> eff_nseq <= 0.0f ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( ! ( hmm -> flags & p7H_CHKSUM ) && hmm -> checksum != 0 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> flags & p7H_RF ) { if ( hmm -> rf == NULL || strlen ( hmm -> rf ) != hmm -> M + 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } else if ( hmm -> rf ) { ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( hmm -> flags & p7H_MMASK ) { if ( hmm -> mm == NULL || strlen ( hmm -> mm ) != hmm -> M + 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } else if ( hmm -> mm ) { ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( hmm -> flags & p7H_CONS ) { if ( hmm -> consensus == NULL || strlen ( hmm -> consensus ) != hmm -> M + 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } else if ( hmm -> consensus ) { ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( hmm -> flags & p7H_CS ) { if ( hmm -> cs == NULL || strlen ( hmm -> cs ) != hmm -> M + 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } else if ( hmm -> cs ) { ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( hmm -> flags & p7H_CA ) { if ( hmm -> ca == NULL || strlen ( hmm -> ca ) != hmm -> M + 1 ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } else if ( hmm -> ca ) { ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( ( hmm -> flags & p7H_MAP ) && hmm -> map == NULL ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( ! ( hmm -> flags & p7H_MAP ) && hmm -> map != NULL ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> flags & p7H_STATS ) { if ( hmm -> evparam [ p7_MLAMBDA ] <= 0. ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> evparam [ p7_VLAMBDA ] <= 0. ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; if ( hmm -> evparam [ p7_FLAMBDA ] <= 0. ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; } if ( hmm -> flags & p7H_COMPO && esl_vec_FValidate ( hmm -> compo , hmm -> abc -> K , tol , NULL ) != eslOK ) ESL_XFAIL ( eslFAIL , errbuf , " " ) ; return eslOK ; ERROR : return status ; }
Function:  p7_hmm_Validate()
 Synopsis:  Validate a <P7_HMM> data structuure.
Function : p7_hmm_Validate () Synopsis : Validate a <P7_HMM > data structuure .
/* comlog is either NULL or a free text string: hard to validate */ /* ctime, ditto */