a06ad24a3fcaa4e141be050c4d289d0f0ce99589
kate
  Mon Dec 17 17:22:40 2018 -0800
Add checksum (SHA1) file required by multiregion feature. Still needs a way to view entire virtual chrom. refs #22422

diff --git src/hg/hgc/interactClick.c src/hg/hgc/interactClick.c
index 87afdb5..1317874 100644
--- src/hg/hgc/interactClick.c
+++ src/hg/hgc/interactClick.c
@@ -1,26 +1,28 @@
 /* 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 "hex.h"
+#include <openssl/sha.h>
 
 #include "interact.h"
 #include "interactUi.h"
 
 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 */
@@ -230,41 +232,59 @@
 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"
+char regionInfo[1024];
+// TODO: check chrom bounds
+int padding = 2;
+safef(regionInfo, sizeof regionInfo, "%s\t%d\t%d\n"
            "%s\t%d\t%d\n",
-                region1Chrom, region1Start, region1End, 
-                region2Chrom, region2Start, region2End);
+                region1Chrom, region1Start-padding, region1End+padding, 
+                region2Chrom, region2Start-padding, region2End+padding);
+mustWrite(f, regionInfo, strlen(regionInfo));
 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);
+
+// create SHA1 file; used to see if file has changed
+unsigned char hash[SHA_DIGEST_LENGTH];
+SHA1((const unsigned char *)regionInfo, strlen(regionInfo), hash);
+char newSha1[(SHA_DIGEST_LENGTH + 1) * 2];
+hexBinaryString(hash, SHA_DIGEST_LENGTH, newSha1, (SHA_DIGEST_LENGTH + 1) * 2);
+char sha1File[1024];
+safef(sha1File, sizeof sha1File, "%s.sha1", mrTn.forCgi);
+f = mustOpen(sha1File, "w");
+mustWrite(f, newSha1, strlen(newSha1));
+carefulClose(&f);
+
+// TODO: add cart variable to set viewport to entire virtual chromosome (TBD galt)
+printf("<br><a target='_blank' "
+        "href='hgTracks?"
+            "virtMode=1&"
+            "virtModeType=customUrl&"
+            "multiRegionsBedUrl=%s'>"
+        "Show both ends of interaction in multi-region browser view</a>",
+                cgiEncode(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 interactPlusRow *ipr, char *item, 
                                 boolean isMultiple)
 /* Details of interaction item */
 {
 struct interact *inter = ipr->interact;
 struct slPair *fields = getFields(tdb, ipr->row);
 printCustomUrlWithFields(tdb, inter->name, inter->name, TRUE, fields);
 if (!isEmptyTextField(inter->name))