third_party_software/hmmer-3.0-linux-intel-x86_64/easel/miniapps/esl-alimanip.c
/* Function:  insert_x_pair_shared()
 * Synopsis:  Calculate the fraction of inserts shared between of two aligned digital seqs.
 * Incept:    EPN, Wed Jun 25 10:33:23 2008
 *
 * Purpose:   Returns the fraction of the total
 *            number of inserts in both sequences that are shared.
 *            An 'insert' is present in sequence s for consensus column 
 *            (non-gap RF column) c if at least 1 residue exists between 
 *            consensus column c and c+1. If sequence t also has an insert
 *            between c and c+1, they share that insert. If that were the
 *            only insert in either of the two sequences, then they would
 *            share 1.0 fraction of inserts.
 *            
 * Args:      msa          - MSA, digitized, with RF annotation
 *            i_am_rf      - [0..msa->alen-1], TRUE if apos is a nongap RF column, FALSE if not 
 *            i            - index of seq 1
 *            j            - indes of seq 2
 *            cfirst       - first consensus position to consider
 *            clast        - last consensus position to consider
 *            opt_pshared  - optRETURN: pairwise insert identity, 0<=x<=1
  *            opt_nshared  - optRETURN: # of inserts shared
 *            opt_nins     - optRETURN: nins
 *
 * Returns:   <eslOK> on success. <opt_distance>, <opt_nid>, <opt_n>
 *            contain the answers, for any of these that were passed
 *            non-<NULL> pointers.
 *
 * Throws:    <eslEINVAL> if the strings are different lengths (not aligned).
 */
insert_x_pair_shared()
Synopsis:  Calculate the fraction of inserts shared between of two aligned digital seqs.

Returns the fraction of the total
number of inserts in both sequences that are shared.
An 'insert' is present in sequence s for consensus column
(non-gap RF column) c if at least 1 residue exists between
consensus column c and c+1. If sequence t also has an insert
between c and c+1, they share that insert. If that were the
only insert in either of the two sequences, then they would
share 1.0 fraction of inserts.



 on success. , , 
contain the answers, for any of these that were passed
non- pointers.

 if the strings are different lengths (not aligned).
insert_x_pair_shared () Synopsis : Calculate the fraction of inserts shared between of two aligned digital seqs . Returns the fraction of the total number of inserts in both sequences that are shared . An ' insert ' is present in sequence s for consensus column ( non - gap RF column ) c if at least 1 residue exists between consensus column c and c + 1 . If sequence t also has an insert between c and c + 1 they share that insert . If that were the only insert in either of the two sequences then they would share 1 . 0 fraction of inserts . on success . contain the answers for any of these that were passed non - pointers . if the strings are different lengths ( not aligned ) .
int
insert_x_pair_shared(ESL_MSA *msa, int *i_am_rf, int i, int j, int cfirst, int clast, double *opt_pshared, int *opt_nshared, int *opt_nins)
{
  int     shared;               
  int     nins;                 
  int     apos;                 
  int     rfpos;
  int     insi, insj;
  int     seen_insert = FALSE;
  shared = nins = 0;
  rfpos = 0;
  for(apos = 1; apos <= msa->alen; apos++)
    {
      if(! esl_abc_CIsGap(msa->abc, msa->rf[(apos-1)])) { 
	rfpos++;
	seen_insert = FALSE;
      }
      else { 
	insi = (! esl_abc_XIsGap(msa->abc, msa->ax[i][apos]));
	insj = (! esl_abc_XIsGap(msa->abc, msa->ax[j][apos]));
	if(rfpos >= cfirst && rfpos <= clast) { 
	  if(insi && insj   && !seen_insert)   shared++;
	  if((insi || insj) && !seen_insert) { nins++; seen_insert = TRUE; }
	}
      }
    }
  if (opt_pshared  != NULL)  *opt_pshared  = ( nins==0 ? 1. : (double) shared / (double) nins );
  if (opt_nshared  != NULL)  *opt_nshared  = shared;
  if (opt_nins     != NULL)  *opt_nins     = nins;
  return eslOK;
}
int insert_x_pair_shared ( ESL_MSA * msa , int * i_am_rf , int i , int j , int cfirst , int clast , double * opt_pshared , int * opt_nshared , int * opt_nins ) { int shared ; int nins ; int apos ; int rfpos ; int insi , insj ; int seen_insert = FALSE ; shared = nins = 0 ; rfpos = 0 ; for ( apos = 1 ; apos <= msa -> alen ; apos ++ ) { if ( ! esl_abc_CIsGap ( msa -> abc , msa -> rf [ ( apos - 1 ) ] ) ) { rfpos ++ ; seen_insert = FALSE ; } else { insi = ( ! esl_abc_XIsGap ( msa -> abc , msa -> ax [ i ] [ apos ] ) ) ; insj = ( ! esl_abc_XIsGap ( msa -> abc , msa -> ax [ j ] [ apos ] ) ) ; if ( rfpos >= cfirst && rfpos <= clast ) { if ( insi && insj && ! seen_insert ) shared ++ ; if ( ( insi || insj ) && ! seen_insert ) { nins ++ ; seen_insert = TRUE ; } } } } if ( opt_pshared != NULL ) * opt_pshared = ( nins == 0 ? 1. : ( double ) shared / ( double ) nins ) ; if ( opt_nshared != NULL ) * opt_nshared = shared ; if ( opt_nins != NULL ) * opt_nins = nins ; return eslOK ; }
Function:  insert_x_pair_shared()
 Synopsis:  Calculate the fraction of inserts shared between of two aligned digital seqs.
Function : insert_x_pair_shared () Synopsis : Calculate the fraction of inserts shared between of two aligned digital seqs .
/* total shared inserts */ /* number of inserts in either sequence */ /* position in aligned seqs   */ /* not a consensus column, an insert column */ /*if (opt_pshared  != NULL)  *opt_pshared  = ( nins==0 ? 0. : (double) shared / (double) nins );*/