hmmer-3.3/easel/miniapps/esl-alimanip.c
/* Function:  dst_nongap_XDiffMx()
 * Synopsis:  NxN difference matrix for N aligned digital seqs.         
 *            Differs from esl_dst_XDiffMx() in that denominator for
 *            seq identity is number of columns that are non-gap in both 
 *            sequences (instead of length of the shorter of the two seqs).
 *            
 * Incept:    EPN, Fri Jun 27 15:10:53 2008
 *
 * Args:      abc   - digital alphabet in use
 *            ax    - aligned dsq's, [0..N-1][1..alen]                  
 *            N     - number of aligned sequences
 *            ret_D - RETURN: NxN matrix of fractional differences
 *            
 * Returns:   <eslOK> on success, and <ret_D> contains the difference
 *            matrix; caller is obligated to free <D> with 
 *            <esl_dmatrix_Destroy()>. 
 *
 * Throws:    <eslEINVAL> if a seq has a different
 *            length than others. On failure, <ret_D> is returned <NULL>
 *            and state of inputs is unchanged.
 */
dst_nongap_XDiffMx()
Synopsis:  NxN difference matrix for N aligned digital seqs.
Differs from esl_dst_XDiffMx() in that denominator for
seq identity is number of columns that are non-gap in both
sequences (instead of length of the shorter of the two seqs).





 on success, and  contains the difference
matrix; caller is obligated to free  with
.

 if a seq has a different
length than others. On failure,  is returned 
and state of inputs is unchanged.
dst_nongap_XDiffMx () Synopsis : NxN difference matrix for N aligned digital seqs . Differs from esl_dst_XDiffMx () in that denominator for seq identity is number of columns that are non - gap in both sequences ( instead of length of the shorter of the two seqs ) . on success and contains the difference matrix ; caller is obligated to free with . if a seq has a different length than others . On failure is returned and state of inputs is unchanged .
int
dst_nongap_XDiffMx(const ESL_ALPHABET *abc, ESL_DSQ **ax, int N, ESL_DMATRIX **ret_D)
{
  ESL_DMATRIX *D = NULL;
  int i,j;
  int status;
  if (( D = esl_dmatrix_Create(N,N) ) == NULL) { status = eslEMEM; goto ERROR; }
  for (i = 0; i < N; i++)
    {
      D->mx[i][i] = 0.;
      for (j = i+1; j < N; j++)
	{
	  status = dst_nongap_XPairId(abc, ax[i], ax[j], &(D->mx[i][j]), NULL, NULL);
	  if (status != eslOK) ESL_XEXCEPTION(status, "Pairwise identity calculation failed at seqs %d,%d\n", i,j);
	  D->mx[i][j] =  1.0 - D->mx[i][j];
	  D->mx[j][i] =  D->mx[i][j];
	}
    }
  if (ret_D != NULL) *ret_D = D; else esl_dmatrix_Destroy(D);
  return eslOK;
 ERROR:
  if (D     != NULL)  esl_dmatrix_Destroy(D);
  if (ret_D != NULL) *ret_D = NULL;
  return status;
}
int dst_nongap_XDiffMx ( const ESL_ALPHABET * abc , ESL_DSQ * * ax , int N , ESL_DMATRIX * * ret_D ) { ESL_DMATRIX * D = NULL ; int i , j ; int status ; if ( ( D = esl_dmatrix_Create ( N , N ) ) == NULL ) { status = eslEMEM ; goto ERROR ; } for ( i = 0 ; i < N ; i ++ ) { D -> mx [ i ] [ i ] = 0. ; for ( j = i + 1 ; j < N ; j ++ ) { status = dst_nongap_XPairId ( abc , ax [ i ] , ax [ j ] , & ( D -> mx [ i ] [ j ] ) , NULL , NULL ) ; if ( status != eslOK ) ESL_XEXCEPTION ( status , " \n " , i , j ) ; D -> mx [ i ] [ j ] = 1.0 - D -> mx [ i ] [ j ] ; D -> mx [ j ] [ i ] = D -> mx [ i ] [ j ] ; } } if ( ret_D != NULL ) * ret_D = D ; else esl_dmatrix_Destroy ( D ) ; return eslOK ; ERROR : if ( D != NULL ) esl_dmatrix_Destroy ( D ) ; if ( ret_D != NULL ) * ret_D = NULL ; return status ; }
Function:  dst_nongap_XDiffMx()
 Synopsis:  NxN difference matrix for N aligned digital seqs.
Function : dst_nongap_XDiffMx () Synopsis : NxN difference matrix for N aligned digital seqs .