summaryrefslogtreecommitdiffstats
Side-by-side diff
-rw-r--r--src/load/load_asn.c173
-rw-r--r--src/load/load_asn.h24
-rw-r--r--src/load/load_features.c167
-rw-r--r--src/load/load_features.h12
4 files changed, 376 insertions, 0 deletions
diff --git a/src/load/load_features.c b/src/load/load_features.c
new file mode 100644
index 0000000..b18031a
--- a/dev/null
+++ b/src/load/load_features.c
@@ -0,0 +1,167 @@
+#include "load_features.h"
+#include <libxml/parser.h>
+#include <stdbool.h>
+#include <asn.h>
+#include <objgbseq.h>
+
+/*
+ * An NCBI GBSeq structure to hold the data for the current record.
+ */
+GBSeqPtr g;
+
+bool in_element;
+
+static void
+lf_startDocument (void *ctx ATTRIBUTE_UNUSED)
+{
+ printf ("SAX.startDocument()\n");
+
+ return;
+}
+
+static void
+lf_endDocument (void *ctx ATTRIBUTE_UNUSED)
+{
+ printf ("SAX.endDocument()\n");
+
+ return;
+}
+
+static xmlEntityPtr
+lf_getEntity (void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
+{
+ printf("SAX.getEntity(%s)\n", name);
+
+ return (NULL);
+}
+
+static void
+lf_startElement(void *ctx ATTRIBUTE_UNUSED,
+ const xmlChar *name, const xmlChar **atts)
+{
+ int i;
+
+ fprintf(stdout, "SAX.startElement(%s", (char *) name);
+ if (atts != NULL) {
+ for (i = 0;(atts[i] != NULL);i++) {
+ fprintf(stdout, ", %s='", atts[i++]);
+ if (atts[i] != NULL)
+ fprintf(stdout, "%s'", atts[i]);
+ }
+ }
+ fprintf(stdout, ")\n");
+
+ in_element = true;
+
+ return;
+}
+
+static void
+lf_endElement(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name)
+{
+ printf("SAX.endElement(%s)\n", (char *) name);
+ in_element = false;
+
+ return;
+}
+
+static void
+lf_characters(void *ctx ATTRIBUTE_UNUSED, const xmlChar *ch, int len)
+{
+ if (!in_element)
+ return;
+
+ char output[40];
+ int i;
+
+ for (i = 0;(i<len) && (i < 30);i++)
+ output[i] = ch[i];
+ output[i] = 0;
+
+ printf("SAX.characters(%s, %d)\n", output, len);
+}
+
+/*
+ * 1. Parse and load the XML file into memory.
+ * 2. Insert the XML into HDF5.
+ * For an example of parsing XML with libxml2 and SAX see:
+ * [http://git.gnome.org/browse/libxml2/tree/testSAX.c].
+ */
+void
+load_features (hid_t file_id, const char* file_name)
+{
+ g = GBSeqNew ();
+
+ LIBXML_TEST_VERSION;
+
+ in_element = false;
+
+ static xmlSAXHandler emptySAXHandlerStruct = {
+ NULL, /* internalSubset */
+ NULL, /* isStandalone */
+ NULL, /* hasInternalSubset */
+ NULL, /* hasExternalSubset */
+ NULL, /* resolveEntity */
+ lf_getEntity, /* getEntity */
+ NULL, /* entityDecl */
+ NULL, /* notationDecl */
+ NULL, /* attributeDecl */
+ NULL, /* elementDecl */
+ NULL, /* unparsedEntityDecl */
+ NULL, /* setDocumentLocator */
+ lf_startDocument, /* startDocument */
+ lf_endDocument, /* endDocument */
+ lf_startElement, /* startElement */
+ lf_endElement, /* endElement */
+ NULL, /* reference */
+ lf_characters, /* characters */
+ NULL, /* ignorableWhitespace */
+ NULL, /* processingInstruction */
+ NULL, /* comment */
+ NULL, /* xmlParserWarning */
+ NULL, /* xmlParserError */
+ NULL, /* xmlParserError */
+ NULL, /* getParameterEntity */
+ NULL, /* cdataBlock; */
+ NULL, /* externalSubset; */
+ 1,
+ NULL,
+ NULL, /* startElementNs */
+ NULL, /* endElementNs */
+ NULL /* xmlStructuredErrorFunc */
+ };
+
+ static xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;
+
+ FILE *f = fopen (file_name, "r");
+
+ if (f != NULL)
+ {
+ int ret;
+ char chars[10];
+ xmlParserCtxtPtr ctxt;
+
+ ret = fread (chars, 1, 4, f);
+ if (ret > 0)
+ {
+ ctxt = xmlCreatePushParserCtxt (emptySAXHandler, NULL,
+ chars, ret, file_name);
+ while ((ret = fread(chars, 1, 3, f)) > 0)
+ {
+ xmlParseChunk (ctxt, chars, ret, 0);
+ }
+ xmlParseChunk (ctxt, chars, 0, 1);
+ xmlFreeParserCtxt(ctxt);
+ }
+ fclose (f);
+ }
+ else
+ {
+ xmlGenericError (xmlGenericErrorContext,
+ "Cannot read file.");
+ }
+
+ GBSeqFree (g);
+
+ return;
+}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.