hmmer-3.3/easel/miniapps/esl-alimanip.c
/* Function: msa_remove_seqs_below_minlen()
 * 
 * Purpose:  Remove sequences in MSA whose dealigned length is less than a minimum length.
 *           If <i_am_rf> is non-NULL, only consider positions that are nongap RF.
 */


Remove sequences in MSA whose dealigned length is less than a minimum length.
If  is non-NULL, only consider positions that are nongap RF.
Remove sequences in MSA whose dealigned length is less than a minimum length . If is non - NULL only consider positions that are nongap RF .
static int
msa_remove_seqs_below_minlen(ESL_MSA *msa, float minlen, int *i_am_rf, ESL_MSA **ret_new_msa)
{
  int     status;
  int    *useme;   
  int     i, apos; 
  int64_t len;     
  ESL_MSA *new_msa;
  ESL_SQ *sq;
  sq = esl_sq_CreateDigital(msa->abc);
  ESL_ALLOC(useme, sizeof(int) * msa->nseq);
  for (i = 0; i < msa->nseq; i++) {
    if(i_am_rf != NULL) { 
      len = 0;
      for(apos = 1; apos <= msa->alen; apos++) { 
        if(i_am_rf[(apos-1)] && (! esl_abc_XIsGap(msa->abc, msa->ax[i][apos]))) len++;
      }
    }
    else { 
      esl_sq_GetFromMSA(msa, i, sq);
      len = sq->n;
      esl_sq_Reuse(sq);
    }
    useme[i] = ((float) len >= minlen) ? TRUE : FALSE;
  }
  if(esl_vec_ISum(useme, msa->nseq) == 0) esl_fatal("No sequences at or above minimum allowed length.");
  if((status = esl_msa_SequenceSubset(msa, useme, &new_msa)) != eslOK) esl_fatal("esl_msa_SequenceSubset() had a problem.");
  free(useme);
  esl_sq_Destroy(sq);
  *ret_new_msa = new_msa;
  return eslOK;
 ERROR:
  esl_fatal("msa_remove_seqs_below_minlen() memory allocation error.");
  return eslOK; 
}
static int msa_remove_seqs_below_minlen ( ESL_MSA * msa , float minlen , int * i_am_rf , ESL_MSA * * ret_new_msa ) { int status ; int * useme ; int i , apos ; int64_t len ; ESL_MSA * new_msa ; ESL_SQ * sq ; sq = esl_sq_CreateDigital ( msa -> abc ) ; ESL_ALLOC ( useme , sizeof ( int ) * msa -> nseq ) ; for ( i = 0 ; i < msa -> nseq ; i ++ ) { if ( i_am_rf != NULL ) { len = 0 ; for ( apos = 1 ; apos <= msa -> alen ; apos ++ ) { if ( i_am_rf [ ( apos - 1 ) ] && ( ! esl_abc_XIsGap ( msa -> abc , msa -> ax [ i ] [ apos ] ) ) ) len ++ ; } } else { esl_sq_GetFromMSA ( msa , i , sq ) ; len = sq -> n ; esl_sq_Reuse ( sq ) ; } useme [ i ] = ( ( float ) len >= minlen ) ? TRUE : FALSE ; } if ( esl_vec_ISum ( useme , msa -> nseq ) == 0 ) esl_fatal ( " " ) ; if ( ( status = esl_msa_SequenceSubset ( msa , useme , & new_msa ) ) != eslOK ) esl_fatal ( " " ) ; free ( useme ) ; esl_sq_Destroy ( sq ) ; * ret_new_msa = new_msa ; return eslOK ; ERROR : esl_fatal ( " " ) ; return eslOK ; }
Function: msa_remove_seqs_below_minlen()
Function : msa_remove_seqs_below_minlen ()
/* [0..msa->nseq-1]: 1 to keep sequence, 0 to remove it */ /* sequence index, alignment position */ /* length of current sequence, either nongap length (if i_am_rf == NULL) or nongap RF length (if i_am_rf != NULL) */ /* i_am_rf is NULL, consider the entire sequence */ /*printf("useme[i:%d]: %d (len: %" PRId64 ", minlen: %.2f)\n", i, useme[i], len, minlen);*/ /* NEVERREACHED */