deps/kb_meme/meme-5.0.1/src/order.c
/***********************************************************************
 * Create an order-and-spacing object from a user-specified string.
 * <spacer>=<strand><motif #>=<spacer>=<strand><motif #>=<spacer>
 * eg
 * 5=+1=12=-1=15
 ***********************************************************************/
Create an order-and-spacing object from a user-specified string.
Create an order - and - spacing object from a user - specified string .
ORDER_T* create_order
  (const char* order_string)
{
  ORDER_T* order;
  int num_equals, i, i_spacer, i_motif, motif;
  regex_t regex_sp_eq, regex_mn_eq, regex_sp;
  regmatch_t matches[2];
  const char *str;
  if (order_string == NULL) {
    return NULL;
  }
  regcomp_or_die("<spacer>=", &regex_sp_eq, 
      "^[[:space:]]*([0-9]+)[[:space:]]*=", REG_EXTENDED);
  regcomp_or_die("<motif #>=", &regex_mn_eq, 
      "^[[:space:]]*([+-]?[0-9]+)[[:space:]]*=", REG_EXTENDED);
  regcomp_or_die("<spacer>", &regex_sp, 
      " ^[[:space:]]*([0-9]+)[[:space:]]*$", REG_EXTENDED);
  for (str = order_string, num_equals = 0; *str != '\0'; ++str) {
    if (*str == '=') ++num_equals;
  }
  if (num_equals % 2 != 0) die("Error reading order and spacing. "
      "The spacing string must have an even number of seperators (=).");
  order = create_empty_order(num_equals / 2, 0.0);
  str = order_string;
  i_spacer = 0;
  i_motif = 0;
  for (i = 0; i < num_equals; i++) {
    if ((i % 2) == 0) { 
      if (regexec_or_die("spacer", &regex_sp_eq, str, 2, matches, 0)) {
        order->motif_spacers[i_spacer++] = regex_int(matches+1, str, 0);
      } else {
        die("Error reading order and spacing at spacer %d.\n", i_spacer + 1);
      }
    } else { 
      if (regexec_or_die("motif num", &regex_mn_eq, str, 2, matches, 0)) {
        motif = regex_int(matches+1, str, 0);
        if (motif == 0 || motif == END_TRANSITION) 
          die("Error reading order and spacing at motif %d.\n", i_motif + 1);
        order->motif_occurs[i_motif++] = motif;
        order->num_occurs += 1;
        rbtree_make(order->distinct, &motif, NULL);
      } else {
        die("Error reading order and spacing at motif %d.\n", i_motif + 1);
      }
    }
    str += matches[0].rm_eo;
  }
  if (regexec_or_die("spacer", &regex_sp, str, 2, matches, 0)) {
    order->motif_spacers[i_spacer++] = regex_int(matches+1, str, 0);
  } else {
    die("Error reading order and spacing at spacer %d.\n", i_spacer + 1);
  }
  assert((order->num_alloc == order->num_occurs));
  if (verbosity >= NORMAL_VERBOSE) {
    fprintf(stderr, "Using order: ");
    print_order_and_spacing(stderr, order);
  }
  return(order);
}
ORDER_T * create_order ( const char * order_string ) { ORDER_T * order ; int num_equals , i , i_spacer , i_motif , motif ; regex_t regex_sp_eq , regex_mn_eq , regex_sp ; regmatch_t matches [ 2 ] ; const char * str ; if ( order_string == NULL ) { return NULL ; } regcomp_or_die ( " " , & regex_sp_eq , " " , REG_EXTENDED ) ; regcomp_or_die ( " " , & regex_mn_eq , " " , REG_EXTENDED ) ; regcomp_or_die ( " " , & regex_sp , " " , REG_EXTENDED ) ; for ( str = order_string , num_equals = 0 ; * str != ' \0 ' ; ++ str ) { if ( * str == ' ' ) ++ num_equals ; } if ( num_equals % 2 != 0 ) die ( " " " " ) ; order = create_empty_order ( num_equals / 2 , 0.0 ) ; str = order_string ; i_spacer = 0 ; i_motif = 0 ; for ( i = 0 ; i < num_equals ; i ++ ) { if ( ( i % 2 ) == 0 ) { if ( regexec_or_die ( " " , & regex_sp_eq , str , 2 , matches , 0 ) ) { order -> motif_spacers [ i_spacer ++ ] = regex_int ( matches + 1 , str , 0 ) ; } else { die ( " \n " , i_spacer + 1 ) ; } } else { if ( regexec_or_die ( " " , & regex_mn_eq , str , 2 , matches , 0 ) ) { motif = regex_int ( matches + 1 , str , 0 ) ; if ( motif == 0 || motif == END_TRANSITION ) die ( " \n " , i_motif + 1 ) ; order -> motif_occurs [ i_motif ++ ] = motif ; order -> num_occurs += 1 ; rbtree_make ( order -> distinct , & motif , NULL ) ; } else { die ( " \n " , i_motif + 1 ) ; } } str += matches [ 0 ] . rm_eo ; } if ( regexec_or_die ( " " , & regex_sp , str , 2 , matches , 0 ) ) { order -> motif_spacers [ i_spacer ++ ] = regex_int ( matches + 1 , str , 0 ) ; } else { die ( " \n " , i_spacer + 1 ) ; } assert ( ( order -> num_alloc == order -> num_occurs ) ) ; if ( verbosity >= NORMAL_VERBOSE ) { fprintf ( stderr , " " ) ; print_order_and_spacing ( stderr , order ) ; } return ( order ) ; }
Create an order-and-spacing object from a user-specified string.
Create an order - and - spacing object from a user - specified string .
// Don't do anything if no string was given.  // Allocate the data structure.  // spacer // motif // Tell the user. 