e0487e263a1b1782cbfe209a1db2baca0132c783
braney
  Sun Jan 23 11:15:11 2011 -0800
add click handler for interactions
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 77e9aec..7ab75ea 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -758,30 +758,118 @@
 	label = tdbLabel;
     printf("<B>%s:</B> %s<BR>\n", label, bed->name);
     }
 if (bedSize >= 5)
     {
     if (!tdb || !trackDbSetting(tdb, "noScoreFilter"))
 	printf("<B>Score:</B> %d<BR>\n", bed->score);
     }
 if (bedSize >= 6)
    {
    strand = bed->strand;
    }
 printPos(bed->chrom, bed->chromStart, bed->chromEnd, strand, TRUE, bed->name);
 }
 
+void interactionPrintPos( struct bed *bed, int bedSize, struct trackDb *tdb)
+/* Print first bedSize fields of a bed type structure in
+ * standard format. */
+{
+
+if (bed->blockCount == 2)
+    {
+    printf("<B>Intrachromosomal interaction:</B> <br>\n");
+    printf("<B>Positions:</B><br> ");
+    printf("<A HREF=\"%s&db=%s&position=%s%%3A%d-%d\">",
+	   hgTracksPathAndSettings(), database, bed->chrom, 
+	   bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0]);
+    printf("%s:%d-%d</A>    \n", 
+	   bed->chrom,
+	   bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0]);
+    printf("Size: %d   \n", bed->blockSizes[0]);
+    printBand( bed->chrom, bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0], FALSE);
+
+    //printf("<BR>\n");
+    printf("<A HREF=\"%s&db=%s&position=%s%%3A%d-%d\">",
+	   hgTracksPathAndSettings(), database, bed->chrom, 
+	   bed->chromStarts[1]+bed->chromStart, 
+	   bed->chromStarts[1]+bed->chromStart + bed->blockSizes[1]);
+    printf("%s:%d-%d</A>     \n", 
+	   bed->chrom,
+	   bed->chromStarts[1]+bed->chromStart, 
+	   bed->chromStarts[1]+bed->chromStart + bed->blockSizes[1]);
+    printf("Size: %d   \n", bed->blockSizes[0]);
+    printBand( bed->chrom, bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[1]+bed->chromStart + bed->blockSizes[1], FALSE);
+
+    printf("<BR>\n");
+    printf("<B>Distance apart:</B>\n"); 
+    printLongWithCommas(stdout,
+	bed->chromStarts[1] - bed->chromStarts[0] + bed->blockSizes[0]);
+
+    printf("bp<BR>\n");
+    }
+else
+    {
+    printf("<B>Interchromosomal interaction:</B> <br>\n");
+    printf("<B>Positions:</B><br> ");
+    printf("<A HREF=\"%s&db=%s&position=%s%%3A%d-%d\">",
+	   hgTracksPathAndSettings(), database, bed->chrom, 
+	   bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0]);
+    printf("%s:%d-%d</A>    \n", 
+	   bed->chrom,
+	   bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0]);
+    printf("Size: %d   \n", bed->blockSizes[0]);
+    printBand( bed->chrom, bed->chromStarts[0]+bed->chromStart, 
+	   bed->chromStarts[0]+bed->chromStart + bed->blockSizes[0], FALSE);
+
+    char buffer[10 * 1024], *otherChrom = buffer;
+    safef(buffer, sizeof buffer, "%s", bed->name);
+    char *ptr;
+    int otherStart, otherEnd;
+
+    if (startsWith(bed->chrom, buffer))
+	{
+	otherChrom = strchr(buffer,'-');
+	otherChrom++;
+	}
+
+    ptr = strchr(otherChrom,':');
+    *ptr++ = 0;
+    otherStart = atoi(ptr);
+    ptr = strchr(ptr,'.');
+    ptr++;
+    ptr++;
+    otherEnd = atoi(ptr);
+    //printf("<BR>\n");
+    printf("<A HREF=\"%s&db=%s&position=%s%%3A%d-%d\">",
+	   hgTracksPathAndSettings(), database, otherChrom,
+	   otherStart, otherEnd);
+    printf("%s:%d-%d</A>     \n", 
+	   otherChrom, otherStart, otherEnd);
+    printf("Size: %d   \n", otherEnd - otherStart);
+    printBand( otherChrom, otherStart, otherEnd, FALSE);
+
+    printf("<BR>\n");
+    }
+}
+
 
 void genericHeader(struct trackDb *tdb, char *item)
 /* Put up generic track info. */
 {
 if (item != NULL && item[0] != 0)
     cartWebStart(cart, database, "%s (%s)", tdb->longLabel, item);
 else
     cartWebStart(cart, database, "%s", tdb->longLabel);
 didCartHtmlStart = TRUE;
 }
 
 static struct dyString *subMulti(char *orig, int subCount,
 				 char *in[], char *out[])
 /* Perform multiple substitions on orig. */
 {
@@ -1319,30 +1407,35 @@
     if (hti && *hti->nameField && differentString("name", hti->nameField))
 	sprintf(query, "select * from %s where %s = '%s' and chrom = '%s' and chromStart = %d",
 	    table, hti->nameField, escapedName, seqName, start);
     else
 	sprintf(query, "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d",
 	    table, escapedName, seqName, start);
     }
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     if (firstTime)
 	firstTime = FALSE;
     else
 	htmlHorizontalLine();
     bed = bedLoadN(row+hasBin, bedSize);
+    if ((tdb->type != NULL) && sameString(tdb->type, "interaction"))
+	{
+	interactionPrintPos( bed, bedSize, tdb);
+	}
+    else
     bedPrintPos(bed, bedSize, tdb);
     // check for seq1 and seq2 in columns 7+8 (eg, pairedTagAlign)
     char *setting = trackDbSetting(tdb, BASE_COLOR_USE_SEQUENCE);
     if (bedSize == 6 && setting && sameString(setting, "seq1Seq2"))
 	printf("<br><B>Sequence 1:</B> %s<br><B>Sequence 2:</B> %s<br>\n",row[hasBin+6], row[hasBin+7]);
     printCompareGenomeLinks(tdb,bed->name);
     }
 sqlFreeResult(&sr);
 getBedTopScorers(conn, tdb, table, item, start, bedSize);
 }
 
 #define INTRON 10
 #define CODINGA 11
 #define CODINGB 12
 #define UTR5 13
@@ -3701,30 +3794,35 @@
 	doBed5FloatScore(tdb, item);
 	}
     else if (sameString(type, "bed6FloatScore"))
 	{
 	doBed6FloatScore(tdb, item);
 	}
     else if (sameString(type, "altGraphX"))
         {
 	doAltGraphXDetails(tdb,item);
 	}
     //add bedDetail here
     else if (startsWith("bedDetail", type))
         {
         doBedDetail(tdb, NULL, item);
         }
+    else if (sameString(type, "interaction") )
+	{
+	int num = 12;
+        genericBedClick(conn, tdb, item, start, num);
+	}
 #ifdef USE_BAM
     else if (sameString(type, "bam"))
 	doBamDetails(tdb, item);
 #endif // USE_BAM
     }
 if (imagePath)
     {
     char *bigImagePath = trackDbSettingClosestToHome(tdb, ITEM_BIG_IMAGE_PATH);
     char *bothWords[2];
     int shouldBeTwo = chopLine(imagePath, bothWords);
     if (shouldBeTwo != 2)
 	errAbort("itemImagePath setting for %s track incorrect. Needs to be \"itemImagePath <path> <suffix>\".", tdb->track);
     printf("<BR><IMG SRC=\"%s/%s.%s\"><BR><BR>\n", bothWords[0], item, bothWords[1]);
     shouldBeTwo = chopLine(bigImagePath, bothWords);
     if (shouldBeTwo != 2)