src/hg/instinct/xRefLookup/xRefLookup.c 1.1

1.1 2009/02/18 23:01:53 jsanborn
adding simple script for steve to access kgXref table
Index: src/hg/instinct/xRefLookup/xRefLookup.c
===================================================================
RCS file: src/hg/instinct/xRefLookup/xRefLookup.c
diff -N src/hg/instinct/xRefLookup/xRefLookup.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/hg/instinct/xRefLookup/xRefLookup.c	18 Feb 2009 23:01:53 -0000	1.1
@@ -0,0 +1,49 @@
+/* xRefLookup - simple look up kgXref by protAcc, geneSymbol, etc.. */
+#include "common.h"
+#include "linefile.h"
+#include "hash.h"
+#include "options.h"
+#include "jksql.h"
+#include "hdb.h"
+
+static char const rcsid[] = "$Id$";
+
+void usage()
+/* Explain usage and exit. */
+{
+errAbort(
+  "xRefLookup - simple look up kgXref by protAcc, geneSymbol, etc.\n"
+  "usage:\n"
+  "   xRefLookup from_field to_field id\n"
+  );
+}
+
+static struct optionSpec options[] = {
+   {NULL, 0},
+};
+
+void xRefLookup(char *from, char *to, char *id)
+/* xRefLookup - simple look up kgXref by protAcc, geneSymbol, etc.. */
+{
+char query[256];
+safef(query, sizeof(query),
+      "select %s from kgXref where %s = '%s';", 
+      to, from, id);
+
+struct sqlConnection *conn = hAllocConnProfile("db", "hg18");
+char *newId = sqlQuickString(conn, query);
+hFreeConn(&conn);
+
+if (newId)
+    fprintf(stdout, "%s\n", newId);
+}
+
+int main(int argc, char *argv[])
+/* Process command line. */
+{
+optionInit(&argc, argv, options);
+if (argc != 4)
+    usage();
+xRefLookup(argv[1], argv[2], argv[3]);
+return 0;
+}