374405106b2e246ff47079103aee676e413b7534
kate
  Wed Aug 15 16:11:04 2018 -0700
Adding 'foot' arg to click through, so interactions using same endpoint can be shown on details page.  Still need to add code to make use of bigBed indexing. refs #21917

diff --git src/hg/hgc/interactClick.c src/hg/hgc/interactClick.c
index f8ebdbb..7338bf7 100644
--- src/hg/hgc/interactClick.c
+++ src/hg/hgc/interactClick.c
@@ -1,29 +1,30 @@
 /* Details page for interact type tracks */
 
 /* Copyright (C) 2018 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 
 #include "common.h"
 #include "obscure.h"
 #include "hdb.h"
 #include "hgc.h"
 
 #include "interact.h"
 #include "interactUi.h"
 
-static struct interact *getInteractFromTable(struct trackDb *tdb, char *chrom, int start, int end)
+static struct interact *getInteractFromTable(struct trackDb *tdb, char *chrom, int start, int end,
+                                                char *foot)
 /* Retrieve interact items at this position from track table */
 {
 struct sqlConnection *conn = NULL;
 struct customTrack *ct = lookupCt(tdb->track);
 char *table;
 if (ct != NULL)
     {
     conn = hAllocConn(CUSTOM_TRASH);
     table = ct->dbTableName;
     }
 else
     {
     conn = hAllocConnTrack(database, tdb);
     table = tdb->table;
     }
@@ -34,61 +35,61 @@
 char **row;
 int offset;
 struct sqlResult *sr = hRangeQuery(conn, table, chrom, start, end, NULL, &offset);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     inter = interactLoadAndValidate(row+offset);
     if (inter->chromStart != start || inter->chromEnd != end)
         continue;
     slAddHead(&inters, inter);
     }
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 return inters;
 }
 
-static struct interact *getInteractFromFile(char *file, char *chrom, int start, int end)
+static struct interact *getInteractFromFile(char *file, char *chrom, int start, int end, char *foot)
 /* Retrieve interact items at this position from big file */
 {
 struct bbiFile *bbi = bigBedFileOpen(file);
 struct lm *lm = lmInit(0);
 struct bigBedInterval *bb, *bbList =  bigBedIntervalQuery(bbi, chrom, start, end, 0, lm);
 struct interact *inters = NULL, *inter = NULL;
 for (bb = bbList; bb != NULL; bb = bb->next)
     {
     char startBuf[16], endBuf[16];
     char *row[32];
     bigBedIntervalToRow(bb, chrom, startBuf, endBuf, row, ArraySize(row));
     inter = interactLoadAndValidate(row);
     if (inter == NULL)
         continue;
     if (inter->chromStart != start || inter->chromEnd != end)
         continue;
     slAddHead(&inters, inter);
     }
 return inters;
 }
 
-static struct interact *getInteractions(struct trackDb *tdb, char *chrom, int start, int end)
-/* Retrieve interact items at this position */
+static struct interact *getInteractions(struct trackDb *tdb, char *chrom, int start, int end, char *foot)
+/* Retrieve interact items at this position. Also any others with the same endpoint, if endpoint clicked on*/
 {
 struct interact *inters = NULL;
 char *file = trackDbSetting(tdb, "bigDataUrl");
 if (file != NULL)
-    inters = getInteractFromFile(file, chrom, start, end);
+    inters = getInteractFromFile(file, chrom, start, end, foot);
 else
-    inters = getInteractFromTable(tdb, chrom, start, end);
+    inters = getInteractFromTable(tdb, chrom, start, end, foot);
 slSort(&inters, bedCmpScore);
 slReverse(&inters);
 return inters;
 }
 
 void doInteractRegionDetails(struct trackDb *tdb, struct interact *inter)
 {
 /* print info for both regions */
 /* Use different labels:
         1) directional (source/target)
         2) non-directional same chrom (lower/upper)
         3) non-directional other chrom (this/other)
 */
 char startBuf[1024], endBuf[1024], sizeBuf[1024];
 printf("<b>Interaction region:</b> ");
@@ -176,32 +177,33 @@
 printf("<b>Score:</b> %d<br>\n", inter->score);
 printf("<b>Value:</b> %0.3f<br>\n", inter->value);
 if (!isEmptyTextField(inter->exp))
     printf("<b>Experiment:</b> %s<br>\n", inter->exp);
 puts("<p>");
 if (!isMultiple)
     doInteractRegionDetails(tdb, inter);
 }
 
 void doInteractDetails(struct trackDb *tdb, char *item)
 /* Details of interaction items */
 {
 char *chrom = cartString(cart, "c");
 int start = cartInt(cart, "o");
 int end = cartInt(cart, "t");
+char *foot = cartString(cart, "foot");
 struct interact *inter = NULL;
-struct interact *inters = getInteractions(tdb, chrom, start, end);
+struct interact *inters = getInteractions(tdb, chrom, start, end, foot);
 if (inters == NULL)
     errAbort("Can't find interaction %s", item ? item : "");
 int count = slCount(inters);
 if (count > 1)
     {
     printf("<b>Interactions at this position:</b> %d<p>", count);
     doInteractRegionDetails(tdb, inters);
     printf("</p>");
     }
 genericHeader(tdb, item);
 for (inter = inters; inter; inter = inter->next)
     {
     if (count > 1)
         printf("<hr>\n");
     doInteractItemDetails(tdb, inter, item, count > 1);