d24f68e60112fbd009085ec5f7a7d59b05160cec
tdreszer
  Tue Nov 1 10:10:40 2011 -0700
Added extraFields support for bigBeds in hgc.
diff --git src/hg/hgc/bigBedClick.c src/hg/hgc/bigBedClick.c
index 879eb53..402e260 100644
--- src/hg/hgc/bigBedClick.c
+++ src/hg/hgc/bigBedClick.c
@@ -1,29 +1,72 @@
 /* Handle details pages for wiggle tracks. */
 
 #include "common.h"
 #include "wiggle.h"
 #include "cart.h"
 #include "hgc.h"
 #include "hCommon.h"
 #include "hgColors.h"
 #include "bigBed.h"
 #include "hui.h"
 
 static char const rcsid[] = "$Id: bigBedClick.c,v 1.11 2010/05/11 01:43:28 kent Exp $";
 
 
+static int bigBedExtraFieldsPrint(struct trackDb *tdb, char *extraFields[],int extraCount)
+// Any extra fields defined in trackDb.  Returns number of extra fields actually printed
+{
+// Additional fields requested in trackDb?
+struct extraField *extras = extraFieldsGet(tdb);
+if (extras == NULL)
+    return 0;
+
+int ix = 0;
+struct extraField *extra = extras;
+for(;extra != NULL && ix <extraCount;extra=extra->next, ix++)
+    {
+    // Note: unlike for sql tables, extraFields is necessarily in sequential order
+
+    // Print as table rows
+    if(ix == 0)
+        printf("<br><table>");
+    printf("<tr><td><B>%s:</B></td>", extra->label);
+    switch (extra->type)
+        {
+        case ftInteger: {
+                        long long valInt = sqlLongLong(extraFields[ix]);
+                        printf("<td>%lld</td></tr>\n", valInt);
+                        }
+                        break;
+        case ftFloat:   {
+                        double valDouble = sqlDouble(extraFields[ix]);
+                        printf("<td>%g</td></tr>\n", valDouble);
+                        }
+                        break;
+        default:
+                        printf("<td>%s</td></tr>\n", extraFields[ix]);
+                        break;
+        }
+    }
+extraFieldsFree(&extras);
+
+if(ix > 0)
+    printf("</table>\n");
+
+return ix;
+}
+
 static void bigBedClick(char *fileName, struct trackDb *tdb, 
 		     char *item, int start, int bedSize)
 /* Handle click in generic bigBed track. */
 {
 boolean showUrl = FALSE;
 char *chrom = cartString(cart, "c");
 
 /* Open BigWig file and get interval list. */
 struct bbiFile *bbi = bigBedFileOpen(fileName);
 struct lm *lm = lmInit(0);
 struct bigBedInterval *bbList = bigBedIntervalQuery(bbi, chrom, winStart, winEnd, 0, lm);
 
 /* Get bedSize if it's not already defined. */
 if (bedSize == 0)
     {
@@ -77,40 +120,43 @@
     if (showUrl && (bedSize >= 4))
 	printCustomUrl(tdb, item, TRUE);
     bedPrintPos(bed, bedSize, tdb);
 
     // display seq1 and seq2 
     if (seq1Seq2 && bedSize+seq1Seq2Fields == 8)
         printf("<table><tr><th>Sequence 1</th><th>Sequence 2</th></tr>"
 	       "<tr><td> %s </td><td> %s </td></tr></table>", fields[6], fields[7]);
     else if (isNotEmpty(rest))
 	{
 	char *restFields[256];
 	int restCount = chopTabs(rest, restFields);
 	int restBedFields = bedSize - 3;
 	if (restCount > restBedFields)
 	    {
+            if (0 == bigBedExtraFieldsPrint(tdb, restFields + restBedFields,restCount - restBedFields))
+                {
 	    int i;
 	    char label[20];
 	    safef(label, sizeof(label), "nonBedFieldsLabel");
 	    printf("<B>%s&nbsp;</B>",
                trackDbSettingOrDefault(tdb, label, "Non-BED fields:"));
 	    for (i = restBedFields;  i < restCount;  i++)
 		printf("%s%s", (i > 0 ? "\t" : ""), restFields[i]);
 	    printf("<BR>\n");
 	    }
 	}
+	}
     if (isCustomTrack(tdb->track))
 	{
 	time_t timep = bbiUpdateTime(bbi);
 	printBbiUpdateTime(&timep);
 	}
     }
 else
     {
     printf("No item %s starting at %d\n", emptyForNull(item), start);
     }
 
 lmCleanup(&lm);
 bbiFileClose(&bbi);
 }