deps/kb_meme/meme-5.0.1/src/tomtom.c
/**************************************************************************
 * Computes the BLiC (Bayesian Likelihood 2-Component) score described
 * by Equation (2) in Habib et al., PLoS CB 4(2):e1000010.
 *
 * Thus far, BLiC is only implemented for DNA.  It would be relatively
 * straightforward to extend to amino acids.
 **************************************************************************/
Computes the BLiC (Bayesian Likelihood 2-Component) score described
by Equation (2) in Habib et al., PLoS CB 4(2):e1000010.

Thus far, BLiC is only implemented for DNA.  It would be relatively
straightforward to extend to amino acids.
Computes the BLiC ( Bayesian Likelihood 2 - Component ) score described by Equation ( 2 ) in Habib et al . PLoS CB 4 ( 2 ) : e1000010 . Thus far BLiC is only implemented for DNA . It would be relatively straightforward to extend to amino acids .
static double one_blic_score(
    int      num_dirichlets,
    ARRAY_T* query_counts, 
    ARRAY_T* target_counts,
    ARRAY_T* background
    ) {
  int alphabet_size = get_array_length(query_counts);
  assert(alphabet_size == 4);  
  ARRAY_T* common_counts = allocate_array(alphabet_size);
  copy_array(query_counts, common_counts);
  sum_array(target_counts, common_counts);
  ARRAY_T* query_source = estimate_source(num_dirichlets, query_counts);
  ARRAY_T* target_source = estimate_source(num_dirichlets, target_counts);
  ARRAY_T* common_source = estimate_source(num_dirichlets, common_counts);
  double first_term = 0.0;
  int i_alph;
  for (i_alph = 0; i_alph < alphabet_size; i_alph++) {
    first_term += 2 * get_array_item(i_alph, common_counts) 
      * log(get_array_item(i_alph, common_source));
  }
  double second_term = 0.0;
  for (i_alph = 0; i_alph < alphabet_size; i_alph++) {
    second_term += get_array_item(i_alph, query_counts)
      * log(get_array_item(i_alph, query_source));
  }
  double third_term = 0.0;
  for (i_alph = 0; i_alph < alphabet_size; i_alph++) {
    third_term += get_array_item(i_alph, target_counts)
      * log(get_array_item(i_alph, target_source));
  }
  double fourth_term = 0.0;
  for (i_alph = 0; i_alph < alphabet_size; i_alph++) {
    fourth_term += get_array_item(i_alph, common_counts)
      * log(get_array_item(i_alph, background));
  }
  return(first_term - (second_term + third_term + fourth_term));
}
static double one_blic_score ( int num_dirichlets , ARRAY_T * query_counts , ARRAY_T * target_counts , ARRAY_T * background ) { int alphabet_size = get_array_length ( query_counts ) ; assert ( alphabet_size == 4 ) ; ARRAY_T * common_counts = allocate_array ( alphabet_size ) ; copy_array ( query_counts , common_counts ) ; sum_array ( target_counts , common_counts ) ; ARRAY_T * query_source = estimate_source ( num_dirichlets , query_counts ) ; ARRAY_T * target_source = estimate_source ( num_dirichlets , target_counts ) ; ARRAY_T * common_source = estimate_source ( num_dirichlets , common_counts ) ; double first_term = 0.0 ; int i_alph ; for ( i_alph = 0 ; i_alph < alphabet_size ; i_alph ++ ) { first_term += 2 * get_array_item ( i_alph , common_counts ) * log ( get_array_item ( i_alph , common_source ) ) ; } double second_term = 0.0 ; for ( i_alph = 0 ; i_alph < alphabet_size ; i_alph ++ ) { second_term += get_array_item ( i_alph , query_counts ) * log ( get_array_item ( i_alph , query_source ) ) ; } double third_term = 0.0 ; for ( i_alph = 0 ; i_alph < alphabet_size ; i_alph ++ ) { third_term += get_array_item ( i_alph , target_counts ) * log ( get_array_item ( i_alph , target_source ) ) ; } double fourth_term = 0.0 ; for ( i_alph = 0 ; i_alph < alphabet_size ; i_alph ++ ) { fourth_term += get_array_item ( i_alph , common_counts ) * log ( get_array_item ( i_alph , background ) ) ; } return ( first_term - ( second_term + third_term + fourth_term ) ) ; }
Computes the BLiC (Bayesian Likelihood 2-Component) score described
 by Equation (2) in Habib et al., PLoS CB 4(2):e1000010.
Computes the BLiC ( Bayesian Likelihood 2 - Component ) score described by Equation ( 2 ) in Habib et al . PLoS CB 4 ( 2 ) : e1000010 .
// Make a vector that sums the two sets of counts. // BLiC only works for DNA. // Estimate the source distributions. // First term. // Second term. // Third term. // Fourth term.