afa4cc7f36a1d3d5c2e4dc4f20fbf6332a4258a3
hiram
  Thu Sep 15 11:28:56 2016 -0700
allow chrom name lookup to use the new chromXref table refs #18027

diff --git src/hg/lib/chromXref.c src/hg/lib/chromXref.c
new file mode 100644
index 0000000..bdc50e7
--- /dev/null
+++ src/hg/lib/chromXref.c
@@ -0,0 +1,180 @@
+/* chromXref.c was originally generated by the autoSql program, which also 
+ * generated chromXref.h and chromXref.sql.  This module links the database and
+ * the RAM representation of objects. */
+
+#include "common.h"
+#include "linefile.h"
+#include "dystring.h"
+#include "jksql.h"
+#include "chromXref.h"
+
+
+
+char *chromXrefCommaSepFieldNames = "ucsc,refseq,genbank,ensembl";
+
+void chromXrefStaticLoad(char **row, struct chromXref *ret)
+/* Load a row from chromXref table into ret.  The contents of ret will
+ * be replaced at the next call to this function. */
+{
+
+ret->ucsc = row[0];
+ret->refseq = row[1];
+ret->genbank = row[2];
+ret->ensembl = row[3];
+}
+
+struct chromXref *chromXrefLoad(char **row)
+/* Load a chromXref from row fetched with select * from chromXref
+ * from database.  Dispose of this with chromXrefFree(). */
+{
+struct chromXref *ret;
+
+AllocVar(ret);
+ret->ucsc = cloneString(row[0]);
+ret->refseq = cloneString(row[1]);
+ret->genbank = cloneString(row[2]);
+ret->ensembl = cloneString(row[3]);
+return ret;
+}
+
+struct chromXref *chromXrefLoadAll(char *fileName) 
+/* Load all chromXref from a whitespace-separated file.
+ * Dispose of this with chromXrefFreeList(). */
+{
+struct chromXref *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[4];
+
+while (lineFileRow(lf, row))
+    {
+    el = chromXrefLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct chromXref *chromXrefLoadAllByChar(char *fileName, char chopper) 
+/* Load all chromXref from a chopper separated file.
+ * Dispose of this with chromXrefFreeList(). */
+{
+struct chromXref *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[4];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = chromXrefLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct chromXref *chromXrefCommaIn(char **pS, struct chromXref *ret)
+/* Create a chromXref out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new chromXref */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->ucsc = sqlStringComma(&s);
+ret->refseq = sqlStringComma(&s);
+ret->genbank = sqlStringComma(&s);
+ret->ensembl = sqlStringComma(&s);
+*pS = s;
+return ret;
+}
+
+void chromXrefFree(struct chromXref **pEl)
+/* Free a single dynamically allocated chromXref such as created
+ * with chromXrefLoad(). */
+{
+struct chromXref *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->ucsc);
+freeMem(el->refseq);
+freeMem(el->genbank);
+freeMem(el->ensembl);
+freez(pEl);
+}
+
+void chromXrefFreeList(struct chromXref **pList)
+/* Free a list of dynamically allocated chromXref's */
+{
+struct chromXref *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    chromXrefFree(&el);
+    }
+*pList = NULL;
+}
+
+void chromXrefOutput(struct chromXref *el, FILE *f, char sep, char lastSep) 
+/* Print out chromXref.  Separate fields with sep. Follow last field with lastSep. */
+{
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->ucsc);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->refseq);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->genbank);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->ensembl);
+if (sep == ',') fputc('"',f);
+fputc(lastSep,f);
+}
+
+void chromXrefJsonOutput(struct chromXref *el, FILE *f) 
+/* Print out chromXref in JSON format. */
+{
+fputc('{',f);
+fputc('"',f);
+fprintf(f,"ucsc");
+fputc('"',f);
+fputc(':',f);
+fputc('"',f);
+fprintf(f, "%s", el->ucsc);
+fputc('"',f);
+fputc(',',f);
+fputc('"',f);
+fprintf(f,"refseq");
+fputc('"',f);
+fputc(':',f);
+fputc('"',f);
+fprintf(f, "%s", el->refseq);
+fputc('"',f);
+fputc(',',f);
+fputc('"',f);
+fprintf(f,"genbank");
+fputc('"',f);
+fputc(':',f);
+fputc('"',f);
+fprintf(f, "%s", el->genbank);
+fputc('"',f);
+fputc(',',f);
+fputc('"',f);
+fprintf(f,"ensembl");
+fputc('"',f);
+fputc(':',f);
+fputc('"',f);
+fprintf(f, "%s", el->ensembl);
+fputc('"',f);
+fputc('}',f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+