Index: src/hg/hgc/bigBedClick.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgc/bigBedClick.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -b -B -U 1000000 -r1.8 -r1.9
--- src/hg/hgc/bigBedClick.c	19 Feb 2010 00:22:30 -0000	1.8
+++ src/hg/hgc/bigBedClick.c	19 Feb 2010 23:24:34 -0000	1.9
@@ -1,110 +1,124 @@
 /* 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$";
 
 
 static void bigBedClick(char *fileName, struct trackDb *tdb, 
 		     char *item, int start, int bedSize)
 /* Handle click in generic bigBed track. */
 {
 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)
     bedSize = bbi->definedFieldCount;
 
 /* Find particular item in list - matching start, and item if possible. */
 struct bigBedInterval *bbMatch = NULL, *bb;
 for (bb = bbList; bb != NULL; bb = bb->next)
     {
     if (bb->start == start)
         {
 	if (bedSize > 3)
 	    {
 	    char *name = cloneFirstWordInLine(bb->rest);
 	    boolean match = sameString(name, item);
 	    freez(&name);
 	    if (match)
 	        {
 		bbMatch = bb;
 		break;
 		}
 	    }
 	else
 	    {
 	    bbMatch = bb;
 	    break;
 	    }
 	}
     }
 
 if (bbMatch != NULL)
     {
-    int extraFields = 0;
+    int seq1Seq2Fields = 0;
     // 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"))
-	extraFields = 2;
-    char *fields[bedSize+extraFields];
+    boolean seq1Seq2 = sameOk(trackDbSetting(tdb, BASE_COLOR_USE_SEQUENCE), "seq1Seq2");
+    if (seq1Seq2 && bedSize == 6)
+	seq1Seq2Fields = 2;
+    char *fields[bedSize+seq1Seq2Fields];
     char startBuf[16], endBuf[16];
     char *rest = cloneString(bbMatch->rest);
-    int bbFieldCount = bigBedIntervalToRow(bbMatch, chrom, startBuf, endBuf, fields, bedSize+extraFields); 
-    if (bbFieldCount != bedSize+extraFields)
+    int bbFieldCount = bigBedIntervalToRow(bbMatch, chrom, startBuf, endBuf, fields,
+					   bedSize+seq1Seq2Fields); 
+    if (bbFieldCount != bedSize+seq1Seq2Fields)
         {
 	errAbort("Disagreement between trackDb field count (%d) and %s fieldCount (%d)", 
 		bedSize, fileName, bbFieldCount);
 	}
     struct bed *bed = bedLoadN(fields, bedSize);
     if (bedSize >= 4)
 	printCustomUrl(tdb, item, TRUE);
     bedPrintPos(bed, bedSize, tdb);
+
     // display seq1 and seq2 
-    if (bedSize+extraFields == 8 && setting && sameString(setting, "seq1Seq2"))
-        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 (bedSize+extraFields > 6) // we have more fields to print
-	printf("Full bed record:<BR><PRE><TT>%s\t%u\t%u\t%s\n</TT></PRE>\n",
-		chrom, bb->start, bb->end, rest);
+    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
+	{
+	char *restFields[256];
+	int restCount = chopTabs(rest, restFields);
+	int restBedFields = bedSize - 3;
+	if (restCount > restBedFields)
+	    {
+	    int i;
+	    printf("<B>Non-BED fields:</B> ");
+	    for (i = restBedFields;  i < restCount;  i++)
+		printf("%s%s", (i > 0 ? "\t" : ""), restFields[i]);
+	    printf("<BR>\n");
+	    }
+	}
     }
 else
     {
     printf("No item %s starting at %d\n", emptyForNull(item), start);
     }
 
 lmCleanup(&lm);
 bbiFileClose(&bbi);
 }
 
 void genericBigBedClick(struct sqlConnection *conn, struct trackDb *tdb, 
 		     char *item, int start, int bedSize)
 /* Handle click in generic bigBed track. */
 {
 char query[256];
 safef(query, sizeof(query), "select fileName from %s", tdb->tableName);
 char *fileName = sqlQuickString(conn, query);
 if (fileName == NULL)
     errAbort("Missing fileName in %s table", tdb->tableName);
 bigBedClick(fileName, tdb, item, start, bedSize);
 }
 
 void bigBedCustomClick(struct trackDb *tdb)
 /* Display details for BigWig custom tracks. */
 {
 char *fileName = trackDbSetting(tdb, "bigDataUrl");
 char *item = cartOptionalString(cart, "i");
 int start = cartInt(cart, "o");
 bigBedClick(fileName, tdb, item, start, 0);
 }

