hmmer-3.3/easel/miniapps/esl-alimanip.c
/* Function: msa_keep_or_remove_seqs()
 * 
 * Purpose:  Given a list of <seqlist_n> sequences in <seqlist>, either remove those
 *           sequences from msa, or remove all other sequences besides those from msa.
 *           Create and return the new msa with only the specified seqs in <ret_new_msa>.
 * 
 * Returns: eslOK on success, eslEINVAL if a sequence name in seqlist does not exist in the msa.
 * 
 */


Given a list of  sequences in , either remove those
sequences from msa, or remove all other sequences besides those from msa.
Create and return the new msa with only the specified seqs in .

eslOK on success, eslEINVAL if a sequence name in seqlist does not exist in the msa.
Given a list of sequences in either remove those sequences from msa or remove all other sequences besides those from msa . Create and return the new msa with only the specified seqs in . eslOK on success eslEINVAL if a sequence name in seqlist does not exist in the msa .
static int
msa_keep_or_remove_seqs(ESL_MSA *msa, char *errbuf, char **seqlist, int seqlist_n, int do_keep, int do_reorder, int nali, ESL_MSA **ret_new_msa)
{
  int  status;
  int *useme;
  int  i, ip, n;
  int *order_all, *order_new;
  ESL_MSA *new_msa;
  if(msa->index == NULL) ESL_FAIL(eslEINVAL, errbuf, "ERROR, msa->index is NULL!");
  ESL_ALLOC(useme,     sizeof(int) * msa->nseq);
  ESL_ALLOC(order_all, sizeof(int) * msa->nseq);
  ESL_ALLOC(order_new, sizeof(int) * seqlist_n);
  esl_vec_ISet(order_all, msa->nseq, -1);
  if(do_keep) esl_vec_ISet(useme, msa->nseq, FALSE);
  else        esl_vec_ISet(useme, msa->nseq, TRUE); 
  for(n = 0; n < seqlist_n; n++) { 
    if((status = esl_keyhash_Lookup(msa->index, seqlist[n], -1, &i)) == eslENOTFOUND) 
      ESL_FAIL(status, errbuf, "Error sequence %s does not exist in alignment %d", seqlist[n], nali);
    useme[i] = do_keep ? TRUE : FALSE;
    if(order_all[i] != -1) ESL_FAIL(eslEINVAL, errbuf, "ERROR sequence %s listed twice in a input list file.", seqlist[n]);
    order_all[i] = n;
  }
  if(esl_vec_ISum(useme, msa->nseq) == 0) esl_fatal("No sequences remaining in the alignment!.");
  if((status = esl_msa_SequenceSubset(msa, useme, &new_msa)) != eslOK) esl_fatal("esl_msa_SequenceSubset() had a problem.");
  if(do_keep && do_reorder) { 
    ip = 0;
    for(i = 0; i < msa->nseq; i++) { 
      if(order_all[i] != -1) order_new[order_all[i]] = ip++;
    }
    if((status = reorder_msa(new_msa, order_new, errbuf)) != eslOK) return status;
  }
  free(useme);
  free(order_all);
  free(order_new);
  *ret_new_msa = new_msa;
  return eslOK;
 ERROR:
  esl_fatal("msa_keep_or_remove_seqs() memory allocation error.");
  return eslOK; 
}
static int msa_keep_or_remove_seqs ( ESL_MSA * msa , char * errbuf , char * * seqlist , int seqlist_n , int do_keep , int do_reorder , int nali , ESL_MSA * * ret_new_msa ) { int status ; int * useme ; int i , ip , n ; int * order_all , * order_new ; ESL_MSA * new_msa ; if ( msa -> index == NULL ) ESL_FAIL ( eslEINVAL , errbuf , " " ) ; ESL_ALLOC ( useme , sizeof ( int ) * msa -> nseq ) ; ESL_ALLOC ( order_all , sizeof ( int ) * msa -> nseq ) ; ESL_ALLOC ( order_new , sizeof ( int ) * seqlist_n ) ; esl_vec_ISet ( order_all , msa -> nseq , -1 ) ; if ( do_keep ) esl_vec_ISet ( useme , msa -> nseq , FALSE ) ; else esl_vec_ISet ( useme , msa -> nseq , TRUE ) ; for ( n = 0 ; n < seqlist_n ; n ++ ) { if ( ( status = esl_keyhash_Lookup ( msa -> index , seqlist [ n ] , -1 , & i ) ) == eslENOTFOUND ) ESL_FAIL ( status , errbuf , " " , seqlist [ n ] , nali ) ; useme [ i ] = do_keep ? TRUE : FALSE ; if ( order_all [ i ] != -1 ) ESL_FAIL ( eslEINVAL , errbuf , " " , seqlist [ n ] ) ; order_all [ i ] = n ; } if ( esl_vec_ISum ( useme , msa -> nseq ) == 0 ) esl_fatal ( " " ) ; if ( ( status = esl_msa_SequenceSubset ( msa , useme , & new_msa ) ) != eslOK ) esl_fatal ( " " ) ; if ( do_keep && do_reorder ) { ip = 0 ; for ( i = 0 ; i < msa -> nseq ; i ++ ) { if ( order_all [ i ] != -1 ) order_new [ order_all [ i ] ] = ip ++ ; } if ( ( status = reorder_msa ( new_msa , order_new , errbuf ) ) != eslOK ) return status ; } free ( useme ) ; free ( order_all ) ; free ( order_new ) ; * ret_new_msa = new_msa ; return eslOK ; ERROR : esl_fatal ( " " ) ; return eslOK ; }
Function: msa_keep_or_remove_seqs()
Function : msa_keep_or_remove_seqs ()
/* if do_keep, reorder to order of names in the list file */ /* NEVERREACHED */