deps/kb_meme/meme-5.0.1/src/seq-reader-from-fasta.c
/******************************************************************************
 * This function attempts to parse the sequence name from the
 * current sequence header. The sequence name is the string up to the first
 * white space in the sequence header.
 *
 * Returns true if it was able to genomic coordinates, false otherwise.
 *****************************************************************************/
This function attempts to parse the sequence name from the
current sequence header. The sequence name is the string up to the first
white space in the sequence header.

Returns true if it was able to genomic coordinates, false otherwise.
This function attempts to parse the sequence name from the current sequence header . The sequence name is the string up to the first white space in the sequence header . Returns true if it was able to genomic coordinates false otherwise .
static bool parse_seq_name(
  SEQ_READER_FROM_FASTA_T *fasta_reader
) {
  #define NUM_SUBMATCHES 2
  #define ERROR_MESSAGE_SIZE 100
  #define BUFFER_SIZE 512
  static bool first_time = true;
  static regex_t ucsc_header_regex;
  static regmatch_t matches[NUM_SUBMATCHES];
  char error_message[ERROR_MESSAGE_SIZE];
  int status = 0;
  if (first_time == true) {
    char *regexp_str = fasta_reader->parse_genomic_coord ?
      "([^[:space:]:]+)[[:space:]]*" : "([^[:space:]]+)[[:space:]]*";
    status = regcomp(
      &ucsc_header_regex,
      regexp_str,
      REG_EXTENDED | REG_ICASE | REG_NEWLINE
    );
    if (status != 0) {
      regerror(status, &ucsc_header_regex, error_message, ERROR_MESSAGE_SIZE);
      die(
        "Error while intitializing regular expression\n"
        "for parsing sequence name from FASTA header: %s\n", 
        error_message
      );
    }
    first_time = false;
  }
  bool found_name = false;
  char* header = fasta_reader->seq_header;
  status = regexec(
    &ucsc_header_regex, 
    header,
    NUM_SUBMATCHES, 
    matches, 
    0
  );
  if(!status) {
    found_name = 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;
    if (fasta_reader->seq_name) {
      myfree(fasta_reader->seq_name);
      fasta_reader->seq_name = NULL;
    }
    fasta_reader->seq_name = strdup(buffer);
    if (fasta_reader->seq_name == NULL) {
      die("Unable to allocate memory while parsing sequence header.\n");
    }
    fasta_reader->seq_name_len = name_len;
  }
  else if(status != REG_NOMATCH ){
    regerror(status, &ucsc_header_regex, error_message, 100);
    die("Error trying to parse name from sequence header: %s\n"
        "error message is %s\n",
        header, 
        error_message
    );
  }
  else {
    found_name = false;
  }
  return found_name;
  #undef NUM_SUBMATCHES
  #undef ERROR_MESSAGE_SIZE
  #undef BUFFER_SIZE
}
static bool parse_seq_name ( SEQ_READER_FROM_FASTA_T * fasta_reader ) { #define NUM_SUBMATCHES  2 #define ERROR_MESSAGE_SIZE  100 #define BUFFER_SIZE  512 static bool first_time = true ; static regex_t ucsc_header_regex ; static regmatch_t matches [ NUM_SUBMATCHES ] ; char error_message [ ERROR_MESSAGE_SIZE ] ; int status = 0 ; if ( first_time == true ) { char * regexp_str = fasta_reader -> parse_genomic_coord ? " " : " " ; status = regcomp ( & ucsc_header_regex , regexp_str , REG_EXTENDED | REG_ICASE | REG_NEWLINE ) ; if ( status != 0 ) { regerror ( status , & ucsc_header_regex , error_message , ERROR_MESSAGE_SIZE ) ; die ( " \n " " \n " , error_message ) ; } first_time = false ; } bool found_name = false ; char * header = fasta_reader -> seq_header ; status = regexec ( & ucsc_header_regex , header , NUM_SUBMATCHES , matches , 0 ) ; if ( ! status ) { found_name = 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 ; if ( fasta_reader -> seq_name ) { myfree ( fasta_reader -> seq_name ) ; fasta_reader -> seq_name = NULL ; } fasta_reader -> seq_name = strdup ( buffer ) ; if ( fasta_reader -> seq_name == NULL ) { die ( " \n " ) ; } fasta_reader -> seq_name_len = name_len ; } else if ( status != REG_NOMATCH ) { regerror ( status , & ucsc_header_regex , error_message , 100 ) ; die ( " \n " " \n " , header , error_message ) ; } else { found_name = false ; } return found_name ; #undef  NUM_SUBMATCHES #undef  ERROR_MESSAGE_SIZE #undef  BUFFER_SIZE }
This function attempts to parse the sequence name from the
 current sequence header.
This function attempts to parse the sequence name from the current sequence header .
// Initialize regular express for extracting chromsome coordinates; // Expected format is based on fastaFromBed name:start-stop[(+|-)][_id] // e.g., ">chr1:1000-1010(-)_xyz" // The sequence header contains genomic coordinates // Copy sequence name to reader