a80a8de2fc8f3573cd184b2a4032afff1f959e16
kate
  Wed Jan 17 16:19:15 2018 -0800
First cut of interact track type.  Same display as longTabix, but with new schema to support phase 2 features. refs #17512

diff --git src/hg/lib/interact.c src/hg/lib/interact.c
new file mode 100644
index 0000000..f210adb
--- /dev/null
+++ src/hg/lib/interact.c
@@ -0,0 +1,240 @@
+/* interact.c was originally generated by the autoSql program, which also 
+ * generated interact.h and interact.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 "interact.h"
+
+
+
+char *interactCommaSepFieldNames = "chrom,chromStart,chromEnd,name,score,strand,color,chrom1,chromStart1,chromEnd1,name1,chrom2,chromStart2,chromEnd2,name2";
+
+void interactStaticLoad(char **row, struct interact *ret)
+/* Load a row from interact table into ret.  The contents of ret will
+ * be replaced at the next call to this function. */
+{
+ret->chrom = row[0];
+ret->chromStart = sqlUnsigned(row[1]);
+ret->chromEnd = sqlUnsigned(row[2]);
+ret->name = row[3];
+ret->score = sqlUnsigned(row[4]);
+safecpy(ret->strand, sizeof(ret->strand), row[5]);
+ret->color = sqlUnsigned(row[6]);
+ret->chrom1 = row[7];
+ret->chromStart1 = sqlUnsigned(row[8]);
+ret->chromEnd1 = sqlUnsigned(row[9]);
+ret->name1 = row[10];
+ret->chrom2 = row[11];
+ret->chromStart2 = sqlUnsigned(row[12]);
+ret->chromEnd2 = sqlUnsigned(row[13]);
+ret->name2 = row[14];
+}
+
+struct interact *interactLoadByQuery(struct sqlConnection *conn, char *query)
+/* Load all interact from table that satisfy the query given.  
+ * Where query is of the form 'select * from example where something=something'
+ * or 'select example.* from example, anotherTable where example.something = 
+ * anotherTable.something'.
+ * Dispose of this with interactFreeList(). */
+{
+struct interact *list = NULL, *el;
+struct sqlResult *sr;
+char **row;
+
+sr = sqlGetResult(conn, query);
+while ((row = sqlNextRow(sr)) != NULL)
+    {
+    el = interactLoad(row);
+    slAddHead(&list, el);
+    }
+slReverse(&list);
+sqlFreeResult(&sr);
+return list;
+}
+
+void interactSaveToDb(struct sqlConnection *conn, struct interact *el, char *tableName, int updateSize)
+/* Save interact as a row to the table specified by tableName. 
+ * As blob fields may be arbitrary size updateSize specifies the approx size
+ * of a string that would contain the entire query. Arrays of native types are
+ * converted to comma separated strings and loaded as such, User defined types are
+ * inserted as NULL. This function automatically escapes quoted strings for mysql. */
+{
+struct dyString *update = newDyString(updateSize);
+sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%s',%u,'%s',%u,%u,'%s','%s',%u,%u,'%s')", 
+	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->color,  el->chrom1,  el->chromStart1,  el->chromEnd1,  el->name1,  el->chrom2,  el->chromStart2,  el->chromEnd2,  el->name2);
+sqlUpdate(conn, update->string);
+freeDyString(&update);
+}
+
+struct interact *interactLoad(char **row)
+/* Load a interact from row fetched with select * from interact
+ * from database.  Dispose of this with interactFree(). */
+{
+struct interact *ret;
+
+AllocVar(ret);
+ret->chrom = cloneString(row[0]);
+ret->chromStart = sqlUnsigned(row[1]);
+ret->chromEnd = sqlUnsigned(row[2]);
+ret->name = cloneString(row[3]);
+ret->score = sqlUnsigned(row[4]);
+safecpy(ret->strand, sizeof(ret->strand), row[5]);
+ret->color = sqlUnsigned(row[6]);
+ret->chrom1 = cloneString(row[7]);
+ret->chromStart1 = sqlUnsigned(row[8]);
+ret->chromEnd1 = sqlUnsigned(row[9]);
+ret->name1 = cloneString(row[10]);
+ret->chrom2 = cloneString(row[11]);
+ret->chromStart2 = sqlUnsigned(row[12]);
+ret->chromEnd2 = sqlUnsigned(row[13]);
+ret->name2 = cloneString(row[14]);
+return ret;
+}
+
+struct interact *interactLoadAll(char *fileName) 
+/* Load all interact from a whitespace-separated file.
+ * Dispose of this with interactFreeList(). */
+{
+struct interact *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[15];
+
+while (lineFileRow(lf, row))
+    {
+    el = interactLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct interact *interactLoadAllByChar(char *fileName, char chopper) 
+/* Load all interact from a chopper separated file.
+ * Dispose of this with interactFreeList(). */
+{
+struct interact *list = NULL, *el;
+struct lineFile *lf = lineFileOpen(fileName, TRUE);
+char *row[15];
+
+while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
+    {
+    el = interactLoad(row);
+    slAddHead(&list, el);
+    }
+lineFileClose(&lf);
+slReverse(&list);
+return list;
+}
+
+struct interact *interactCommaIn(char **pS, struct interact *ret)
+/* Create a interact out of a comma separated string. 
+ * This will fill in ret if non-null, otherwise will
+ * return a new interact */
+{
+char *s = *pS;
+
+if (ret == NULL)
+    AllocVar(ret);
+ret->chrom = sqlStringComma(&s);
+ret->chromStart = sqlUnsignedComma(&s);
+ret->chromEnd = sqlUnsignedComma(&s);
+ret->name = sqlStringComma(&s);
+ret->score = sqlUnsignedComma(&s);
+sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand));
+ret->color = sqlUnsignedComma(&s);
+ret->chrom1 = sqlStringComma(&s);
+ret->chromStart1 = sqlUnsignedComma(&s);
+ret->chromEnd1 = sqlUnsignedComma(&s);
+ret->name1 = sqlStringComma(&s);
+ret->chrom2 = sqlStringComma(&s);
+ret->chromStart2 = sqlUnsignedComma(&s);
+ret->chromEnd2 = sqlUnsignedComma(&s);
+ret->name2 = sqlStringComma(&s);
+*pS = s;
+return ret;
+}
+
+void interactFree(struct interact **pEl)
+/* Free a single dynamically allocated interact such as created
+ * with interactLoad(). */
+{
+struct interact *el;
+
+if ((el = *pEl) == NULL) return;
+freeMem(el->chrom);
+freeMem(el->name);
+freeMem(el->chrom1);
+freeMem(el->name1);
+freeMem(el->chrom2);
+freeMem(el->name2);
+freez(pEl);
+}
+
+void interactFreeList(struct interact **pList)
+/* Free a list of dynamically allocated interact's */
+{
+struct interact *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    interactFree(&el);
+    }
+*pList = NULL;
+}
+
+void interactOutput(struct interact *el, FILE *f, char sep, char lastSep) 
+/* Print out interact.  Separate fields with sep. Follow last field with lastSep. */
+{
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->chrom);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->chromStart);
+fputc(sep,f);
+fprintf(f, "%u", el->chromEnd);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->name);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->score);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->strand);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->color);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->chrom1);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->chromStart1);
+fputc(sep,f);
+fprintf(f, "%u", el->chromEnd1);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->name1);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->chrom2);
+if (sep == ',') fputc('"',f);
+fputc(sep,f);
+fprintf(f, "%u", el->chromStart2);
+fputc(sep,f);
+fprintf(f, "%u", el->chromEnd2);
+fputc(sep,f);
+if (sep == ',') fputc('"',f);
+fprintf(f, "%s", el->name2);
+if (sep == ',') fputc('"',f);
+fputc(lastSep,f);
+}
+
+/* -------------------------------- End autoSql Generated Code -------------------------------- */
+