4725917ec779f7bfd48575084715500b618bccd4
fanhsu
  Fri Mar 18 10:01:18 2011 -0700
Move OMIM entry class filtering to omimLoadBed.
diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 64376a6..5e63848 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -11088,30 +11088,31 @@
 if (row != NULL)
 	{
 	answer = strdup(row[0]);
 	}
 else
 	{
 	answer = strdup("0");
 	}
 
 hFreeConn(&conn);
 sqlFreeResult(&sr);
 return(answer);
 }
 
 boolean doThisOmimEntry(struct track *tg, char *omimId)
+/* check if the specific class of this OMIM entry is selected by the user */
 {
 char *disorderClass = NULL; 
 boolean doIt;
 
 char labelName[255];
 boolean doClass1 = FALSE;
 boolean doClass2 = FALSE;
 boolean doClass3 = FALSE;
 boolean doClass4 = FALSE;
 boolean doOthers = FALSE;
 
 struct hashEl *omimLocationLabels;
 struct hashEl *label;
 
 safef(labelName, sizeof(labelName), "%s.label", tg->table);
@@ -11144,68 +11145,42 @@
 	}
     }
 
 disorderClass = getDisorderClass(omimId);
 
 doIt = FALSE;
 doIt = doIt || (doClass1 && sameWord(disorderClass, "1")) ;
 doIt = doIt || (doClass2 && sameWord(disorderClass, "2")) ;
 doIt = doIt || (doClass3 && sameWord(disorderClass, "3")) ;
 doIt = doIt || (doClass4 && sameWord(disorderClass, "4")) ;
 doIt = doIt || (doOthers && sameWord(disorderClass, "0")) ;
 
 return(doIt);
 }
 
-char *omimLocationName(struct track *tg, void *item)
-/* set name for omimLcation track */
-{
-struct bed *el = item;
-
-/* return empty string if this OMIM entry should not be presented */
-if (!doThisOmimEntry(tg, el->name)) 
-	return("");
-else
-	return(el->name);
-}
-
-char *omimGene2Name(struct track *tg, void *item)
-/* set name for omimGene2 track */
-{
-struct bed *el = item;
-
-/* return empty string if this OMIM entry should not be presented */
-if (!doThisOmimEntry(tg, el->name)) 
-	return("");
-else
-	return(el->name);
-}
-
 static void omimGene2DrawAt(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 *sPhenotypes;
 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;
 
-if (!doThisOmimEntry(tg, bed->name)) return;
-
 sPhenotypes = omimGene2DisorderList(tg, item);
 w = x2-x1;
 if (w < 1)
     w = 1;
 if (color)
     {
     hvGfxBox(hvg, x1, y, w, heightPer, color);
 
     if (vis == tvFull)
         {
         hvGfxTextRight(hvg, x1-mgFontStringWidth(font, sPhenotypes)-2, y,
 		    mgFontStringWidth(font, sPhenotypes),
                     heightPer, MG_BLACK, font, sPhenotypes);
         }
     if (vis != tvDense)
@@ -11224,30 +11199,56 @@
     int dir = 0;
     if (bed->strand[0] == '+')
 	dir = 1;
     else if(bed->strand[0] == '-')
 	dir = -1;
     if (dir != 0 && w > 2)
 	{
 	int midY = y + (heightPer>>1);
 	Color textColor = hvGfxContrastingColor(hvg, color);
 	clippedBarbs(hvg, x1, midY, w, tl.barbHeight, tl.barbSpacing,
 		dir, textColor, TRUE);
 	}
     }
 }
 
+void omimBedLoad(struct track *tg)
+/* Load the items in the gmimeGene2 or the omimLocation track */
+{
+struct bed *bed, *list = NULL;
+struct sqlConnection *conn = hAllocConn(database);
+struct sqlResult *sr;
+char **row;
+int rowOffset;
+
+sr = hRangeQuery(conn, tg->table, chromName, winStart, winEnd, NULL, &rowOffset);
+while ((row = sqlNextRow(sr)) != NULL)
+    {
+    bed = bedLoadN(row+rowOffset, 4);
+    
+    /* check if user has selected the specific class for this OMIM entry */
+    if (doThisOmimEntry(tg, bed->name)) 
+	{
+	slAddHead(&list, bed);
+	}
+    }
+sqlFreeResult(&sr);
+hFreeConn(&conn);
+slReverse(&list);
+tg->items = list;
+}
+
 Color omimGene2Color(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);
@@ -11291,33 +11292,33 @@
 	    else
 	    	{
 	    	// set to purplish color for phenClass 4
             	sqlFreeResult(&sr);
 	    	return hvGfxFindColorIx(hvg, 200, 100, 100);
             	}
 	    }
 
 	}  
     }
 }
 
 void omimGene2Methods (struct track *tg)
 {
 tg->itemColor 	  = omimGene2Color;
-tg->itemName      = omimGene2Name;
 tg->itemNameColor = omimGene2Color;
 tg->drawItemAt    = omimGene2DrawAt;
+tg->loadItems	  = omimBedLoad;
 }
 
 char omimAvSnpBuffer[OMIM_MAX_DESC_LEN];
 
 char *omimAvSnpAaReplacement(struct track *tg, struct bed *item)
 /* Return replacement string associated with a OMIM AV entry */
 {
 struct sqlConnection *conn;
 char query[256];
 struct sqlResult *sr;
 char **row;
 char *chp;
 
 omimAvSnpBuffer[0] = '\0';
 
@@ -11492,60 +11493,56 @@
     }
 }
 
 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;
 
-/* skip if the entry is not amount the class(es) selected */
-if (!doThisOmimEntry(tg, bed->name))
-    return;
-
 omimTitle = omimLocationDescription(tg, item);
 w = x2-x1;
 if (w < 1)
     w = 1;
 if (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->itemName      = omimLocationName;
 tg->itemColor     = omimLocationColor;
+tg->loadItems	  = omimBedLoad;
 }
 
 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;