7a89988d6fd56140fd0b43c0f60430a210c24570 braney Thu May 19 16:41:30 2016 -0700 connecting things up for the long-range interaction display. diff --git src/hg/lib/longRange.c src/hg/lib/longRange.c new file mode 100644 index 0000000..57c674c --- /dev/null +++ src/hg/lib/longRange.c @@ -0,0 +1,90 @@ + +#include "longRange.h" + +void longRangeCfgUi(struct cart *cart, struct trackDb *tdb, char *name, char *title, boolean boxed) +/* Complete track controls for long range interaction. */ +{ +char buffer[1024]; +safef(buffer, sizeof buffer, "%s.%s", tdb->track, LONG_HEIGHT ); +unsigned height = sqlUnsigned(cartUsualString(cart, buffer, LONG_DEFHEIGHT)); +printf("
Track height: "); +cgiMakeIntVar(buffer, height, 3); +safef(buffer, sizeof buffer, "%s.%s", tdb->track, LONG_MINSCORE); +double minScore = sqlDouble(cartUsualString(cart, buffer, LONG_DEFMINSCORE)); +printf("

Minimum score: "); +cgiMakeDoubleVar(buffer, minScore, 0); +} + +static char *getOther(struct bed *bed, unsigned *s, unsigned *e, double *score) +{ +char *otherChrom = cloneString(bed->name); +char *ptr = strchr(otherChrom, ':'); +if (ptr == NULL) + errAbort("bad longTabix bed name %s\n", bed->name); +*ptr++ = 0; +*s = atoi(ptr); +ptr = strchr(ptr, '-'); +if (ptr == NULL) + errAbort("bad longTabix bed name %s\n", bed->name); +ptr++; +*e = atoi(ptr); +ptr = strchr(ptr, ','); +if (ptr == NULL) + errAbort("bad longTabix bed name %s\n", bed->name); +ptr++; +*score = sqlDouble(ptr); + +return otherChrom; +} + +struct longRange *parseLongTabix(struct bed *beds, unsigned *maxWidth, double minScore) +{ +struct longRange *longRangeList = NULL; +for(; beds; beds=beds->next) + { + double score; + unsigned otherS; + unsigned otherE; + char *otherChrom = getOther(beds, &otherS, &otherE, &score); + if (score < minScore) + continue; + + struct longRange *longRange; + AllocVar(longRange); + slAddHead(&longRangeList, longRange); + + unsigned otherCenter = (otherS + otherE)/2; + unsigned otherWidth = otherE - otherS; + unsigned thisWidth = beds->chromEnd - beds->chromStart; + unsigned center = (beds->chromEnd + beds->chromStart) / 2; + + // don't have oriented feet at the moment + longRange->sOrient = longRange->eOrient = 0; + longRange->id = beds->score; + longRange->score = score; + longRange->name = beds->name; + + if (otherCenter < center) + { + longRange->s = otherCenter; + longRange->sw = otherWidth; + longRange->sChrom = otherChrom; + longRange->e = center; + longRange->ew = thisWidth; + longRange->eChrom = beds->chrom; + } + else + { + longRange->s = center; + longRange->sw = thisWidth; + longRange->sChrom = beds->chrom; + longRange->e = otherCenter; + longRange->ew = otherWidth; + longRange->eChrom = otherChrom; + } + unsigned longRangeWidth = longRange->e - longRange->s; + if (longRangeWidth > *maxWidth) + *maxWidth = longRangeWidth; + } +return longRangeList; +}