68caf43f9cc2b29f3bd764cc1c0c82aa9c0183e4
kate
  Mon Mar 23 15:59:04 2015 -0700
GTEX track display: Add hgc to show tissue color table. Add debug statements for hgTracks. Also doc. This is version demoed at SAB. refs #13504

diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index c90bdf3..4eda2a7 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -39,30 +39,33 @@
 #include "agpFrag.h"
 #include "agpGap.h"
 #include "ctgPos.h"
 #include "contigAcc.h"
 #include "ctgPos2.h"
 #include "clonePos.h"
 #include "bactigPos.h"
 #include "rmskOut.h"
 #include "xenalign.h"
 #include "isochores.h"
 #include "simpleRepeat.h"
 #include "cpgIsland.h"
 #include "cpgIslandExt.h"
 #include "genePred.h"
 #include "genePredReader.h"
+#include "gtexGeneBed.h"
+#include "gtexTissue.h"
+#include "rainbow.h"
 #include "pepPred.h"
 #include "peptideAtlasPeptide.h"
 #include "wabAli.h"
 #include "genomicDups.h"
 #include "est3.h"
 #include "rnaGene.h"
 #include "tRNAs.h"
 #include "gbRNAs.h"
 #include "encode/encodeRna.h"
 #include "hgMaf.h"
 #include "maf.h"
 #include "stsMarker.h"
 #include "stsMap.h"
 #include "rhMapZfishInfo.h"
 #include "recombRate.h"
@@ -4241,31 +4244,30 @@
 if (dbIsFound)
     puts("Note: The \"Mask repeats\" option applies only to \"get DNA\", not to \"extended case/color options\". <P>");
 }
 
 boolean dnaIgnoreTrack(char *track)
 /* Return TRUE if this is one of the tracks too boring
  * to put DNA on. */
 {
 return (sameString("cytoBand", track) ||
 	sameString("gcPercent", track) ||
 	sameString("gold", track) ||
 	sameString("gap", track) ||
 	startsWith("mouseSyn", track));
 }
 
-
 struct customTrack *getCtList()
 /* initialize theCtList if necessary and return it */
 {
 if (theCtList == NULL)
     theCtList = customTracksParseCart(database, cart, NULL, NULL);
 return(theCtList);
 }
 
 struct trackDb *tdbForCustomTracks()
 /* Load custom tracks (if any) and translate to list of trackDbs */
 {
 struct customTrack *ctList = getCtList();
 struct customTrack *ct;
 struct trackDb *tdbList = NULL, *tdb;
 
@@ -24390,30 +24392,95 @@
 {
 char *table = cartString(cart, "table");
 struct trackDb *tdb = hashFindVal(trackHash, table);
 if (tdb == NULL)
     errAbort("no trackDb entry for %s", table);
 return tdb;
 }
 
 void doQPCRPrimers(struct trackDb *tdb, char *itemName)
 /* Put up page for QPCRPrimers. */
 {
 genericHeader(tdb, itemName);
 doBedDetail(tdb, NULL, itemName);
 } /* end of doQPCRPrimers */
 
+void doGtexGeneExpr(struct trackDb *tdb, char *item)
+/* Details of GTEX gene expression item */
+{
+// Load item from table */
+
+// TODO:  Get full details from Data table 
+struct dyString *dy = dyStringNew(0);
+//char sampleTable[128];
+//safef(sampleTable, sizeof(able), "%sSampleData", tdb->table);
+
+struct sqlConnection *conn = hAllocConn(database);
+char **row;
+int expCount = 0;
+if (sqlTableExists(conn, tdb->table))
+    {
+    char query[512];
+    sqlSafef(query, sizeof(query), "select * from %s where name = '%s'", tdb->table, item);
+    struct sqlResult *sr = sqlGetResult(conn, query);
+    row = sqlNextRow(sr);
+    if (row != NULL)
+        {
+        struct gtexGeneBed *gtexGene = gtexGeneBedLoad(row);
+        //printf("<b>Gene name</b> %s<br>\n", gtexGene->name);
+        //printf("<b>Ensembl gene</b> %s<br>\n", gtexGene->geneId);
+        //printf("<b>Ensembl transcript</b> %s<br>\n", gtexGene->transcriptId);
+        expCount = gtexGene->expCount;
+        }
+    sqlFreeResult(&sr);
+    }
+hFreeConn(&conn);
+
+// Print out tissue table with color assignments
+conn = hAllocConn("hgFixed");
+char *tissueTable = "gtexTissue";
+if (sqlTableExists(conn, tissueTable))
+    {
+    dyStringPrintf(dy, "<table>");
+    dyStringPrintf(dy, "<tr><td>Color</td><td>Tissue</td></tr>\n");
+    int i;
+    double invExpCount = 1.0/expCount;
+    char query[512];
+    sqlSafef(query, sizeof(query), "select * from %s", tissueTable);
+    struct sqlResult *sr = sqlGetResult(conn, query);
+    for (i=0; i<expCount; i++)
+        {
+        row = sqlNextRow(sr);
+        if (row == NULL)
+            break;
+        struct gtexTissue *tissue = gtexTissueLoad(row);
+        double colPos = invExpCount * i;
+        struct rgbColor color = saturatedRainbowAtPos(colPos);
+        dyStringPrintf(dy, "<tr><td bgcolor='#%02X%02X%02X'></td><td>%s</td></tr>\n",
+                    color.r, color.g, color.b, tissue->description);
+        }
+    sqlFreeResult(&sr);
+    }
+hFreeConn(&conn);
+dyStringPrintf(dy, "</table>");
+
+//cartWebStart(cart, database, "List of items assayed in %s", clusterTdb->shortLabel);
+
+genericClickHandlerPlus(tdb, item, item, dy->string);
+dyStringFree(&dy);
+}
+
 void doSnakeClick(struct trackDb *tdb, char *itemName)
 /* Put up page for snakes. */
 {
 genericHeader(tdb, itemName);
 char *otherSpecies = trackHubSkipHubName(tdb->table) + strlen("snake");
 char *hubName = cloneString(database);
 char *ptr = strchr(hubName + 4, '_');
 *ptr = 0;
 char otherDb[4096];
 char *qName = cartOptionalString(cart, "qName");
 int qs = atoi(cartOptionalString(cart, "qs"));
 int qe = atoi(cartOptionalString(cart, "qe"));
 int qWidth = atoi(cartOptionalString(cart, "qWidth"));
 safef(otherDb, sizeof otherDb, "%s_%s", hubName, otherSpecies);
 
@@ -25709,30 +25776,34 @@
     {
     doLrg(tdb, item);
     }
 else if (sameString("lrgTranscriptAli", table))
     {
     doLrgTranscriptPsl(tdb, item);
     }
 else if (sameWord(table, "htcLrgCdna"))
     {
     htcLrgCdna(item);
     }
 else if (startsWith("peptideAtlas", table))
     {
     doPeptideAtlas(tdb, item);
     }
+else if (startsWith("gtexGene", table))
+    {
+    doGtexGeneExpr(tdb, item);
+    }
 else if (isHubTrack(table) && startsWith("snake", trackHubSkipHubName(table)))
     {
     doSnakeClick(tdb, item);
     }
 #ifdef USE_TABIX
 else if (tdb != NULL && startsWithWord("vcfTabix", tdb->type))
     {
     doVcfTabixDetails(tdb, item);
     }
 #endif // USE_TABIX
 else if (tdb != NULL && startsWithWord("vcf", tdb->type))
     {
     doVcfDetails(tdb, item);
     }
 else if (tdb != NULL)
@@ -25768,15 +25839,17 @@
 doMiddle();
 }
 
 char *excludeVars[] = {"Submit", "submit", "g", "i", "aliTable", "addp", "pred", NULL};
 
 int main(int argc, char *argv[])
 {
 long enteredMainTime = clock1000();
 pushCarefulMemHandler(LIMIT_2or6GB);
 cgiSpoof(&argc,argv);
 setUdcCacheDir();
 cartEmptyShell(cartDoMiddle, hUserCookie(), excludeVars, NULL);
 cgiExitTime("hgc", enteredMainTime);
 return 0;
 }
+
+