Beispiel #1
0
void* dxml_create(const char *optional_filename, int options) {
    DXML_T *parser;
    // allocate the structure to hold the parser information
    parser = (DXML_T*)mm_malloc(sizeof(DXML_T));
    // setup data store
    parser->data = create_parser_data(options, optional_filename);
    // setup meme xml callbacks
    parser->callbacks = (DREME_IO_XML_CALLBACKS_T*)mm_malloc(sizeof(DREME_IO_XML_CALLBACKS_T));
    memset(parser->callbacks, 0, sizeof(DREME_IO_XML_CALLBACKS_T));
    //start callbacks
    parser->callbacks->error = dxml_error;
    parser->callbacks->start_dreme = dxml_start_dreme;
    // start dreme
    // start model
    parser->callbacks->handle_background = dxml_handle_background;
    // end model
    // start motifs
    parser->callbacks->start_motif = dxml_start_motif;
    parser->callbacks->end_motif = dxml_end_motif;
    // start motif
    parser->callbacks->handle_pos = dxml_handle_pos;
    // end motif
    // end motifs
    // end dreme
    // end callbacks
    // setup context for SAX parser
    parser->sax_context = create_dreme_io_xml_sax_context(parser->data, parser->callbacks);
    // setup SAX handler
    parser->handler = (xmlSAXHandler*)mm_malloc(sizeof(xmlSAXHandler));
    register_dreme_io_xml_sax_handlers(parser->handler);
    // create the push parser context
    parser->ctxt = xmlCreatePushParserCtxt(parser->handler, parser->sax_context, NULL, 0, optional_filename);
    return parser;
}
/*****************************************************************************
 * Create a parser for MEME's XML format.
 ****************************************************************************/
void* mxml_create(const char *optional_filename, int options) {
  MXML_T *parser;
  // allocate the structure to hold the parser information
  parser = (MXML_T*)mm_malloc(sizeof(MXML_T));
  // setup data store
  parser->data = create_parser_data(options, optional_filename);
  // setup meme xml callbacks
  parser->callbacks = (MEME_IO_XML_CALLBACKS_T*)mm_malloc(sizeof(MEME_IO_XML_CALLBACKS_T));
  memset(parser->callbacks, 0, sizeof(MEME_IO_XML_CALLBACKS_T));
  parser->callbacks->error = mxml_error;
  parser->callbacks->start_meme = mxml_start_meme;
  parser->callbacks->start_alphabet = mxml_start_alphabet;
  parser->callbacks->handle_alphabet_letter = mxml_alphabet_letter;
  parser->callbacks->end_alphabet = mxml_end_alphabet;
  parser->callbacks->handle_ambigs_letter = mxml_ambigs_letter;
  parser->callbacks->handle_strands = mxml_handle_strands;
  parser->callbacks->handle_bf_aa_value = mxml_background_value;
  parser->callbacks->end_background_frequencies = mxml_end_background;
  parser->callbacks->start_motif = mxml_start_motif;
  parser->callbacks->end_motif = mxml_end_motif;
  parser->callbacks->start_scores = mxml_start_scores;
  parser->callbacks->end_sc_am_alphabet_array = mxml_end_score_pos;
  parser->callbacks->handle_sc_am_aa_value = mxml_score_value;
  parser->callbacks->start_probabilities = mxml_start_probabilities;
  parser->callbacks->end_pr_am_alphabet_array = mxml_end_probability_pos;
  parser->callbacks->handle_pr_am_aa_value = mxml_probability_value;
  if (options & SCANNED_SITES) {
    parser->callbacks->handle_sequence = mxml_sequence;
    parser->callbacks->start_scanned_sites_summary = mxml_start_scanned_sites;
    parser->callbacks->end_scanned_sites_summary = mxml_end_scanned_sites;
    parser->callbacks->start_scanned_sites = mxml_start_scanned_seq;
    parser->callbacks->handle_scanned_site = mxml_scanned_site;
  }
  // setup context for SAX parser
  parser->sax_context = create_meme_io_xml_sax_context(parser->data, parser->callbacks);
  // setup SAX handler
  parser->handler = (xmlSAXHandler*)mm_malloc(sizeof(xmlSAXHandler));
  register_meme_io_xml_sax_handlers(parser->handler);
  // create the push parser context
  parser->ctxt = xmlCreatePushParserCtxt(parser->handler, parser->sax_context, NULL, 0, optional_filename); 
  return parser;
}