5dffa4e472b83289e2bb9d65bbdc8541b0a48c82
Merge parents c8cca30 b0267b2
kate
  Mon Nov 26 17:15:58 2018 -0800
Resolve merge cconflict

diff --cc src/hg/hgc/interactClick.c
index 4ea46ec,f9f28eb..9d1e538
--- src/hg/hgc/interactClick.c
+++ src/hg/hgc/interactClick.c
@@@ -1,31 -1,39 +1,40 @@@
  /* 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 "jksql.h"
  #include "hgc.h"
 +#include "trashDir.h"
  
  #include "interact.h"
  #include "interactUi.h"
  
- static struct interact *getInteractsFromTable(struct trackDb *tdb, char *chrom, int start, int end,
-                                                 char *foot)
+ struct interactPlusRow
+     {
+     /* Keep field values in string format, for url processing */
+     struct interactPlusRow *next;
+     struct interact *interact;
+     char **row;
+     };
+ 
+ static struct interactPlusRow *getInteractsFromTable(struct trackDb *tdb, char *chrom, 
+                                     int start, int end, char *name, 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;
      }
@@@ -133,107 -200,113 +201,131 @@@
          region2Label = "Other";
          }
      else
          {
          region1Label = "Lower";
          region2Label = "Upper";
          }
      }
  // format and print
  sprintLongWithCommas(startBuf, region1Start + 1);
  sprintLongWithCommas(endBuf, region1End);
  sprintLongWithCommas(sizeBuf, region1End - region1Start);
  printf("<b>%s region:</b> %s&nbsp;&nbsp;"
                  "<a href='hgTracks?position=%s:%d-%d' target='_blank'>%s:%s-%s</a> %s",
                  region1Label, region1Name, region1Chrom, region1Start+1, region1End,
-                 region1Chrom, startBuf, endBuf, inter->sourceStrand[0] == '.' ? "" : inter->sourceStrand);
+                 region1Chrom, startBuf, endBuf, 
+                 inter->sourceStrand[0] == '.' ? "" : inter->sourceStrand);
  printf("&nbsp;&nbsp;%s bp<br>\n", sizeBuf);
  
  sprintLongWithCommas(startBuf, region2Start+1);
  sprintLongWithCommas(endBuf, region2End);
  sprintLongWithCommas(sizeBuf, region2End - region2Start);
  printf("<b>%s region:</b> %s&nbsp;&nbsp;"
                  "<a href='hgTracks?position=%s:%d-%d' target='_blank'>%s:%s-%s</a> %s",
                  region2Label, region2Name, region2Chrom, region2Start+1, region2End,
-                 region2Chrom, startBuf, endBuf, inter->targetStrand[0] == '.' ? "" : inter->targetStrand);
+                 region2Chrom, startBuf, endBuf, 
+                 inter->targetStrand[0] == '.' ? "" : inter->targetStrand);
  printf("&nbsp;&nbsp;%s bp<br>\n", sizeBuf);
  int distance = interactRegionDistance(inter);
  if (distance > 0)
      {
      // same chrom
      sprintLongWithCommas(sizeBuf, distance);
      printf("<b>Distance between midpoints:</b> %s bp<br>\n", sizeBuf); 
      }
  
 +// print link to multi-region view of ends
 +
 +// create bed file in trash directory with end coordinates
 +struct tempName mrTn;
 +trashDirFile(&mrTn, "hgt", "custRgn_interact", ".bed");
 +FILE *f = fopen(mrTn.forCgi, "w");
 +if (f == NULL)
 +    errAbort("can't create temp file %s", mrTn.forCgi);
 +fprintf(f, "%s\t%d\t%d\n"
 +           "%s\t%d\t%d\n",
 +                region1Chrom, region1Start, region1End, 
 +                region2Chrom, region2Start, region2End);
 +fclose(f);
 +printf("<br><a target='_blank' href='hgTracks?"
 +                "virtMode=1"
 +                "&virtModeType=customUrl"
 +                "&multiRegionsBedUrl=%s'"
 +        ">Show both ends of interaction in multi-region browser view</a>",
 +                mrTn.forCgi);
 +
  #ifdef TODO /* TODO: get count and score stats of all interactions in window ?*/
  double *scores;
  AllocArray(scores, count);
  #endif
  }
  
- void doInteractItemDetails(struct trackDb *tdb, struct interact *inter, char *item, boolean isMultiple)
+ void doInteractItemDetails(struct trackDb *tdb, struct interactPlusRow *ipr, char *item, 
+                                 boolean isMultiple)
  /* Details of interaction item */
  {
+ struct interact *inter = ipr->interact;
+ struct slPair *fields = getFields(tdb, ipr->row);
+ printCustomUrlWithFields(tdb, item, item, TRUE, fields);
  if (!isEmptyTextField(inter->name))
-     printf("<b>Interaction name:</b> %s<br>\n", inter->name);
- 
- 
+     printf("<b>Interaction:</b> %s<br>\n", inter->name);
  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 = cartOptionalString(cart, "foot");
- struct interact *inter = NULL;
- struct interact *inters = getInteractions(tdb, chrom, start, end, foot);
- if (inters == NULL)
+ char *foot = cgiOptionalString("foot");
+ int minStart, maxEnd;
+ struct interactPlusRow *iprs = getInteractions(tdb, chrom, start, end, item, foot, &minStart, &maxEnd);
+ start = minStart;
+ end = maxEnd;
+ if (iprs == NULL)
      errAbort("Can't find interaction %s", item ? item : "");
- int count = slCount(inters);
- if (count > 1)
+ int count = slCount(iprs);
+ char *clusterMode = interactUiClusterMode(cart, tdb->track, tdb);
+ if (count > 1 || clusterMode)
      {
-     printf("<b>Interactions at this position:</b> %d<p>", count);
-     doInteractRegionDetails(tdb, inters);
+     printf("<b>Interactions:</b> %d<p>", count);
+     if (clusterMode || foot)
+         {
+         char startBuf[1024], endBuf[1024], sizeBuf[1024];
+         sprintLongWithCommas(startBuf, start + 1);
+         sprintLongWithCommas(endBuf, end);
+         sprintLongWithCommas(sizeBuf, end - start);
+         printf("<b>%s interactions region:</b> &nbsp;&nbsp;"
+                         "<a href='hgTracks?position=%s:%d-%d' target='_blank'>%s:%s-%s</a> ",
+                         item, chrom, start+1, end, chrom, startBuf, endBuf);
+         printf("&nbsp;&nbsp;%s bp<br>\n", sizeBuf);
+         }
+     else
+         {
+         doInteractRegionDetails(tdb, iprs->interact);
+         }
      printf("</p>");
      }
+ 
  genericHeader(tdb, item);
- for (inter = inters; inter; inter = inter->next)
+ static struct interactPlusRow *ipr = NULL;
+ for (ipr = iprs; ipr != NULL; ipr = ipr->next)
      {
      if (count > 1)
          printf("<hr>\n");
-     doInteractItemDetails(tdb, inter, item, count > 1);
-     if (count > 1 && !isEmptyTextField(inter->name) && sameString(inter->name, item))
+     doInteractItemDetails(tdb, ipr, item, count > 1);
+     if (foot || (clusterMode && count > 1))
+         doInteractRegionDetails(tdb, ipr->interact);
+     if (count > 1 && !isEmptyTextField(ipr->interact->name) && sameString(ipr->interact->name, item))
          printf("<hr>\n");
      }
- 
 -if (count > 1 && clusterMode)
 -    printf("<hr>\n");
  }