src/hg/hgTracks/simpleTracks.c 1.80

1.80 2009/05/19 22:36:48 fanhsu
Added decipher tracks.
Index: src/hg/hgTracks/simpleTracks.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/simpleTracks.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -b -B -U 4 -r1.79 -r1.80
--- src/hg/hgTracks/simpleTracks.c	18 May 2009 21:17:41 -0000	1.79
+++ src/hg/hgTracks/simpleTracks.c	19 May 2009 22:36:48 -0000	1.80
@@ -4697,8 +4697,11 @@
 
 /* reserve space no more than 20 unique gad disease entries */
 char gadDiseaseClassBuffer[2000];
 
+/* reserve space no more than 20 unique decipher entries */
+char decipherBuffer[2000];
+
 char *gadDiseaseClassList(struct track *tg, struct bed *item)
 /* Return list of diseases associated with a GAD entry */
 {
 struct sqlConnection *conn;
@@ -4857,8 +4860,116 @@
 	}
     }
 }
 
+char *decipherPhenotypeList(struct track *tg, struct bed *item)
+/* Return list of diseases associated with a DECIPHER entry */
+{
+struct sqlConnection *conn;
+char query[256];
+struct sqlResult *sr;
+char **row;
+char *chp;
+int i=0;
+
+conn = hAllocConn(database);
+
+sprintf(query, 
+        "select distinct phenotype from decipherRaw where id='%s' order by phenotype", item->name);
+sr = sqlMustGetResult(conn, query);
+row = sqlNextRow(sr);
+
+/* show up to 20 max entries */
+chp = decipherBuffer;
+while ((row != NULL) && i<20)
+    {
+    if (i != 0)
+	{
+	sprintf(chp, "; ");
+	chp++;chp++;
+	}
+    sprintf(chp, "%s", row[0]);
+    chp = chp+strlen(row[0]);
+    row = sqlNextRow(sr);
+    i++;
+    }
+
+if ((i == 20) && (row != NULL))
+    {
+    sprintf(chp, " ...");
+    chp++;chp++;chp++;chp++;
+    }
+
+*chp = '\0';
+
+hFreeConn(&conn);
+sqlFreeResult(&sr);
+return(decipherBuffer);
+}
+
+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. */
+{
+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;
+
+sPhenotypes = decipherPhenotypeList(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 (tg->drawName && vis != tvSquish)
+	{
+	/* Clip here so that text will tend to be more visible... */
+	char *s = tg->itemName(tg, bed);
+	w = x2-x1;
+	if (w > mgFontStringWidth(font, s))
+	    {
+	    Color textColor = hvGfxContrastingColor(hvg, color);
+	    hvGfxTextCentered(hvg, x1, y, w, heightPer, textColor, font, s);
+	    }
+	}
+    mapBoxHc(hvg, bed->chromStart, bed->chromEnd, x1, y, x2 - x1, heightPer,
+	     tg->mapName, tg->mapItemName(tg, bed), sPhenotypes);
+    }
+if (tg->subType == lfWithBarbs)
+    {
+    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 decipherMethods(struct track *tg)
+/* Methods for DECIPHER track. */
+{
+tg->drawItemAt 	= decipherDrawAt;
+}
+
 void gadMethods(struct track *tg)
 /* Methods for GAD track. */
 {
 tg->drawItemAt 	= gadDrawAt;
@@ -10827,8 +10938,9 @@
 registerTrackHandler("h1n1b_0514Seq", h1n1SeqMethods);
 registerTrackHandler("hg17Kg", hg17KgMethods);
 registerTrackHandler("superfamily", superfamilyMethods);
 registerTrackHandler("gad", gadMethods);
+registerTrackHandler("decipher", decipherMethods);
 registerTrackHandler("rgdQtl", rgdQtlMethods);
 registerTrackHandler("rgdRatQtl", rgdQtlMethods);
 registerTrackHandler("refGene", refGeneMethods);
 registerTrackHandler("blastMm6", blastMethods);