src/hg/lib/hui.c 1.206

1.206 2009/05/29 22:19:50 hiram
Fixup chainCfgUi to honor a normScore option from the trackDb composite bucket
Index: src/hg/lib/hui.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hui.c,v
retrieving revision 1.205
retrieving revision 1.206
diff -b -B -U 4 -r1.205 -r1.206
--- src/hg/lib/hui.c	27 May 2009 21:36:17 -0000	1.205
+++ src/hg/lib/hui.c	29 May 2009 22:19:50 -0000	1.206
@@ -12,8 +12,9 @@
 #include "hui.h"
 #include "hCommon.h"
 #include "hgConfig.h"
 #include "chainCart.h"
+#include "chainDb.h"
 #include "netCart.h"
 #include "obscure.h"
 #include "wiggle.h"
 #include "phyloTree.h"
@@ -3650,21 +3651,63 @@
 
 enum chainColorEnum chainColor =
 	chainFetchColorOption(cart, tdb, compositeLevel);
 
+/* check if we have normalized scores available */
+boolean normScoreAvailable = FALSE;
+
+if (! compositeLevel)
+    {
+    // This will not work if tableName is a split table, we don't know
+    //	the chromosome at this point here
+    struct sqlConnection *conn = hAllocConn(db);
+    int tblIx = sqlFieldIndex(conn, tdb->tableName, "normScore");
+    normScoreAvailable = (tblIx > -1) ? TRUE : FALSE;
+    hFreeConn(&conn);
+    }
+else
+    {
+    char * colorOptionType =
+     trackDbSettingClosestToHomeOrDefault(tdb, "chainNormScoreAvailable", "no");
+    if (differentWord(colorOptionType, "no"))
+	normScoreAvailable = TRUE;
+    }
+
 char optString[256];
-safef(optString, ArraySize(optString), "%s.%s", prefix, OPT_CHROM_COLORS );
-printf("<p><b>Color chains by:&nbsp;</b>");
-chainColorDropDown(optString, chainColorEnumToString(chainColor));
+if (normScoreAvailable)
+    {
+    safef(optString, ArraySize(optString), "%s.%s", prefix, OPT_CHROM_COLORS );
+    printf("<p><b>Color chains by:&nbsp;</b>");
+    chainColorDropDown(optString, chainColorEnumToString(chainColor));
+    }
+else
+    {
+    printf("<p><b>Color track based on chromosome:</b>&nbsp;");
 
+    char optString[256];
+    /* initial value of chromosome coloring option is "on", unless
+     * overridden by the colorChromDefault setting in the track */
+    char *binaryColorDefault =
+	    trackDbSettingClosestToHomeOrDefault(tdb, "colorChromDefault", "on");
+    /* allow cart to override trackDb setting */
+    safef(optString, sizeof(optString), "%s.color", prefix);
+    char * colorSetting = cartUsualStringClosestToHome(cart, tdb,
+	compositeLevel, "color", binaryColorDefault);
+    cgiMakeRadioButton(optString, "on", sameString(colorSetting, "on"));
+    printf(" on ");
+    cgiMakeRadioButton(optString, "off", sameString(colorSetting, "off"));
+    printf(" off ");
+    printf("<br>\n");
+    }
 
 printf("<p><b>Filter by chromosome (e.g. chr10):</b> ");
 safef(optString, ArraySize(optString), "%s.%s", prefix, OPT_CHROM_FILTER);
 cgiMakeTextVar(optString,
     cartUsualStringClosestToHome(cart, tdb, compositeLevel,
 	OPT_CHROM_FILTER, ""), 15);
 
-scoreCfgUi(db, cart,tdb,prefix,NULL,CHAIN_SCORE_MAXIMUM,FALSE);
+if (normScoreAvailable)
+    scoreCfgUi(db, cart,tdb,prefix,NULL,CHAIN_SCORE_MAXIMUM,FALSE);
 
 cfgEndBox(boxed);
 }