be3dc2f7f8a22768c79f2ec27dbea7fc78a2bd95
braney
  Thu Oct 6 14:14:13 2016 -0700
first pass at supporting tagStorm in track hubs.

diff --git src/hg/lib/hui.c src/hg/lib/hui.c
index 0128593..3cb1819 100644
--- src/hg/lib/hui.c
+++ src/hg/lib/hui.c
@@ -34,30 +34,31 @@
 #include "regexHelper.h"
 #include "snakeUi.h"
 #include "vcfUi.h"
 #include "vcf.h"
 #include "errCatch.h"
 #include "samAlignment.h"
 #include "makeItemsItem.h"
 #include "bedDetail.h"
 #include "pgSnp.h"
 #include "memgfx.h"
 #include "trackHub.h"
 #include "gtexUi.h"
 #include "genbank.h"
 #include "htmlPage.h"
 #include "longRange.h"
+#include "tagStorm.h"
 
 #define SMALLBUF 256
 #define MAX_SUBGROUP 9
 #define ADD_BUTTON_LABEL        "add"
 #define CLEAR_BUTTON_LABEL      "clear"
 #define JBUFSIZE 2048
 
 #define PM_BUTTON  "<IMG height=18 width=18 onclick=\"setCheckBoxesThatContain(" \
                    "'%s',%s,true,'%s','','%s');\" id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\">\n"
 #define DEF_BUTTON "<IMG onclick=\"setCheckBoxesThatContain('%s',true,false,'%s','','%s'); " \
                    "setCheckBoxesThatContain('%s',false,false,'%s','_defOff','%s');\" " \
                    "id=\"btn_%s\" src=\"../images/%s\" alt=\"%s\">\n"
 #define DEFAULT_BUTTON(nameOrId,anc,beg,contains) \
         printf(DEF_BUTTON,(nameOrId),(beg),(contains),(nameOrId),(beg),(contains),(anc), \
               "defaults_sm.png","default")
@@ -172,33 +173,77 @@
     {
     char *encFile = cgiEncode(file);
     dyLink = dyStringCreate(VOCAB_LINK_WITH_FILE,encFile,encTerm,encValue,title,label);
     freeMem(encFile);
     }
 else
     dyLink = dyStringCreate(VOCAB_LINK,encTerm,encValue,title,label);
 if (suffix != NULL)
     dyStringAppend(dyLink,suffix);  // Don't encode since this may contain HTML
 
 freeMem(encTerm);
 freeMem(encValue);
 return dyStringCannibalize(&dyLink);
 }
 
+// static global that maps tagStorm file names to hashes on the "track" value
+static struct hash *tagStanzaHash;
+
+char *tagStormAsHtmlTable(char *tagStormFile, struct trackDb *tdb,boolean showLongLabel,boolean showShortLabel)
+/* Return a string which is an HTML table of the tags for this track. */
+{
+if (tagStanzaHash == NULL)
+    tagStanzaHash = newHash(5);
+struct hash *stanzaHash = hashFindVal(tagStanzaHash, tagStormFile);
+if (stanzaHash == NULL)
+    {
+    struct tagStorm *tags = tagStormFromFile(tagStormFile);
+    stanzaHash = tagStormUniqueIndex(tags, "track");
+    hashAdd(tagStanzaHash, tagStormFile, stanzaHash);
+    }
+
+struct tagStanza *stanza = hashFindVal(stanzaHash, trackHubSkipHubName(tdb->track));
+if (stanza == NULL)
+    return "";
+
+struct slPair *pairs = tagListIncludingParents(stanza);
+struct dyString *dyTable = dyStringCreate("<table style='display:inline-table;'>");
+
+if (showLongLabel)
+    dyStringPrintf(dyTable,"<tr valign='bottom'><td colspan=2 nowrap>%s</td></tr>",tdb->longLabel);
+if (showShortLabel)
+    dyStringPrintf(dyTable,"<tr valign='bottom'><td align='right' nowrap><i>shortLabel:</i></td>"
+                           "<td nowrap>%s</td></tr>",tdb->shortLabel);
+
+for(; pairs; pairs = pairs->next)
+    {
+    if (!isEmpty((char *)pairs->val))
+        dyStringPrintf(dyTable,"<tr valign='bottom'><td align='right' nowrap><i>%s:</i></td>"
+                           "<td nowrap>%s</td></tr>",pairs->name, (char *)pairs->val);
+    }
+dyStringAppend(dyTable,"</table>");
+return dyStringCannibalize(&dyTable);
+}
+
 char *metadataAsHtmlTable(char *db,struct trackDb *tdb,boolean showLongLabel,boolean showShortLabel)
 // If metadata from metaDb exists, return string of html with table definition
 {
+char *tagStormFile = trackDbSetting(tdb, "tagStorm");
+
+if (tagStormFile)
+    return tagStormAsHtmlTable(tagStormFile, tdb, showLongLabel, showShortLabel);
+
 const struct mdbObj *safeObj = metadataForTable(db,tdb,NULL);
 if (safeObj == NULL || safeObj->vars == NULL)
     return NULL;
 
 //struct dyString *dyTable = dyStringCreate("<table id='mdb_%s'>",tdb->table);
 struct dyString *dyTable = dyStringCreate("<table style='display:inline-table;'>");
 if (showLongLabel)
     dyStringPrintf(dyTable,"<tr valign='bottom'><td colspan=2 nowrap>%s</td></tr>",tdb->longLabel);
 if (showShortLabel)
     dyStringPrintf(dyTable,"<tr valign='bottom'><td align='right' nowrap><i>shortLabel:</i></td>"
                            "<td nowrap>%s</td></tr>",tdb->shortLabel);
 
 // Get the hash of mdb and cv term types
 struct hash *cvTermTypes = (struct hash *)cvTermTypeHash();