49c5df6c8158b664a05dbd0ced17d19a25b822d6
fanhsu
  Thu Jun 23 12:51:49 2011 -0700
Added label processing for omimGene2 track.
diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 4ddfece..4c0e660 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -11079,35 +11079,103 @@
     else if (sameWord(phenClass, "4"))
 	{
 	// set to the color for phenClass 4
         sqlFreeResult(&sr);
 	return class4Clr; 
 	}
     else
 	{
 	// set to the color for Others
         sqlFreeResult(&sr);
 	return classOtherClr; 
 	}
     }
 }
 
+char * omimGene2Name(struct track *tg, void *item)
+/* Returns a combination of OMIM ID and/or gene symbol(s) depending on user's selection */
+{
+struct bed *el = item;
+
+struct sqlConnection *conn = hAllocConn(database);
+boolean labelStarted = FALSE;
+boolean useGeneSymbol = FALSE;
+boolean useOmimId =  FALSE;
+char *geneSymbol;
+char *omimId;
+struct hashEl *omimGene2Labels = cartFindPrefix(cart, "omimGene2.label");
+struct hashEl *label;
+
+if (omimGene2Labels == NULL)
+    {
+    useOmimId = TRUE; /* default to omim ID*/
+    /* set cart to match the default set */
+    cartSetBoolean(cart, "omimGene2.label.omimId", TRUE);
+    }
+else
+    {
+    for (label = omimGene2Labels; label != NULL; label = label->next)
+    	{
+    	if (endsWith(label->name, "gene") && differentString(label->val, "0"))
+	    {
+	    useGeneSymbol = TRUE;
+	    }
+    	else if (endsWith(label->name, "omimId") && differentString(label->val, "0"))
+    	    {
+            useOmimId = TRUE;
+	    }  
+    	}	
+    }
+
+struct dyString *name = dyStringNew(SMALLDYBUF);
+labelStarted = FALSE; /* reset for each item in track */
+
+if (useOmimId)
+    {
+    omimId = strdup(el->name);
+    if (omimId != NULL)
+        {
+        dyStringAppend(name, omimId);
+        }
+    labelStarted = TRUE;
+    }
+
+if (useGeneSymbol)
+    {
+    if (labelStarted) 
+    	dyStringAppendC(name, '/');
+    else 
+    	labelStarted = TRUE;
+    // get gene symbol(s) from omimGeneMap table.
+    // Note: some entries are not in omimGeneMap and/or does not have gene symbol(s)
+    char query[256];
+    safef(query, sizeof(query), "select geneSymbol from omimGeneMap where omimId = %s", el->name);
+    geneSymbol = sqlQuickString(conn, query);
+    if (geneSymbol && differentString(geneSymbol, "0"))
+        dyStringAppend(name, geneSymbol);
+    }
+
+hFreeConn(&conn);
+return(name->string);
+}
+
 void omimGene2Methods (struct track *tg)
 /* Methods for version 2 of OMIM Genes track. */
 {
 tg->loadItems	  = omimGene2Load;
 tg->itemColor 	  = omimGene2Color;
+tg->itemName	  = omimGene2Name;
 tg->itemNameColor = omimGene2Color;
 tg->drawItemAt    = bedPlusLabelDrawAt;
 tg->mapItem       = bedPlusLabelMapItem;
 tg->nextPrevExon = simpleBedNextPrevEdge;
 }
 
 static char *omimAvSnpAaReplacement(char *name)
 /* Return replacement string associated with a OMIM AV (Allelic Variant) entry */
 {
 static char omimAvSnpBuffer[256];
 struct sqlConnection *conn;
 char query[256];
 struct sqlResult *sr;
 char **row;