deps/kb_meme/meme-5.0.1/src/tomtom.c
/**************************************************************************
 * Computes Kullback-Leiber for all columns of the query matrix against target
 * motif. Note we use
 * a modified Kullback-leibler for computing single column scores. We do not
 * divide the score by the width. This division is replaced by our DP based
 * p-value computation.
 **************************************************************************/
Computes Kullback-Leiber for all columns of the query matrix against target
motif. Note we use
a modified Kullback-leibler for computing single column scores. We do not
divide the score by the width. This division is replaced by our DP based
p-value computation.
Computes Kullback - Leiber for all columns of the query matrix against target motif . Note we use a modified Kullback - leibler for computing single column scores . We do not divide the score by the width . This division is replaced by our DP based p - value computation .
void kullback_scores(
    MOTIF_T* query_motif,
    MOTIF_T* target_motif,
    ARRAY_T* background,
    int offset,
    MATRIX_T** score
    ) {
  int index_query;
  int index_target;
  for (index_query = 0; index_query < get_motif_length(query_motif); index_query++) {
    for (index_target = 0; index_target < get_motif_length(target_motif); index_target++) {
      double SCORE_F = 0;
      int index; 
      for (index = 0; index < get_motif_alph_size(query_motif); index++) {
        double query_freq
          = get_matrix_cell(index_query, index, get_motif_freqs(query_motif));
        double target_freq
          = get_matrix_cell(index_target, index, get_motif_freqs(target_motif));
        double avg_kull;
        avg_kull = ((query_freq * log10(query_freq/target_freq))
            + (target_freq * log10(target_freq/query_freq))) / 2;
        SCORE_F = SCORE_F + avg_kull;
      }
      SCORE_F = SCORE_F * -1;
      set_matrix_cell(index_query, offset + index_target, SCORE_F, *score);
    } 
  } 
}
void kullback_scores ( MOTIF_T * query_motif , MOTIF_T * target_motif , ARRAY_T * background , int offset , MATRIX_T * * score ) { int index_query ; int index_target ; for ( index_query = 0 ; index_query < get_motif_length ( query_motif ) ; index_query ++ ) { for ( index_target = 0 ; index_target < get_motif_length ( target_motif ) ; index_target ++ ) { double SCORE_F = 0 ; int index ; for ( index = 0 ; index < get_motif_alph_size ( query_motif ) ; index ++ ) { double query_freq = get_matrix_cell ( index_query , index , get_motif_freqs ( query_motif ) ) ; double target_freq = get_matrix_cell ( index_target , index , get_motif_freqs ( target_motif ) ) ; double avg_kull ; avg_kull = ( ( query_freq * log10 ( query_freq / target_freq ) ) + ( target_freq * log10 ( target_freq / query_freq ) ) ) / 2 ; SCORE_F = SCORE_F + avg_kull ; } SCORE_F = SCORE_F * -1 ; set_matrix_cell ( index_query , offset + index_target , SCORE_F , * score ) ; } } }
Computes Kullback-Leiber for all columns of the query matrix against target
 motif.
Computes Kullback - Leiber for all columns of the query matrix against target motif .
/*   Recurse pairwise over the columns */ /* Index corresponds to the alphabets. */ /* Average Kullback */ /* Target motif */ /* Query motif */