deps/kb_meme/meme-5.0.1/src/xml-util.c
/***********************************************************************
 * Read the background letter frequencies from XML.
 * Caller is responsible for freeing the returned array.
 ***********************************************************************/
Read the background letter frequencies from XML.
Caller is responsible for freeing the returned array.
Read the background letter frequencies from XML . Caller is responsible for freeing the returned array .
ARRAY_T* read_bg_freqs_from_xml(xmlXPathContextPtr xpath_ctxt, ALPH_T* alph) {
  xmlXPathObjectPtr xpathObj = NULL;
  ATYPE    value;
  ARRAY_T* bg_freqs;
  int a_size = alph_size_core(alph);
  xpathObj = xpath_query(
    xpath_ctxt, 
    "//*/background_frequencies/alphabet_array/value"
  );
  int num_values = (xpathObj->nodesetval ? xpathObj->nodesetval->nodeNr : 0);
  xmlXPathFreeObject(xpathObj);
  assert(num_values == a_size);
  bg_freqs= allocate_array(alph_size_full(alph));
  const int MAX_XPATH_EXPRESSION = 200;
  char xpath_expression[MAX_XPATH_EXPRESSION];
  xmlNodePtr currValueNode = NULL;
  int i_node = 0;
  for (i_node = 0; i_node < a_size; i_node++) {
    snprintf(
      xpath_expression,
      MAX_XPATH_EXPRESSION,
      "//*/background_frequencies/"
      "alphabet_array/value[@letter_id='letter_%c']",
      alph_char(alph, i_node)
    );
    xpathObj = xpath_query(xpath_ctxt, xpath_expression);
    assert(xpathObj->nodesetval->nodeNr == 1);
    currValueNode = xpathObj->nodesetval->nodeTab[0];
    xmlXPathFreeObject(xpathObj);
    value = xmlXPathCastNodeToNumber(currValueNode);
    set_array_item(i_node, value, bg_freqs);
  }
  normalize_subarray(0, a_size, 0.0, bg_freqs);
  calc_ambigs(alph, false, bg_freqs);
  return bg_freqs;
}
ARRAY_T * read_bg_freqs_from_xml ( xmlXPathContextPtr xpath_ctxt , ALPH_T * alph ) { xmlXPathObjectPtr xpathObj = NULL ; ATYPE value ; ARRAY_T * bg_freqs ; int a_size = alph_size_core ( alph ) ; xpathObj = xpath_query ( xpath_ctxt , " " ) ; int num_values = ( xpathObj -> nodesetval ? xpathObj -> nodesetval -> nodeNr : 0 ) ; xmlXPathFreeObject ( xpathObj ) ; assert ( num_values == a_size ) ; bg_freqs = allocate_array ( alph_size_full ( alph ) ) ; const int MAX_XPATH_EXPRESSION = 200 ; char xpath_expression [ MAX_XPATH_EXPRESSION ] ; xmlNodePtr currValueNode = NULL ; int i_node = 0 ; for ( i_node = 0 ; i_node < a_size ; i_node ++ ) { snprintf ( xpath_expression , MAX_XPATH_EXPRESSION , " " " " , alph_char ( alph , i_node ) ) ; xpathObj = xpath_query ( xpath_ctxt , xpath_expression ) ; assert ( xpathObj -> nodesetval -> nodeNr == 1 ) ; currValueNode = xpathObj -> nodesetval -> nodeTab [ 0 ] ; xmlXPathFreeObject ( xpathObj ) ; value = xmlXPathCastNodeToNumber ( currValueNode ) ; set_array_item ( i_node , value , bg_freqs ) ; } normalize_subarray ( 0 , a_size , 0.0 , bg_freqs ) ; calc_ambigs ( alph , false , bg_freqs ) ; return bg_freqs ; }
Read the background letter frequencies from XML.
Read the background letter frequencies from XML .
// Use XPATH to get the background frequencies from XML // The number of background frequences should match the alphabet size. // Allocate the array. // XML doesn't enforce any order on the emission probability values, // so force reading bg frequency values in alphabet order. // Build the XPATH expression to get bg freq for a character. // Read the selected bg frequency. // Should only find one node // Decode from node set to numeric value for bg freq. // Make sure the frequencies add up to 1.0.  // Fill in ambiguous characters. 