deps/kb_meme/meme-5.0.1/src/momo-modl.c
/**
 * Computes the number of bits (description length) to encode all the peptides 
 * using the given list of motifs.
 */
Computes the number of bits (description length) to encode all the peptides
using the given list of motifs.
Computes the number of bits ( description length ) to encode all the peptides using the given list of motifs .
double compute_peptides_dl(ARRAYLST_T* regexmotifs,
                           MATRIX_T* bg_freqs,
                           int max_motifs,
                           MOMO_OPTIONS_T* options,
                           SUMMARY_T* summary,
                           MOD_INFO_T* mod_info) {
  const char* alph_letters = summary->alph_letters;
  int i;
  int j;
  int k;
  int width_no_center = options->width - 1;
  double result = 0.0;
  double num_motifs = 0.0;
  for (i = 0; i < arraylst_size(regexmotifs); ++i) {
    num_motifs = num_motifs + 1.0;
  }
  for (i = 0; i < arraylst_size(mod_info->seq_list); ++i) {
    SEQ_T* seq_object = (SEQ_T*) ((options->eliminate_repeat_width) ? hash_get_entry_value(arraylst_get(i, mod_info->seq_list)) : arraylst_get(i, mod_info->seq_list));
    char* sequence = get_raw_sequence(seq_object);
    result += 1.0;
    bool has_motif = false;
    bool within_sequence[arraylst_size(regexmotifs)];
    for (j = 0; j < arraylst_size(regexmotifs); ++j) {
      within_sequence[j] = sequence_contains_regexmotif(arraylst_get(j, regexmotifs), sequence, options, summary);
      if (within_sequence[j]) {
        has_motif = true;
      }
    }
    result += has_motif ? num_motifs : 0;
    for (j = 0; j < width_no_center; ++j) {
      int char_idx = (j < width_no_center / 2) ? j : j+1;
      int min_length_residues_list = 0;
      for (k = 0; k < arraylst_size(regexmotifs); ++k) {
        REGEX_MOTIF_T* regexmotif = arraylst_get(k,regexmotifs);
        if (within_sequence[k] && regexmotif->conserved[j]) {
          char* alph_letters_substring = strchr(alph_letters, sequence[char_idx]);
          if (alph_letters_substring) {
            int aa_idx = alph_letters_substring - alph_letters;
            if (get_matrix_cell(j, aa_idx, regexmotif->residues) == 1.0) {
              int residues_length = get_residues_length(regexmotif, summary, j);
              if (min_length_residues_list == 0 || residues_length < min_length_residues_list) {
                min_length_residues_list = residues_length;
              }
            }
          }
        }
      }
      if (min_length_residues_list == 0) {
        if (strchr(alph_letters, sequence[char_idx])) {
          result -= log(get_matrix_cell(char_idx, strchr(alph_letters, sequence[char_idx]) - alph_letters, bg_freqs)) / log(2);
        }
      } else {
        result += log(min_length_residues_list) / log(2);
      }
    }
  }
  return result;
}
double compute_peptides_dl ( ARRAYLST_T * regexmotifs , MATRIX_T * bg_freqs , int max_motifs , MOMO_OPTIONS_T * options , SUMMARY_T * summary , MOD_INFO_T * mod_info ) { const char * alph_letters = summary -> alph_letters ; int i ; int j ; int k ; int width_no_center = options -> width - 1 ; double result = 0.0 ; double num_motifs = 0.0 ; for ( i = 0 ; i < arraylst_size ( regexmotifs ) ; ++ i ) { num_motifs = num_motifs + 1.0 ; } for ( i = 0 ; i < arraylst_size ( mod_info -> seq_list ) ; ++ i ) { SEQ_T * seq_object = ( SEQ_T * ) ( ( options -> eliminate_repeat_width ) ? hash_get_entry_value ( arraylst_get ( i , mod_info -> seq_list ) ) : arraylst_get ( i , mod_info -> seq_list ) ) ; char * sequence = get_raw_sequence ( seq_object ) ; result += 1.0 ; bool has_motif = false ; bool within_sequence [ arraylst_size ( regexmotifs ) ] ; for ( j = 0 ; j < arraylst_size ( regexmotifs ) ; ++ j ) { within_sequence [ j ] = sequence_contains_regexmotif ( arraylst_get ( j , regexmotifs ) , sequence , options , summary ) ; if ( within_sequence [ j ] ) { has_motif = true ; } } result += has_motif ? num_motifs : 0 ; for ( j = 0 ; j < width_no_center ; ++ j ) { int char_idx = ( j < width_no_center / 2 ) ? j : j + 1 ; int min_length_residues_list = 0 ; for ( k = 0 ; k < arraylst_size ( regexmotifs ) ; ++ k ) { REGEX_MOTIF_T * regexmotif = arraylst_get ( k , regexmotifs ) ; if ( within_sequence [ k ] && regexmotif -> conserved [ j ] ) { char * alph_letters_substring = strchr ( alph_letters , sequence [ char_idx ] ) ; if ( alph_letters_substring ) { int aa_idx = alph_letters_substring - alph_letters ; if ( get_matrix_cell ( j , aa_idx , regexmotif -> residues ) == 1.0 ) { int residues_length = get_residues_length ( regexmotif , summary , j ) ; if ( min_length_residues_list == 0 || residues_length < min_length_residues_list ) { min_length_residues_list = residues_length ; } } } } } if ( min_length_residues_list == 0 ) { if ( strchr ( alph_letters , sequence [ char_idx ] ) ) { result -= log ( get_matrix_cell ( char_idx , strchr ( alph_letters , sequence [ char_idx ] ) - alph_letters , bg_freqs ) ) / log ( 2 ) ; } } else { result += log ( min_length_residues_list ) / log ( 2 ) ; } } } return result ; }
Computes the number of bits (description length) to encode all the peptides
 using the given list of motifs.
Computes the number of bits ( description length ) to encode all the peptides using the given list of motifs .
// we want to compute a dl for each peptide // number of motifs // for each peptide // number of bits to store does this sequence contain motifs? // which of the motifs are in this sequence? // cost of each residue // get min_length_residues_list // cost of residue using min_length_residue_list