src/hg/hgc/expClick.c 1.24

1.24 2010/01/22 22:52:04 aamp
Microarray tracks and custom microarray tracks now support the "expColor" trackDb setting which can be "redGreen" (default), "redBlue", "redBlueOnWhite", "yellowBlue", or "redBlueOnYellow". Some things wre changed around so that adding more color options in the future is a cinch.
Index: src/hg/hgc/expClick.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgc/expClick.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -b -B -U 4 -r1.23 -r1.24
--- src/hg/hgc/expClick.c	5 Mar 2009 10:09:22 -0000	1.23
+++ src/hg/hgc/expClick.c	22 Jan 2010 22:52:04 -0000	1.24
@@ -17,9 +17,9 @@
 /* global flag to indicate if the track is a cancer genomics track */
 boolean isCancerGenomicsTrack = FALSE;
 
 static struct rgbColor getColorForExprBed(float val, float max,
-	boolean redGreen, boolean redBlueOnWhite)
+        enum expColorType colorScheme)
 /* Return the correct color for a given score */
 {
 float absVal = fabs(val);
 struct rgbColor color; 
@@ -36,28 +36,24 @@
     absVal = max;
 if (max == 0) 
     errAbort("ERROR: hgc::getColorForExprBed() maxDeviation can't be zero\n"); 
 colorIndex = (int)(absVal * 255/max);
-
-
-if (redGreen) 
-    {
-   if(val > 0) 
-	{
+color.r = color.g = color.b = 0;
+if (colorScheme == redBlue)
+    if (val > 0)
 	color.r = colorIndex; 
-	color.g = 0;
-	color.b = 0;
-	}
     else 
+	color.b = colorIndex;
+else if (colorScheme == yellowBlue)
+    if (val > 0)
 	{
-	color.r = 0;
+	color.r = colorIndex;
 	color.g = colorIndex;
-	color.b = 0;
 	}
-    }
-else if (redBlueOnWhite)
-    {
-    if(val > 0) 
+    else
+	color.b = colorIndex;
+else if (colorScheme == redBlueOnWhite)
+    if (val > 0)
 	{
 	color.r = 255; 
 	color.g = 255 - colorIndex;
 	color.b = 255 - colorIndex;
@@ -67,24 +63,25 @@
 	color.r = 255 - colorIndex;
 	color.g = 255 - colorIndex;
 	color.b = 255;
 	}	
-    }
-else
-    {
-    if(val > 0) 
+else if (colorScheme == redBlueOnYellow)
+    if (val > 0)
 	{
-	color.r = colorIndex; 
-	color.g = colorIndex;
-	color.b = 0;
+	color.r = 255;
+	color.g = 255 - colorIndex;
 	}
     else 
 	{
-	color.r = 0;
-	color.g = 0;
+	color.r = 255 - colorIndex;
+	color.g = 255 - colorIndex;
 	color.b = colorIndex;
 	}	
-    }
+else
+    if (val > 0)
+	color.r = colorIndex;
+    else
+	color.g = colorIndex;
 
 return color;
 }
 
@@ -123,9 +120,9 @@
 msBedPrintTableHeader(bedList, erHash, itemName, headerNames, ArraySize(headerNames), scoresHeader);
 }
 
 static void printExprssnColorKey(float minVal, float maxVal, float stepSize, int base,
-	struct rgbColor(*getColor)(float val, float maxVal, boolean redGreen, boolean redBlueOnWhite), boolean redGreen, boolean redBlueOnWhite)
+	  struct rgbColor(*getColor)(float val, float maxVal, enum expColorType colorScheme), enum expColorType colorScheme)
 /* print out a little table which provides a color->score key */
 {
 float currentVal = -1 * maxVal;
 int numColumns;
@@ -143,18 +140,18 @@
     }
 printf("</tr><tr>\n");
 for(currentVal = minVal; currentVal <= maxVal + (stepSize/2); currentVal += stepSize)
     {
-    struct rgbColor rgb = getColor(currentVal, maxVal, redGreen, redBlueOnWhite);
+    struct rgbColor rgb = getColor(currentVal, maxVal, colorScheme);
     printf("<td bgcolor=\"#%.2X%.2X%.2X\">&nbsp</td>\n", rgb.r, rgb.g, rgb.b);
     }
 printf("</tr></table>\n");
 printf("</td></tr></table>\n");
 }
 
 static void msBedExpressionPrintRow(struct bed *bedList, struct hash *erHash, 
      int expIndex, char *expName, float maxScore,
-    boolean redGreen, boolean redBlueOnWhite)
+     enum expColorType colorScheme)
 /* print the name of the experiment and color the 
    background of individual cells using the score to 
    create false two color display */
 {
@@ -182,9 +179,9 @@
     }
 for(bed = bedList;bed != NULL; bed = bed->next)
     {
     /* use the background colors to creat patterns */
-    struct rgbColor rgb = getColorForExprBed(bed->expScores[expIndex], maxScore, redGreen, redBlueOnWhite);
+    struct rgbColor rgb = getColorForExprBed(bed->expScores[expIndex], maxScore, colorScheme);
     printf("<td height=%d width=%d bgcolor=\"#%.2X%.2X%.2X\">&nbsp</td>\n", square, square, rgb.r, rgb.g, rgb.b);
     }
 printf("</tr>\n");
 }
@@ -192,29 +189,29 @@
 static void msBedPrintTable(struct bed *bedList, struct hash *erHash,
     char *itemName, char *expName, float minScore, float maxScore,
     float stepSize, int base,
     void(*printHeader)(struct bed *bedList, struct hash *erHash, char *item),
-    void(*printRow)(struct bed *bedList,struct hash *erHash, int expIndex, char *expName, float maxScore, boolean redGreen, boolean redBlueOnWhite),
-    void(*printKey)(float minVal, float maxVal, float size, int base, struct rgbColor(*getColor)(float val, float max, boolean redGreen, boolean redBlueOnWhite), boolean redGreen, boolean redBlueOnWhite),
-    struct rgbColor(*getColor)(float val, float max, boolean redGreen, boolean redBlueOnWhite),
-	boolean redGreen, boolean redBlueOnWhite)
+			    void(*printRow)(struct bed *bedList,struct hash *erHash, int expIndex, char *expName, float maxScore, enum expColorType colorScheme),
+    void(*printKey)(float minVal, float maxVal, float size, int base, struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme), enum expColorType colorScheme),
+    struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme),
+	enum expColorType colorScheme)
 /* prints out a table from the data present in the bedList */
 {
 int i,featureCount=0;
 if(bedList == NULL)
     errAbort("hgc::msBedPrintTable() - bedList is NULL");
 featureCount = slCount(bedList);
 /* time to write out some html, first the table and header */
 if(printKey != NULL)
-    printKey(minScore, maxScore, stepSize, base, getColor, redGreen, redBlueOnWhite);
+    printKey(minScore, maxScore, stepSize, base, getColor, colorScheme);
 printf("<p>\n");
 printf("<basefont size=-1>\n");
 printf("<table  bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td>");
 printf("<table  bgcolor=\"#fffee8\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">");
 printHeader(bedList, erHash, itemName);
 for(i=0; i<bedList->expCount; i++)
     {
-    printRow(bedList, erHash, i, expName, maxScore, redGreen, redBlueOnWhite);
+    printRow(bedList, erHash, i, expName, maxScore, colorScheme);
     }
 printf("</table>");
 printf("</td></tr></table>");
 printf("</basefont>");
@@ -423,33 +420,22 @@
 double stepSize = atof(expStep);
 struct bed *bedList;
 char *itemName = cgiUsualString("i2","none");
 char *expName = (item == NULL) ? itemName : item;
-boolean redGreen = TRUE;
-boolean redBlueOnWhite = FALSE;
+char *tdbSetting = trackDbSettingOrDefault(tdb, "expColor", "redGreen");
+char *colorVal = NULL;
+enum expColorType colorScheme;
 char colorVarName[256];
+safef(colorVarName, sizeof(colorVarName), "%s.color", tdb->tableName);
+colorVal = cartUsualString(cart, colorVarName, tdbSetting);
+colorScheme = getExpColorType(colorVal);
 
 if (sameWord(tdb->grp, "cancerGenomics"))
     {
     /* set global flag */
     isCancerGenomicsTrack = TRUE;
     }
 
-safef(colorVarName, sizeof(colorVarName), "%s.color", tdb->tableName);
-/* decide color scheme flags */
-if (!sameString(cartUsualString(cart, colorVarName, "redGreen"), "redGreen"))
-    {
-    if (sameString(cartUsualString(cart, colorVarName, "redGreen"), "redBlueOnWhite"))
-    	{
-	redBlueOnWhite = TRUE;
-    	redGreen = FALSE;
-	}
-    else
-    	{
-    	redGreen = FALSE;
-	}
-    }
-
 if (!ct)
     {
     genericHeader(tdb, itemName);
     bedList = loadMsBed(tdb, tdb->tableName, seqName, winStart, winEnd);
@@ -490,9 +476,9 @@
 	}
     puts("<h2></h2><p>\n");
     msBedPrintTable(bedList, erHash, itemName, expName, -1*maxScore, maxScore,
 	stepSize, 2, msBedDefaultPrintHeader, msBedExpressionPrintRow,
-	printExprssnColorKey, getColorForExprBed, redGreen, redBlueOnWhite);
+	printExprssnColorKey, getColorForExprBed, colorScheme);
     hashTraverseEls(erHash, erHashElFree);
     hashFree(&erHash);
     microarrayGroupsFree(&groupings);
     }