deps/kb_meme/meme-5.0.1/src/momo-motifx.c
/**
 * Recursive function. While there is a significant position/residue pair,
 * will update pattern and return a count matrix for this pattern.
 */
Recursive function. While there is a significant position/residue pair,
will update pattern and return a count matrix for this pattern.
Recursive function . While there is a significant position / residue pair will update pattern and return a count matrix for this pattern .
MATRIX_T* add_to_pattern(char* pattern,
                         ARRAYLST_T* phospho_seqs,
                         ARRAYLST_T* bg_seqs,
                         MOTIFX_STATUS_T** phospho_status,
                         MOTIFX_STATUS_T** bg_status,
                         int* num_active,
                         int* num_bg_active,
                         MATRIX_T* phospho_count,
                         MATRIX_T* bg_count,
                         double* motif_score,
                         SUMMARY_T* summary,
                         MOMO_OPTIONS_T* options) {
  int i;
  const char* alph_letters = summary->alph_letters;
  MATRIX_T* binomial = duplicate_matrix(bg_count);	
  normalize_rows(0.0, binomial);			
  convert_bg_freqs_to_binomial(phospho_count, binomial, *num_active, options->harvard);
  int row_idx = -1;
  int col_idx = -1;
  double minimum = NAN;
  find_most_significant_within_matrix(binomial, phospho_count, &row_idx, &col_idx, &minimum, summary, options);
  free_matrix(binomial);
  if (row_idx >= 0 && col_idx >= 0) {
    pattern[row_idx] = alph_letters[col_idx];
    *motif_score = *motif_score - (minimum / log(10));
    double num_active_save = *num_active;
    remove_sequences_and_update_matrix(alph_letters[col_idx],
                                       row_idx,
                                       phospho_seqs,
                                       phospho_status,
                                       num_active,
                                       phospho_count,
                                       summary,
                                       options);
    if (num_active_save != *num_active) {
      remove_sequences_and_update_matrix(alph_letters[col_idx],
					 row_idx,
					 bg_seqs,
					 bg_status,
					 num_bg_active,
					 bg_count,
					 summary,
					 options);
      return add_to_pattern(pattern,
			    phospho_seqs,
			    bg_seqs,
			    phospho_status,
			    bg_status,
			    num_active,
			    num_bg_active,
			    phospho_count,
			    bg_count,
			    motif_score,
			    summary,
                            options);
    }
  }
  return phospho_count;
}
MATRIX_T * add_to_pattern ( char * pattern , ARRAYLST_T * phospho_seqs , ARRAYLST_T * bg_seqs , MOTIFX_STATUS_T * * phospho_status , MOTIFX_STATUS_T * * bg_status , int * num_active , int * num_bg_active , MATRIX_T * phospho_count , MATRIX_T * bg_count , double * motif_score , SUMMARY_T * summary , MOMO_OPTIONS_T * options ) { int i ; const char * alph_letters = summary -> alph_letters ; MATRIX_T * binomial = duplicate_matrix ( bg_count ) ; normalize_rows ( 0.0 , binomial ) ; convert_bg_freqs_to_binomial ( phospho_count , binomial , * num_active , options -> harvard ) ; int row_idx = -1 ; int col_idx = -1 ; double minimum = NAN ; find_most_significant_within_matrix ( binomial , phospho_count , & row_idx , & col_idx , & minimum , summary , options ) ; free_matrix ( binomial ) ; if ( row_idx >= 0 && col_idx >= 0 ) { pattern [ row_idx ] = alph_letters [ col_idx ] ; * motif_score = * motif_score - ( minimum / log ( 10 ) ) ; double num_active_save = * num_active ; remove_sequences_and_update_matrix ( alph_letters [ col_idx ] , row_idx , phospho_seqs , phospho_status , num_active , phospho_count , summary , options ) ; if ( num_active_save != * num_active ) { remove_sequences_and_update_matrix ( alph_letters [ col_idx ] , row_idx , bg_seqs , bg_status , num_bg_active , bg_count , summary , options ) ; return add_to_pattern ( pattern , phospho_seqs , bg_seqs , phospho_status , bg_status , num_active , num_bg_active , phospho_count , bg_count , motif_score , summary , options ) ; } } return phospho_count ; }
Recursive function.
Recursive function .
// Set binomial to bg count, normalize to frequencies, and then convert it into a binomial matrix // at this point it is a bg count matrix // at this point it is a bg freq matrix // Find minimum, and update if passes thresholds. // clean up binomial after usage. // If one of the position/residue pairs pass, update pattern and statuses, then try to add another character to the pattern. // remove sequences an update matrices for phospho and bg