third_party_software/hmmer-3.0-linux-intel-x86_64/easel/miniapps/esl-alimanip.c
/* map_rfpos_to_apos
 *                   
 * Given an MSA, determine the alignment position of each
 * non-gap RF (reference) position. The abc is only necessary
 * for defining gap characters.
 * 
 * rf2a_map[0..rfpos..rflen-1] = apos, apos is the alignment position (0..msa->alen-1) that 
 *                               is non-gap RF position rfpos+1 (for rfpos in 0..rflen-1) 
 */


Given an MSA, determine the alignment position of each
non-gap RF (reference) position. The abc is only necessary
for defining gap characters.


Given an MSA determine the alignment position of each non - gap RF ( reference ) position . The abc is only necessary for defining gap characters .
static int map_rfpos_to_apos(ESL_MSA *msa, ESL_ALPHABET *abc, char *errbuf, int **ret_i_am_rf, int **ret_rf2a_map, int *ret_rflen)
{
  int status;
  int rflen = 0;
  int *rf2a_map = NULL;
  int *i_am_rf = NULL;
  int rfpos = 0;
  int apos = 0;
  if(msa->rf == NULL) ESL_FAIL(eslEINVAL, errbuf, "Error, trying to map RF positions to alignment positions, but msa->rf is NULL.");
  for(apos = 0; apos < msa->alen; apos++) { 
    if((! esl_abc_CIsGap(abc, msa->rf[apos])) && 
       (! esl_abc_CIsMissing(abc, msa->rf[apos])) && 
       (! esl_abc_CIsNonresidue(abc, msa->rf[apos])))
      { 
	rflen++;
      }
  }
  ESL_ALLOC(i_am_rf, sizeof(int) * msa->alen);
  ESL_ALLOC(rf2a_map, sizeof(int) * rflen);
  for(apos = 0; apos < msa->alen; apos++) {
    if((! esl_abc_CIsGap(abc, msa->rf[apos])) && 
       (! esl_abc_CIsMissing(abc, msa->rf[apos])) && 
       (! esl_abc_CIsNonresidue(abc, msa->rf[apos]))) { 
      i_am_rf[apos] = TRUE;
      rf2a_map[rfpos++] = apos;
    }
    else { 
      i_am_rf[apos] = FALSE;
    }
  }
  *ret_i_am_rf  = i_am_rf;
  *ret_rf2a_map = rf2a_map;
  *ret_rflen    = rflen;
  return eslOK;
 ERROR:
  if(i_am_rf  != NULL) free(i_am_rf);
  if(rf2a_map != NULL) free(rf2a_map);
  ESL_FAIL(status, errbuf, "Error, out of memory while mapping RF positions to alignment positions.");
}
static int map_rfpos_to_apos ( ESL_MSA * msa , ESL_ALPHABET * abc , char * errbuf , int * * ret_i_am_rf , int * * ret_rf2a_map , int * ret_rflen ) { int status ; int rflen = 0 ; int * rf2a_map = NULL ; int * i_am_rf = NULL ; int rfpos = 0 ; int apos = 0 ; if ( msa -> rf == NULL ) ESL_FAIL ( eslEINVAL , errbuf , " " ) ; for ( apos = 0 ; apos < msa -> alen ; apos ++ ) { if ( ( ! esl_abc_CIsGap ( abc , msa -> rf [ apos ] ) ) && ( ! esl_abc_CIsMissing ( abc , msa -> rf [ apos ] ) ) && ( ! esl_abc_CIsNonresidue ( abc , msa -> rf [ apos ] ) ) ) { rflen ++ ; } } ESL_ALLOC ( i_am_rf , sizeof ( int ) * msa -> alen ) ; ESL_ALLOC ( rf2a_map , sizeof ( int ) * rflen ) ; for ( apos = 0 ; apos < msa -> alen ; apos ++ ) { if ( ( ! esl_abc_CIsGap ( abc , msa -> rf [ apos ] ) ) && ( ! esl_abc_CIsMissing ( abc , msa -> rf [ apos ] ) ) && ( ! esl_abc_CIsNonresidue ( abc , msa -> rf [ apos ] ) ) ) { i_am_rf [ apos ] = TRUE ; rf2a_map [ rfpos ++ ] = apos ; } else { i_am_rf [ apos ] = FALSE ; } } * ret_i_am_rf = i_am_rf ; * ret_rf2a_map = rf2a_map ; * ret_rflen = rflen ; return eslOK ; ERROR : if ( i_am_rf != NULL ) free ( i_am_rf ) ; if ( rf2a_map != NULL ) free ( rf2a_map ) ; ESL_FAIL ( status , errbuf , " " ) ; }
map_rfpos_to_apos
map_rfpos_to_apos
/* contract check */ /* count non-gap RF columns */ /* I don't use esl_abc_CIsResidue() b/c that would return FALSE for 'x' with RNA and DNA */ /* build map */