third_party_software/hmmer-3.0-linux-intel-x86_64/easel/miniapps/esl-alimanip.c
/* determine_first_last_consensus_columns
 *                   
 * Given an MSA, determine the first and last consensus columns
 * occupied by each sequence
 */


Given an MSA, determine the first and last consensus columns
occupied by each sequence
Given an MSA determine the first and last consensus columns occupied by each sequence
static int determine_first_last_consensus_columns(ESL_MSA *msa, char *errbuf, int *i_am_rf, int rflen, int **ret_fA, int **ret_lA)
{
  int status;
  int *fA = NULL;
  int *lA = NULL;
  int rfpos = 0;
  int apos = 0;
  int i;
  if(msa->rf == NULL) { status = eslEINVAL; goto ERROR; }
  ESL_ALLOC(fA, sizeof(int) * msa->nseq);
  ESL_ALLOC(lA, sizeof(int) * msa->nseq);
  esl_vec_ISet(lA, msa->nseq, 0);
  esl_vec_ISet(fA, msa->nseq, rflen);
  for(i = 0; i < msa->nseq; i++) { 
    rfpos = 0;
    for(apos = 0; apos < msa->alen; apos++) {
      if(i_am_rf[apos]) { 
	rfpos++;
	if(! esl_abc_XIsGap(msa->abc, msa->ax[i][(apos+1)])) { 
	  fA[i] = ESL_MIN(fA[i], rfpos);
	  lA[i] = ESL_MAX(lA[i], rfpos);
	}
      }
    }
  }
  *ret_fA   = fA;
  *ret_lA   = lA;
  return eslOK;
 ERROR: ESL_FAIL(status, errbuf, "determine_first_last_consensus_columns(): memory allocation error.");
  return status; 
}
static int determine_first_last_consensus_columns ( ESL_MSA * msa , char * errbuf , int * i_am_rf , int rflen , int * * ret_fA , int * * ret_lA ) { int status ; int * fA = NULL ; int * lA = NULL ; int rfpos = 0 ; int apos = 0 ; int i ; if ( msa -> rf == NULL ) { status = eslEINVAL ; goto ERROR ; } ESL_ALLOC ( fA , sizeof ( int ) * msa -> nseq ) ; ESL_ALLOC ( lA , sizeof ( int ) * msa -> nseq ) ; esl_vec_ISet ( lA , msa -> nseq , 0 ) ; esl_vec_ISet ( fA , msa -> nseq , rflen ) ; for ( i = 0 ; i < msa -> nseq ; i ++ ) { rfpos = 0 ; for ( apos = 0 ; apos < msa -> alen ; apos ++ ) { if ( i_am_rf [ apos ] ) { rfpos ++ ; if ( ! esl_abc_XIsGap ( msa -> abc , msa -> ax [ i ] [ ( apos + 1 ) ] ) ) { fA [ i ] = ESL_MIN ( fA [ i ] , rfpos ) ; lA [ i ] = ESL_MAX ( lA [ i ] , rfpos ) ; } } } } * ret_fA = fA ; * ret_lA = lA ; return eslOK ; ERROR : ESL_FAIL ( status , errbuf , " " ) ; return status ; }
determine_first_last_consensus_columns
determine_first_last_consensus_columns
/* contract check */ /* determine the first and last occupied consensus position in each sequence */ /* this could be way more efficient */ /* apos is a consensus position */ /* rfpos for seq i is not a gap */ /* NEVERREACHED */