deps/kb_meme/meme-5.0.1/src/momo-modl.c
/**
 * Converts a regexmotif to a string representation.
 */
Converts a regexmotif to a string representation.
Converts a regexmotif to a string representation .
char* regexmotif_to_string(REGEX_MOTIF_T* regexmotif,
                           MOD_INFO_T* mod_info,
                           SUMMARY_T* summary,
                           MOMO_OPTIONS_T* options) {
  int i;
  int j;
  const char* alph_letters = summary->alph_letters;
  int width_no_center = options->width - 1;
  int required_length = 3 + strlen(mod_info->mod_name);
  for (i=0; i < width_no_center; ++i) {
    int residues_length = (regexmotif->conserved[i]) ? get_residues_length(regexmotif, summary, i) : 0;
    if (residues_length == 0 || residues_length == 1) {
      required_length++;
    } else {
      required_length += residues_length + 2;
    }
  }
  char* result = mm_malloc(required_length);
  result[0] = '\0';
  for (i = 0; i < options->width; ++i) {
    int idx_no_center = (i < width_no_center / 2) ? i : i - 1;
    if (i == options->width / 2) {
      strncat(result, "_", 1);
      strncat(result, mod_info->mod_name, strlen(mod_info->mod_name));
      strncat(result, "_", 1);
    } else if (!regexmotif->conserved[idx_no_center]) {
      strncat(result, "X", 1);
    } else {
      int residues_length = get_residues_length(regexmotif, summary, idx_no_center);
      if (residues_length > 1) {
        strncat(result, "[", 1);
      }
      for (j = 0; j < strlen(alph_letters); ++j) {
        if (get_matrix_cell(idx_no_center, j, regexmotif->residues) == 1.0) {
          strncat(result, &alph_letters[j], 1);
        }
      }
      if (residues_length > 1) {
        strncat(result, "]", 1);
      }
    }
  }
  return result;
}
char * regexmotif_to_string ( REGEX_MOTIF_T * regexmotif , MOD_INFO_T * mod_info , SUMMARY_T * summary , MOMO_OPTIONS_T * options ) { int i ; int j ; const char * alph_letters = summary -> alph_letters ; int width_no_center = options -> width - 1 ; int required_length = 3 + strlen ( mod_info -> mod_name ) ; for ( i = 0 ; i < width_no_center ; ++ i ) { int residues_length = ( regexmotif -> conserved [ i ] ) ? get_residues_length ( regexmotif , summary , i ) : 0 ; if ( residues_length == 0 || residues_length == 1 ) { required_length ++ ; } else { required_length += residues_length + 2 ; } } char * result = mm_malloc ( required_length ) ; result [ 0 ] = ' \0 ' ; for ( i = 0 ; i < options -> width ; ++ i ) { int idx_no_center = ( i < width_no_center / 2 ) ? i : i - 1 ; if ( i == options -> width / 2 ) { strncat ( result , " " , 1 ) ; strncat ( result , mod_info -> mod_name , strlen ( mod_info -> mod_name ) ) ; strncat ( result , " " , 1 ) ; } else if ( ! regexmotif -> conserved [ idx_no_center ] ) { strncat ( result , " " , 1 ) ; } else { int residues_length = get_residues_length ( regexmotif , summary , idx_no_center ) ; if ( residues_length > 1 ) { strncat ( result , " " , 1 ) ; } for ( j = 0 ; j < strlen ( alph_letters ) ; ++ j ) { if ( get_matrix_cell ( idx_no_center , j , regexmotif -> residues ) == 1.0 ) { strncat ( result , & alph_letters [ j ] , 1 ) ; } } if ( residues_length > 1 ) { strncat ( result , " " , 1 ) ; } } } return result ; }
Converts a regexmotif to a string representation.
Converts a regexmotif to a string representation .
// Required Length // the length of mod/center // 2 for _ surrounding mod/center // 1 for the '\0' character // 1 for non-conserved or single lettered positions // length + 2 for positions with multi residues (to encode []) // motif string creation