deps/kb_meme/meme-5.0.1/src/mhmm.c
/***********************************************************************
 * Convert transition counts to transition probabilities, and compute
 * average spacer lengths.
 *
 * Each matrix is indexed 0 ... n+1, where n is the number of motifs.
 * The entry at [i,j] corresponds to the transition from motif i to
 * motif j.  Hence, after normalization, each row in the transition
 * matrix should sum to 1.
 ***********************************************************************/
Convert transition counts to transition probabilities, and compute
average spacer lengths.

Each matrix is indexed 0 ... n+1, where n is the number of motifs.
The entry at [i,j] corresponds to the transition from motif i to
motif j.  Hence, after normalization, each row in the transition
matrix should sum to 1.
Convert transition counts to transition probabilities and compute average spacer lengths . Each matrix is indexed 0 ... n + 1 where n is the number of motifs . The entry at [ i j ] corresponds to the transition from motif i to motif j . Hence after normalization each row in the transition matrix should sum to 1 .
static void normalize_spacer_counts(
  double    trans_pseudo,
  double    spacer_pseudo,    
  bool keep_unused,
  MATRIX_T* transp_freq,
  MATRIX_T* spacer_ave
) {
  int i_row;
  int i_col;
  int num_rows;
  double total_spacer;
  double num_transitions;
  double ave_spacer;
  num_rows = get_num_rows(transp_freq);
  for (i_row = 0; i_row < num_rows; i_row++) {
    for (i_col = 0; i_col < num_rows; i_col++) {
      total_spacer = get_matrix_cell(i_row, i_col, spacer_ave) + spacer_pseudo;
      num_transitions = get_matrix_cell(i_row, i_col, transp_freq);
      if (spacer_pseudo > 0) num_transitions++;
      if (num_transitions != 0.0) {
        ave_spacer = total_spacer / num_transitions;
        set_matrix_cell(i_row, i_col, ave_spacer, spacer_ave);
      }
    }
  }
  for (i_row = 0; i_row < num_rows; i_row++) {
    for (i_col = 0; i_col < num_rows; i_col++) {
      if (
        (i_col == 0) || 
        (i_row == num_rows - 1) ||
        ((i_row == 0) && (i_col == num_rows - 1))) {
        set_matrix_cell(i_row, i_col, 0.0, transp_freq);
      }
      else {
        if ((keep_unused) || 
            (get_matrix_cell(i_row, i_col, transp_freq) > 0.0)) {
          incr_matrix_cell(i_row, i_col, trans_pseudo, transp_freq);
        }
      }
    }
  }
  for (i_row = 0; i_row < num_rows - 1; i_row++) {
    if (array_total(get_matrix_row(i_row, transp_freq)) > 0.0) {
      normalize(SLOP, get_matrix_row(i_row, transp_freq));
    }
  }
}
static void normalize_spacer_counts ( double trans_pseudo , double spacer_pseudo , bool keep_unused , MATRIX_T * transp_freq , MATRIX_T * spacer_ave ) { int i_row ; int i_col ; int num_rows ; double total_spacer ; double num_transitions ; double ave_spacer ; num_rows = get_num_rows ( transp_freq ) ; for ( i_row = 0 ; i_row < num_rows ; i_row ++ ) { for ( i_col = 0 ; i_col < num_rows ; i_col ++ ) { total_spacer = get_matrix_cell ( i_row , i_col , spacer_ave ) + spacer_pseudo ; num_transitions = get_matrix_cell ( i_row , i_col , transp_freq ) ; if ( spacer_pseudo > 0 ) num_transitions ++ ; if ( num_transitions != 0.0 ) { ave_spacer = total_spacer / num_transitions ; set_matrix_cell ( i_row , i_col , ave_spacer , spacer_ave ) ; } } } for ( i_row = 0 ; i_row < num_rows ; i_row ++ ) { for ( i_col = 0 ; i_col < num_rows ; i_col ++ ) { if ( ( i_col == 0 ) || ( i_row == num_rows - 1 ) || ( ( i_row == 0 ) && ( i_col == num_rows - 1 ) ) ) { set_matrix_cell ( i_row , i_col , 0.0 , transp_freq ) ; } else { if ( ( keep_unused ) || ( get_matrix_cell ( i_row , i_col , transp_freq ) > 0.0 ) ) { incr_matrix_cell ( i_row , i_col , trans_pseudo , transp_freq ) ; } } } } for ( i_row = 0 ; i_row < num_rows - 1 ; i_row ++ ) { if ( array_total ( get_matrix_row ( i_row , transp_freq ) ) > 0.0 ) { normalize ( SLOP , get_matrix_row ( i_row , transp_freq ) ) ; } } }
Convert transition counts to transition probabilities, and compute
 average spacer lengths.
Convert transition counts to transition probabilities and compute average spacer lengths .
// Pseudocount for self-loop. /* Divide the spacer lengths by the number of occurrences. */ // Add pseudocounts. // Force some transitions to zero. // No transitions to the start state. // No transitions from the end state. // No transition from start to end. // Only increment the used transitions. // Normalize rows.