src/hg/hgTracks/simpleTracks.c 1.144

1.144 2010/05/28 19:50:34 fanhsu
Added function to set color for DECIPHER entries.
Index: src/hg/hgTracks/simpleTracks.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/simpleTracks.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -b -B -U 4 -r1.143 -r1.144
--- src/hg/hgTracks/simpleTracks.c	27 May 2010 21:13:24 -0000	1.143
+++ src/hg/hgTracks/simpleTracks.c	28 May 2010 19:50:34 -0000	1.144
@@ -5126,8 +5126,51 @@
 sqlFreeResult(&sr);
 return(decipherBuffer);
 }
 
+Color decipherColor(struct track *tg, void *item, struct hvGfx *hvg)
+/* Return color to draw DECIPHER entry */
+{
+struct bed *bedItem = item;
+int col = tg->ixColor;
+struct sqlConnection *conn = hAllocConn(database);
+struct sqlResult *sr;
+char **row;
+char query[256];
+char cond_str[256];
+char *decipherId = NULL;
+
+/* color scheme:
+	RED:	If the entry is a deletion (mean ratio < 0)
+	GREEN:	If the entry is a duplication (mean ratio > 0)
+*/
+sprintf(cond_str, "name='%s' ", bedItem->name);
+decipherId = sqlGetField(database, "decipher", "name", cond_str);
+if (decipherId != NULL)
+    {
+    if (hTableExists(database, "decipherRaw"))
+    	{
+    	sprintf(query, "select mean_ratio > 0 from decipherRaw where id = '%s'", decipherId);
+    	sr = sqlGetResult(conn, query);
+    	if ((row = sqlNextRow(sr)) != NULL)
+            {
+	    if (sameWord(row[0], "1"))
+	    	{
+	    	col = MG_GREEN;
+	    	}
+	    else
+		{
+	    	col = MG_RED;
+		}
+	    }
+	sqlFreeResult(&sr);
+	}
+    }
+
+hFreeConn(&conn);
+return(col);
+}
+
 static void decipherDrawAt(struct track *tg, void *item,
 	struct hvGfx *hvg, int xOff, int y,
 	double scale, MgFont *font, Color color, enum trackVisibility vis)
 /* Draw a single superfamily item at position. */
@@ -5144,9 +5187,9 @@
 if (w < 1)
     w = 1;
 if (color)
     {
-    hvGfxBox(hvg, x1, y, w, heightPer, color);
+    hvGfxBox(hvg, x1, y, w, heightPer, decipherColor(tg, item, hvg));
 
     if (vis == tvFull)
         {
         hvGfxTextRight(hvg, x1-mgFontStringWidth(font, sPhenotypes)-2, y,
@@ -5182,12 +5225,12 @@
 		dir, textColor, TRUE);
 	}
     }
 }
-
 void decipherMethods(struct track *tg)
 /* Methods for DECIPHER track. */
 {
+tg->itemColor   = decipherColor;
 tg->drawItemAt 	= decipherDrawAt;
 }
 
 void gadMethods(struct track *tg)