6ee178c93b929d9ddd41d8647962a716c87fe7db
kate
Mon Sep 17 22:39:08 2018 -0700
Forgive incorrect chromStart/chromEnd. And on click, find named items when pos doesn't do it. refs #21917
diff --git src/hg/hgc/interactClick.c src/hg/hgc/interactClick.c
index 44f39b2..2c7b3c1 100644
--- src/hg/hgc/interactClick.c
+++ src/hg/hgc/interactClick.c
@@ -9,124 +9,150 @@
#include "jksql.h"
#include "hgc.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 *foot)
+ 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;
}
if (conn == NULL)
return NULL;
struct interactPlusRow *iprs = NULL;
char **row;
int offset;
struct sqlResult *sr = hRangeQuery(conn, table, chrom, start, end, NULL, &offset);
int fieldCount = 0;
while ((row = sqlNextRow(sr)) != NULL)
{
struct interact *inter = interactLoadAndValidate(row+offset);
+ if (!name)
+ {
if (inter->chromStart != start || inter->chromEnd != end)
continue;
-
+ }
+ else
+ {
+ if (differentString(inter->name, name))
+ continue;
+ }
// got one, save object and row representation
struct interactPlusRow *ipr;
AllocVar(ipr);
ipr->interact = inter;
char **fieldVals;
if (fieldCount == 0)
fieldCount = sqlCountColumns(sr);
AllocArray(fieldVals, fieldCount);
int i;
for (i = 0; i < fieldCount; i++)
fieldVals[i] = cloneString(row[i]);
ipr->row = fieldVals;
slAddHead(&iprs, ipr);
}
sqlFreeResult(&sr);
hFreeConn(&conn);
return iprs;
}
static struct interactPlusRow *getInteractsFromFile(char *file, char *chrom, int start, int end,
- char *foot)
-/* Retrieve interact items at this position from big file */
+ char *name, char *foot)
+/* Retrieve interact items at this position or name 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 interactPlusRow *iprs = NULL;
+
for (bb = bbList; bb != NULL; bb = bb->next)
{
char startBuf[16], endBuf[16];
int maxFields = 32;
char *row[maxFields]; // big enough ?
int fieldCount = bigBedIntervalToRow(bb, chrom, startBuf, endBuf, row, maxFields);
struct interact *inter = interactLoadAndValidate(row);
if (inter == NULL)
continue;
+ if (!name)
+ {
if (inter->chromStart != start || inter->chromEnd != end)
continue;
+ }
+ else
+ {
+ //uglyf("inter name: %s. len: %d ", inter->name, (int)strlen(inter->name));
+ if (differentString(inter->name, name))
+ continue;
+ }
// got one, save object and row representation
struct interactPlusRow *ipr;
AllocVar(ipr);
ipr->interact = inter;
char **fieldVals;
AllocArray(fieldVals, fieldCount);
int i;
for (i = 0; i < fieldCount; i++)
fieldVals[i] = cloneString(row[i]);
ipr->row = fieldVals;
slAddHead(&iprs, ipr);
}
return iprs;
}
-static struct interactPlusRow *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*/
+static struct interactPlusRow *getInteractions(struct trackDb *tdb, char *chrom,
+ int start, int end, char *name, char *foot)
+/* Retrieve interact items at this position or name.
+ * Also any others with the same endpoint, if endpoint clicked on*/
{
struct interactPlusRow *iprs = NULL;
char *file = trackDbSetting(tdb, "bigDataUrl");
if (file != NULL)
- iprs = getInteractsFromFile(file, chrom, start, end, foot);
+ {
+ iprs = getInteractsFromFile(file, chrom, start, end, NULL, foot);
+ if (!iprs)
+ iprs = getInteractsFromFile(file, chrom, start, end, name, foot);
+ }
else
- iprs = getInteractsFromTable(tdb, chrom, start, end, foot);
+ {
+ iprs = getInteractsFromTable(tdb, chrom, start, end, NULL, foot);
+ if (!iprs)
+ iprs = getInteractsFromTable(tdb, chrom, start, end, name, foot);
+ }
// TODO: add sort on score in interacts in ipr
//slSort(&inters, bedCmpScore);
//slReverse(&inters);
return iprs;
}
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];
@@ -218,37 +244,37 @@
printf("Value: %0.3f
\n", inter->value);
if (!isEmptyTextField(inter->exp))
printf("Experiment: %s
\n", inter->exp);
puts("
"); 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 interactPlusRow *iprs = getInteractions(tdb, chrom, start, end, foot); +struct interactPlusRow *iprs = getInteractions(tdb, chrom, start, end, item, foot); if (iprs == NULL) errAbort("Can't find interaction %s", item ? item : ""); int count = slCount(iprs); if (count > 1) { - printf("Interactions at this position: %d
", count); + printf("Interactions: %d
", count); doInteractRegionDetails(tdb, iprs->interact); printf("
"); } genericHeader(tdb, item); static struct interactPlusRow *ipr = NULL; for (ipr = iprs; ipr != NULL; ipr = ipr->next) { if (count > 1) printf("