b7da88f01046d47191f922563fef44b132f7626c
fanhsu
  Fri Feb 18 16:50:20 2011 -0800
Added function for omimLocation to set color for its entries of different classes.
diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 6fde82b..5099e1d 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -10987,39 +10987,38 @@
 
 // get gene symbol(s) first
 
 conn = hAllocConn(database);
 safef(query,sizeof(query),
         "select geneSymbol from omimGeneMap where omimId =%s", item->name);
 sr = sqlMustGetResult(conn, query);
 row = sqlNextRow(sr);
 
 if (row != NULL) 
     {
     safef(omimGeneClass3Buffer, sizeof(omimGeneClass3Buffer), "%s; disorder(s): ", row[0]);
     }
 
 chp = omimGeneClass3Buffer + (long)strlen(row[0]) + 15L; 
+sqlFreeResult(&sr);
 
-conn = hAllocConn(database);
 safef(query,sizeof(query),
         "select distinct disorder from omimDisorderMap, omimGeneClass3 where name='%s' and name=cast(omimId as char) order by disorder", item->name);
 sr = sqlMustGetResult(conn, query);
 row = sqlNextRow(sr);
 
 /* show up to 20 max entries */
-//chp = omimGeneClass3Buffer;
 while ((row != NULL) && i<20)
     {
     int lengthLeft = sizeof(omimGeneClass3Buffer) - strlen(omimGeneClass3Buffer);
     /* omimDisorderMap disorder field some times have trailing blanks. */
     eraseTrailingSpaces(row[0]);
     if (i != 0)
 	{
 	safef(chp, 3, "; ");
 	chp++;chp++;
 	}
     safecpy(chp, lengthLeft, row[0]);
     lengthLeft = lengthLeft - strlen(row[0]) - 2;
     
     safecpy(chp, OMIM_MAX_DESC_LEN, row[0]);
     
@@ -11198,66 +11197,131 @@
         "select concat(title1, ' ', title2) from omimGeneMap where omimId=%s", item->name);
 sr = sqlMustGetResult(conn, query);
 row = sqlNextRow(sr);
 
 chp = omimLocationBuffer;
 if (row != NULL) 
     {
     safef(omimLocationBuffer, sizeof(omimLocationBuffer), "%s", row[0]);
     }
 
 hFreeConn(&conn);
 sqlFreeResult(&sr);
 return(omimLocationBuffer);
 }
 
+Color omimLocationColor(struct track *tg, void *item, struct hvGfx *hvg)
+/* set the color for omimLocation track items */
+{
+struct bed *el = item;
+char *omimId;
+char *phenClass;
+char query[256];
+struct sqlResult *sr;
+char **row;
+
+struct sqlConnection *conn = hAllocConn(database);
+
+safef(query, sizeof(query), 
+      "select omimId, phenotypeClass from omimDisorderPhenotype where omimId=%s", el->name);
+sr = sqlMustGetResult(conn, query);
+row = sqlNextRow(sr);
+
+hFreeConn(&conn);
+
+if (row == NULL)
+    {
+    // set to gray if this entry does not have any disorder info
+    sqlFreeResult(&sr);
+    return hvGfxFindColorIx(hvg, 200, 200, 200);
+    }
+else
+    {
+    omimId    = row[0];
+    phenClass = row[1];
+
+    if (sameWord(phenClass, "3"))
+    	{
+	// set to dark red, the same color as omimGeneClass3 track
+	sqlFreeResult(&sr);
+	return hvGfxFindColorIx(hvg, 220, 0, 0);
+    	}	
+    else
+    	{
+    	if (sameWord(phenClass, "2"))
+    	    {
+	    // set to green for class 2
+	    sqlFreeResult(&sr);
+	    return hvGfxFindColorIx(hvg, 0, 255, 0);
+    	    }	
+	else
+	    {
+    	    if (sameWord(phenClass, "1"))
+    	    	{
+		// set to orange for class 1
+	    	sqlFreeResult(&sr);
+	    	return hvGfxFindColorIx(hvg, 200, 0, 200);
+    	    	}
+	    else
+	    	{
+	    	// set to purplish color for phenClass 4
+            	sqlFreeResult(&sr);
+	    	return hvGfxFindColorIx(hvg, 200, 100, 100);
+            	}
+	    }
+
+	}  
+    }
+}
+
 static void omimLocationDrawAt(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. */
 {
 struct bed *bed = item;
 char *omimTitle;
 int heightPer = tg->heightPer;
 int x1 = round((double)((int)bed->chromStart-winStart)*scale) + xOff;
 int x2 = round((double)((int)bed->chromEnd-winStart)*scale) + xOff;
 int w;
 
 omimTitle = omimLocationDescription(tg, item);
 w = x2-x1;
 if (w < 1)
     w = 1;
 if (color)
     {
-    hvGfxBox(hvg, x1, y, w, heightPer, color);
+    hvGfxBox(hvg, x1, y, w, heightPer, omimLocationColor(tg, item, hvg));
 
     if (vis == tvFull)
         {
         hvGfxTextRight(hvg, x1-mgFontStringWidth(font, omimTitle)-2, y,
 		    mgFontStringWidth(font, omimTitle),
                     heightPer, MG_BLACK, font, omimTitle);
         }
 
     if (vis != tvDense)
    	mapBoxHc(hvg, bed->chromStart, bed->chromEnd, x1, y, x2 - x1, heightPer,
 	         tg->track, tg->mapItemName(tg, bed), omimTitle);
     }
 }
 
 void omimLocationMethods (struct track *tg)
 {
 tg->drawItemAt    = omimLocationDrawAt;
+tg->itemColor     = omimLocationColor;
 }
 
 char *omimGeneName(struct track *tg, void *item)
 /* set name for omimGene track */
 {
 struct bed *el = item;
 char query[256];
 struct sqlConnection *conn = hAllocConn(database);
 char *geneLabel = NULL;
 
 char *omimGeneLabel = cartUsualString(cart, "omimGene.label", "OMIM ID");
 
 if (sameWord(omimGeneLabel, "OMIM ID"))
     {
     geneLabel = el->name;