deps/kb_meme/meme-5.0.1/src/prior-reader-from-psp.c
/******************************************************************************
 * This function attempts to parse genomic coordinates from the
 * current sequence header. If successful it will set the sequence
 * name to the chromosome name, and set the starting sequence position.
 *
 * Returns true if it was able to find genomic coordinates, false otherwise.
 *****************************************************************************/
This function attempts to parse genomic coordinates from the
current sequence header. If successful it will set the sequence
name to the chromosome name, and set the starting sequence position.

Returns true if it was able to find genomic coordinates, false otherwise.
This function attempts to parse genomic coordinates from the current sequence header . If successful it will set the sequence name to the chromosome name and set the starting sequence position . Returns true if it was able to find genomic coordinates false otherwise .
static bool parse_genomic_coordinates(
  PSP_DATA_BLOCK_READER_T *psp_reader
) {
  #define NUM_SUBMATCHES 4
  #define ERROR_MESSAGE_SIZE 100
  #define BUFFER_SIZE 512
  static bool first_time = true;
  static regex_t fasta_header_regex;
  static regmatch_t matches[NUM_SUBMATCHES];
  char error_message[ERROR_MESSAGE_SIZE];
  int status = 0;
  if (first_time == true) {
    status = regcomp(
      &fasta_header_regex, 
      "[[:space:]]*([^[:space:]:]+):([[:digit:]]+)-([[:digit:]]+)", 
      REG_EXTENDED | REG_ICASE | REG_NEWLINE
    );
    if (status != 0) {
      regerror(status, &fasta_header_regex, error_message, ERROR_MESSAGE_SIZE);
      die(
        "Error while intitializing regular expression\n"
        "for parsing genome coordinates from FASTA header: %s\n", 
        error_message
      );
    }
    first_time = false;
  }
  bool found_coordinates = false;
  char* header = psp_reader->sequence_header;
  status = regexec(
    &fasta_header_regex, 
    header,
    NUM_SUBMATCHES, 
    matches, 
    0
  );
  if(!status) {
    found_coordinates = true;
    char buffer[BUFFER_SIZE];
    int name_len = matches[1].rm_eo - matches[1].rm_so;
    strncpy(buffer, header + matches[1].rm_so, name_len);
    buffer[name_len] = 0;
    psp_reader->sequence_name = strdup(buffer);
    if (psp_reader->sequence_name == NULL) {
      die("Unable to allocate memory while parsing sequence header.\n");
    }
    psp_reader->sequence_name_len = name_len;
    size_t pos_len = matches[2].rm_eo - matches[2].rm_so;
    strncpy(buffer, header + matches[2].rm_so, pos_len);
    buffer[pos_len] = 0;
    psp_reader->current_position = atol(buffer) - 1;
  }
  else if(status != REG_NOMATCH ){
    regerror(status, &fasta_header_regex, error_message, 100);
    die("Error trying to parse genome coordinates from sequence header: %s\n"
        "error message is %s\n",
        header, 
        error_message
    );
  }
  else {
    found_coordinates = false;
  }
  return found_coordinates;
  #undef NUM_SUBMATCHES
  #undef ERROR_MESSAGE_SIZE
  #undef BUFFER_SIZE
}
static bool parse_genomic_coordinates ( PSP_DATA_BLOCK_READER_T * psp_reader ) { #define NUM_SUBMATCHES  4 #define ERROR_MESSAGE_SIZE  100 #define BUFFER_SIZE  512 static bool first_time = true ; static regex_t fasta_header_regex ; static regmatch_t matches [ NUM_SUBMATCHES ] ; char error_message [ ERROR_MESSAGE_SIZE ] ; int status = 0 ; if ( first_time == true ) { status = regcomp ( & fasta_header_regex , " " , REG_EXTENDED | REG_ICASE | REG_NEWLINE ) ; if ( status != 0 ) { regerror ( status , & fasta_header_regex , error_message , ERROR_MESSAGE_SIZE ) ; die ( " \n " " \n " , error_message ) ; } first_time = false ; } bool found_coordinates = false ; char * header = psp_reader -> sequence_header ; status = regexec ( & fasta_header_regex , header , NUM_SUBMATCHES , matches , 0 ) ; if ( ! status ) { found_coordinates = true ; char buffer [ BUFFER_SIZE ] ; int name_len = matches [ 1 ] . rm_eo - matches [ 1 ] . rm_so ; strncpy ( buffer , header + matches [ 1 ] . rm_so , name_len ) ; buffer [ name_len ] = 0 ; psp_reader -> sequence_name = strdup ( buffer ) ; if ( psp_reader -> sequence_name == NULL ) { die ( " \n " ) ; } psp_reader -> sequence_name_len = name_len ; size_t pos_len = matches [ 2 ] . rm_eo - matches [ 2 ] . rm_so ; strncpy ( buffer , header + matches [ 2 ] . rm_so , pos_len ) ; buffer [ pos_len ] = 0 ; psp_reader -> current_position = atol ( buffer ) - 1 ; } else if ( status != REG_NOMATCH ) { regerror ( status , & fasta_header_regex , error_message , 100 ) ; die ( " \n " " \n " , header , error_message ) ; } else { found_coordinates = false ; } return found_coordinates ; #undef  NUM_SUBMATCHES #undef  ERROR_MESSAGE_SIZE #undef  BUFFER_SIZE }
This function attempts to parse genomic coordinates from the
 current sequence header.
This function attempts to parse genomic coordinates from the current sequence header .
// Initialize regular express for extracting chromsome coordinates; // Expected format is name:start-stop // The sequence header contains genomic coordinates // Copy chromosome name and position to reader