deps/kb_meme/meme-5.0.1/src/mhmm.c
/***********************************************************************
 * Discard motifs that are not connected.
 ***********************************************************************/
Discard motifs that are not connected.
Discard motifs that are not connected .
static void throw_out_unused_motifs
  (RBTREE_T *motifs,
   MATRIX_T *transp_freq,
   MATRIX_T *spacer_ave)
{
  int i_motif_loc, j_motif;
  ARRAY_T* row_sums;
  ARRAY_T* col_sums;
  RBNODE_T *node, *next_node;
  row_sums = get_matrix_row_sums(transp_freq);
  col_sums = get_matrix_col_sums(transp_freq);
  for (i_motif_loc = 1, node = rbtree_first(motifs); 
      node != NULL; node = next_node, i_motif_loc++) {
    next_node = rbtree_next(node);
    if ((get_array_item(i_motif_loc, row_sums) == 0.0) ||
      (get_array_item(i_motif_loc, col_sums) == 0.0)) {
      if (verbosity >= NORMAL_VERBOSE) {
        fprintf(stderr, "Removing unused motif %s. "
            "No occurrences of this motif were found.\n",
            get_motif_st_id((MOTIF_T*)rbtree_value(node)));
      }
      remove_matrix_row(i_motif_loc, transp_freq);
      remove_matrix_col(i_motif_loc, transp_freq);
      assert(get_num_rows(transp_freq) == get_num_cols(transp_freq));
      remove_matrix_row(i_motif_loc, spacer_ave);
      remove_matrix_col(i_motif_loc, spacer_ave);
      assert(get_num_rows(spacer_ave) == get_num_cols(spacer_ave));
      rbtree_delete(motifs, node, NULL, NULL);
      i_motif_loc--;
      free_array(row_sums);
      free_array(col_sums);
      row_sums = get_matrix_row_sums(transp_freq);
      col_sums = get_matrix_col_sums(transp_freq);
    }
  }
  free_array(row_sums);
  free_array(col_sums);
}
static void throw_out_unused_motifs ( RBTREE_T * motifs , MATRIX_T * transp_freq , MATRIX_T * spacer_ave ) { int i_motif_loc , j_motif ; ARRAY_T * row_sums ; ARRAY_T * col_sums ; RBNODE_T * node , * next_node ; row_sums = get_matrix_row_sums ( transp_freq ) ; col_sums = get_matrix_col_sums ( transp_freq ) ; for ( i_motif_loc = 1 , node = rbtree_first ( motifs ) ; node != NULL ; node = next_node , i_motif_loc ++ ) { next_node = rbtree_next ( node ) ; if ( ( get_array_item ( i_motif_loc , row_sums ) == 0.0 ) || ( get_array_item ( i_motif_loc , col_sums ) == 0.0 ) ) { if ( verbosity >= NORMAL_VERBOSE ) { fprintf ( stderr , " " " \n " , get_motif_st_id ( ( MOTIF_T * ) rbtree_value ( node ) ) ) ; } remove_matrix_row ( i_motif_loc , transp_freq ) ; remove_matrix_col ( i_motif_loc , transp_freq ) ; assert ( get_num_rows ( transp_freq ) == get_num_cols ( transp_freq ) ) ; remove_matrix_row ( i_motif_loc , spacer_ave ) ; remove_matrix_col ( i_motif_loc , spacer_ave ) ; assert ( get_num_rows ( spacer_ave ) == get_num_cols ( spacer_ave ) ) ; rbtree_delete ( motifs , node , NULL , NULL ) ; i_motif_loc -- ; free_array ( row_sums ) ; free_array ( col_sums ) ; row_sums = get_matrix_row_sums ( transp_freq ) ; col_sums = get_matrix_col_sums ( transp_freq ) ; } } free_array ( row_sums ) ; free_array ( col_sums ) ; }
Discard motifs that are not connected.
Discard motifs that are not connected .
// Extract the margins of the transition matrix. // calculate the next node before we delete anything // Is this row or column empty? // Remove the row and column from the transition matrix. // Remove the motif from the tree // Recalculate the row and column sums.