fac6f1db370338b0f775b60037e66fc2aac3cfdd
kate
Tue Jan 30 16:54:25 2018 -0800
Beginnings of details page for interact track. refs #17512
diff --git src/hg/hgc/interactClick.c src/hg/hgc/interactClick.c
new file mode 100644
index 0000000..b4ab8c7
--- /dev/null
+++ src/hg/hgc/interactClick.c
@@ -0,0 +1,155 @@
+/* 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 "hdb.h"
+#include "hgc.h"
+
+#include "interact.h"
+#include "interactUi.h"
+
+static struct interact *getInteract(char *item, char *chrom, int start, int end, char *table)
+/* Retrieve this item from track table
+ * TODO: Hubbify */
+{
+struct sqlConnection *conn = hAllocConn(database);
+struct interact *inters = NULL, *inter;
+char **row;
+int offset;
+char where[512];
+sqlSafefFrag(where, sizeof(where), "name='%s'", item);
+struct sqlResult *sr = hRangeQuery(conn, table, chrom, start, end, where, &offset);
+while ((row = sqlNextRow(sr)) != NULL)
+ {
+ inter = interactLoad(row+offset);
+ slAddHead(&inters, inter);
+ }
+slReverse(&inters);
+sqlFreeResult(&sr);
+hFreeConn(&conn);
+return inters;
+}
+
+void doInteractDetails(struct trackDb *tdb, char *item)
+/* Details of interaction item */
+{
+char *chrom = cartString(cart, "c");
+int start = cartInt(cart, "o");
+int end = cartInt(cart, "t");
+// TODO: hubbify
+struct interact *inter = getInteract(item, chrom, start, end, tdb->table);
+if (inter == NULL)
+ errAbort("Can't find interaction '%s'", item);
+genericHeader(tdb, item);
+printf("Source: %s %s:%d-%d
\n",
+ inter->sourceName, inter->sourceChrom, inter->sourceStart, inter->sourceEnd);
+printf("Target: %s %s:%d-%d
\n",
+ inter->targetName, inter->targetChrom, inter->targetStart, inter->targetEnd);
+}
+
+#ifdef FOO
+static void doLongTabix(struct trackDb *tdb, char *item)
+/* Handle a click on a long range interaction */
+{
+char *bigDataUrl = hashFindVal(tdb->settingsHash, "bigDataUrl");
+struct bedTabixFile *btf = bedTabixFileMayOpen(bigDataUrl, NULL, 0, 0);
+char *chromName = cartString(cart, "c");
+struct bed *list = bedTabixReadBeds(btf, chromName, winStart, winEnd, bedLoad5);
+bedTabixFileClose(&btf);
+unsigned maxWidth;
+struct longRange *longRangeList = parseLongTabix(list, &maxWidth, 0);
+struct longRange *longRange, *ourLongRange = NULL;
+unsigned itemNum = sqlUnsigned(item);
+unsigned count = slCount(longRangeList);
+double *doubleArray;
+
+AllocArray(doubleArray, count);
+
+int ii = 0;
+for(longRange = longRangeList; longRange; longRange = longRange->next, ii++)
+ {
+ if (longRange->id == itemNum)
+ {
+ ourLongRange = longRange;
+ }
+ doubleArray[ii] = longRange->score;
+ }
+
+if (ourLongRange == NULL)
+ errAbort("cannot find long range item with id %d\n", itemNum);
+
+printf("Item you clicked on:
\n");
+printf(" ID: %u
\n", ourLongRange->id);
+if (!ourLongRange->hasColor)
+ // if there's color, then there's no score in this format
+ printf("Score: %g
\n", ourLongRange->score);
+
+unsigned padding = (ourLongRange->e - ourLongRange->s) / 10;
+int s = ourLongRange->s - padding;
+int e = ourLongRange->e + padding;
+if (s < 0 )
+ s = 0;
+int chromSize = hChromSize(database, seqName);
+if (e > chromSize)
+ e = chromSize;
+
+char sStartPosBuf[1024], sEndPosBuf[1024];
+char eStartPosBuf[1024], eEndPosBuf[1024];
+// FIXME: longRange should store region starts, not centers
+sprintLongWithCommas(sStartPosBuf, ourLongRange->s - ourLongRange->sw/2 + 1);
+sprintLongWithCommas(sEndPosBuf, ourLongRange->s + ourLongRange->sw/2 + 1);
+sprintLongWithCommas(eStartPosBuf, ourLongRange->e - ourLongRange->ew/2 + 1);
+sprintLongWithCommas(eEndPosBuf, ourLongRange->e + ourLongRange->ew/2 + 1);
+char sWidthBuf[1024], eWidthBuf[1024];
+char regionWidthBuf[1024];
+sprintLongWithCommas(sWidthBuf, ourLongRange->sw);
+sprintLongWithCommas(eWidthBuf, ourLongRange->ew);
+sprintLongWithCommas(regionWidthBuf, ourLongRange->ew + ourLongRange->e - ourLongRange->s);
+
+if (differentString(ourLongRange->sChrom, ourLongRange->eChrom))
+ {
+ printf("Current region: ");
+ printf("%s:%s-%s (%s bp)
\n",
+ ourLongRange->sChrom, sStartPosBuf, sEndPosBuf,
+ ourLongRange->sChrom, sStartPosBuf,sEndPosBuf, sWidthBuf);
+ printf("Paired region: ");
+ printf("%s:%s-%s (%s bp)
\n",
+ ourLongRange->eChrom, eStartPosBuf, eEndPosBuf,
+ ourLongRange->eChrom, eStartPosBuf, eEndPosBuf, eWidthBuf);
+ }
+else
+ {
+ printf("Lower region: ");
+ printf("%s:%s-%s (%s bp)
\n",
+ ourLongRange->sChrom, sStartPosBuf,sEndPosBuf,
+ ourLongRange->sChrom, sStartPosBuf,sEndPosBuf, sWidthBuf);
+ printf("Upper region: ");
+ printf("%s:%s-%s (%s bp)
\n",
+ ourLongRange->eChrom, eStartPosBuf, eEndPosBuf,
+ ourLongRange->eChrom, eStartPosBuf, eEndPosBuf, eWidthBuf);
+ printf("Interaction region: ");
+ printf("%s:%s-%s (%s bp)
\n",
+ ourLongRange->eChrom, sStartPosBuf, eEndPosBuf,
+ ourLongRange->eChrom, sStartPosBuf, eEndPosBuf, regionWidthBuf);
+ }
+if (ourLongRange->hasColor)
+ return;
+
+struct aveStats *as = aveStatsCalc(doubleArray, count);
+printf("
Statistics on the scores of all items in window (go to track controls to set minimum score to display):\n");
+
+printf("
Q1 | %f |
median | %f |
Q3 | %f |
average | %f |
min | %f |
max | %f |
count | %d |
total | %f |
standard deviation | %f |