6ecf4a7fdccf43addd6ca15bc2dedaa239852784
braney
  Tue May 9 16:09:07 2017 -0700
ongoing work on hgComposite.  Support add all visible button

diff --git src/hg/hgComposite/hgComposite.c src/hg/hgComposite/hgComposite.c
index 4c89acc..5e34817 100644
--- src/hg/hgComposite/hgComposite.c
+++ src/hg/hgComposite/hgComposite.c
@@ -1,18 +1,18 @@
-/* hgVai - Variant Annotation Integrator. */
+/* hgComposite --- build a composite */
 
-/* Copyright (C) 2014 The Regents of the University of California 
+/* Copyright (C) 2017 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "options.h"
 #include "jksql.h"
 #include "htmshell.h"
 #include "web.h"
 #include "cheapcgi.h"
 #include "cart.h"
 #include "cartTrackDb.h"
 #include "genbank.h"
 #include "hgConfig.h"
 #include "hgHgvs.h"
 #include "hui.h"
@@ -24,30 +24,31 @@
 #include "memalloc.h"
 #include "textOut.h"
 #include "trackHub.h"
 #include "hubConnect.h"
 #include "twoBit.h"
 #include "gpFx.h"
 #include "bigGenePred.h"
 #include "udc.h"
 #include "knetUdc.h"
 #include "cartTrackDb.h"
 #include "trashDir.h"
 #include "customComposite.h"
 
 #define hgCompEditPrefix    "hgCompositeEdit_"
 #define hgsAddTrack hgCompEditPrefix "addTrack"
+#define hgsAddVisTrack hgCompEditPrefix "addVisTrack"
 #define hgsChangeGroup hgCompEditPrefix "changeGroup"
 #define hgsCurrentGroup hgCompEditPrefix "currentGroup"
 #define hgsCurrentComposite hgCompEditPrefix "currentComposite"
 #define hgsNewCompositeName hgCompEditPrefix "newCompositeName"
 #define hgsNewCompositeShortLabel hgCompEditPrefix "newCompositeShortLabel"
 #define hgsNewCompositeLongLabel hgCompEditPrefix "newCompositeLongLabel"
 //#define hgCompositePrefix    "hgComposite_"
 #define hgDoNewComposite      hgCompEditPrefix    "doNewComposite"
 
 struct track
 {
 struct track *next;
 char *name;
 char *shortLabel;
 char *longLabel;
@@ -59,31 +60,31 @@
 char *name;
 char *shortLabel;
 char *longLabel;
 struct track *trackList;
 };
 
 
 /* Global Variables */
 struct cart *cart;		/* CGI and other variables */
 struct hash *oldVars = NULL;	/* The cart before new cgi stuff added. */
 char *genome = NULL;		/* Name of genome - mouse, human, etc. */
 char *database = NULL;		/* Current genome database - hg17, mm5, etc. */
 struct grp *fullGroupList = NULL;	/* List of all groups. */
 
 // Null terminated list of CGI Variables we don't want to save permanently:
-char *excludeVars[] = {"Submit", "submit", "hgva_startQuery", hgsAddTrack,  hgsNewCompositeName, hgsNewCompositeShortLabel, hgsNewCompositeLongLabel, hgsChangeGroup, NULL};
+char *excludeVars[] = {"Submit", "submit", "hgva_startQuery", hgsAddTrack,  hgsNewCompositeName, hgsNewCompositeShortLabel, hgsNewCompositeLongLabel, hgsChangeGroup, hgsAddVisTrack, NULL};
 
 void nbSpaces(int count)
 /* Print some non-breaking spaces. */
 {
 int i;
 for (i=0; i<count; ++i)
     printf("&nbsp;");
 }
 
 void addSomeCss()
 /*#*** This should go in a .css file of course. */
 {
 printf("<style>\n"
 	"div.sectionLite { border-width: 1px; border-color: #"HG_COL_BORDER"; border-style: solid;"
 	"  background-color: #FFFFFF; padding-left: 10px; padding-right: 10px; "
@@ -408,30 +409,35 @@
 cgiMakeHiddenVar(hgsCurrentGroup, "");
 hPrintf("</FORM>\n");
 
 hPrintf("<FORM ACTION='%s' NAME='changeCompositeForm'>", cgiScriptName());
 cartSaveSession(cart);
 cgiMakeHiddenVar(hgsCurrentComposite, "");
 hPrintf("</FORM>\n");
 
 hPrintf("<FORM ACTION='%s' NAME='makeNewCompositeForm'>", cgiScriptName());
 cartSaveSession(cart);
 cgiMakeHiddenVar(hgsNewCompositeName, "");
 cgiMakeHiddenVar(hgsNewCompositeShortLabel, "");
 cgiMakeHiddenVar(hgsNewCompositeLongLabel, "");
 hPrintf("</FORM>\n");
 
+hPrintf("<FORM ACTION='%s' NAME='addVisTrackForm'>", cgiScriptName());
+cartSaveSession(cart);
+cgiMakeHiddenVar(hgsAddVisTrack, "");
+hPrintf("</FORM>\n");
+
 hPrintf("<FORM ACTION='%s' NAME='addTrackForm'>", cgiScriptName());
 cartSaveSession(cart);
 cgiMakeHiddenVar(hgsAddTrack, "");
 hPrintf("</FORM>\n");
 
 /* Hidden form for jumping to custom tracks CGI. */
 hPrintf("<FORM ACTION='%s' NAME='customTrackForm'>", hgCustomName());
 cartSaveSession(cart);
 hPrintf("</FORM>\n");
 
 /* Hidden form for jumping to track hub manager CGI. */
 hPrintf("<FORM ACTION='%s' NAME='trackHubForm'>", hgHubConnectName());
 cartSaveSession(cart);
 hPrintf("</FORM>\n");
 
@@ -598,31 +604,31 @@
                     "change", 
                     "var e = document.getElementById('availTracks'); \
                     var strUser = e.options[e.selectedIndex].value; \
                     document.addTrackForm.elements['"hgsAddTrack"'].value = strUser;");
                     //document.addTrackForm.elements['hgComp_track'] = strUser;");
 hOnClickButton("addTrack", 
     "var e = document.getElementById('availTracks'); \
     var strUser = e.options[e.selectedIndex].value;  \
     document.addTrackForm.elements['"hgsAddTrack"'].value =  strUser;  \
     document.addTrackForm.submit();"
 , "add track");
 
 printf("<BR>");
 printf("<BR>");
 printf("<BR>");
-hOnClickButton("selVar_AddAllVis", "document.trackHubForm.submit(); return false;", "Add All Visibile Wiggles");
+hOnClickButton("selVar_AddAllVis", "document.addVisTrackForm.submit(); return false;", "Add All Visibile Wiggles");
 }
 
 void doMainPage(char *db, struct grp *groupList,  struct trackDb *fullTrackList, struct composite *currentComposite, struct composite *compositeList)
 /* Print out initial HTML of control page. */
 {
 //struct composite *currentComposite = compositeList;
 jsInit();
 webIncludeResourceFile("jquery-ui.css");
 webIncludeResourceFile("ui.dropdownchecklist.css");
 boolean alreadyAgreed = cartUsualBoolean(cart, "hgva_agreedToDisclaimer", FALSE);
 jsInlineF(
     "$(document).ready(function() { hgva.disclaimer.init(%s, hgva.userClickedAgree); });\n"
     , alreadyAgreed ? "true" : "false");
 addSomeCss();
 printAssemblySection();
@@ -654,31 +660,31 @@
 //selectVariants();
 //char *geneTrack = selectGenes();
 //if (geneTrack != NULL)
     {
     //selectRegulatory();
     //selectAnnotations(geneTrack);
     //selectFilters();
     //selectOutput();
     //submitAndDisclaimer();
     }
 
 printf("</FORM>");
 jsReloadOnBackButton(cart);
 
 webNewSection("Using the Composite Builder");
-webIncludeHelpFileSubst("hgCompositeHelpText", cart, FALSE);
+webIncludeHelpFileSubst("hgCompositeHelp", cart, FALSE);
 jsIncludeFile("jquery-ui.js", NULL);
 jsIncludeFile("hgVarAnnogrator.js", NULL);
 jsIncludeFile("ui.dropdownchecklist.js", NULL);
 jsIncludeFile("ddcl.js", NULL);
 }
 
 
 
 
 
 
 void doUi(char *db, struct grp *groupList, struct trackDb *fullTrackList,struct composite *currentComposite, struct composite *compositeList) 
 /* Set up globals and make web page */
 {
 cartWebStart(cart, db, "Composite Editor");
@@ -722,30 +728,50 @@
 char buffer[4096];
 
 for(;; count++)
     {
     safef(buffer, sizeof buffer, "%s%d", tdb->track, count);
     if (hashLookup(nameHash, buffer) == NULL)
         {
         hashAdd(nameHash, buffer, tdb);
         return cloneString(buffer);
         }
     }
 
 return NULL;
 }
 
+bool trackVisible(struct trackDb *tdb)
+{
+if ((tdb->parent != NULL) && !trackVisible(tdb->parent))
+    return FALSE;
+
+boolean vis = tdb->visibility != tvHide;
+char *cartVis = cartOptionalString(cart, tdb->track);
+
+if (cartVis != NULL) 
+    {
+    if (differentString(cartVis, "hide"))
+        vis = TRUE;
+    else
+        vis = FALSE;
+    }
+
+return vis;
+}
+
+
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 long enteredMainTime = clock1000();
 if (hIsPrivateHost())
     pushCarefulMemHandler(LIMIT_2or6GB);
 
 cgiSpoof(&argc, argv);
 htmlPushEarlyHandlers(); /* Make errors legible during initialization. */
 oldVars = hashNew(10);
 cart = cartAndCookie(hUserCookie(), excludeVars, oldVars);
 
 /* Set up global variables. */
 getDbAndGenome(cart, &database, &genome, oldVars);
 initGenbankTableNames(database);
@@ -811,40 +837,60 @@
             composite->shortLabel = composite->name;
         else
             composite->shortLabel = cloneString(newCompositeShortLabel);
         char *newCompositeLongLabel = cartOptionalString(cart, hgsNewCompositeLongLabel);
         if (isEmpty(newCompositeLongLabel))
             composite->longLabel = composite->name;
         else
             composite->longLabel = cloneString(newCompositeLongLabel);
 
         }
     }
 
 if (currentCompositeName == NULL)
     currentComposite = compositeList;
 
+char *addAllVisible = cartOptionalString(cart, hgsAddVisTrack);
+if (addAllVisible != NULL)
+    {
+    struct trackDb *tdb;
+
+    for(tdb = fullTrackList; tdb; tdb = tdb->next)
+        {
+        if (trackCanBeAdded(tdb) && trackVisible(tdb))
+            {
+            struct track *track;
+            AllocVar(track);
+            track->name = makeUnique(nameHash,  tdb);
+            track->shortLabel = tdb->shortLabel;
+            track->longLabel = tdb->longLabel;
+            slAddHead(&currentComposite->trackList, track);
+            }
+        }
+    }
+
 char *newTrackName = cartOptionalString(cart, hgsAddTrack);
 if (newTrackName != NULL)
     {
     if (currentComposite == NULL)
         warn("cannot add track without specifying a composite");
     else
         {
         struct trackDb *tdb = findTrack(newTrackName, wigTracks);
 
         struct track *track;
         AllocVar(track);
         track->name = makeUnique(nameHash,  tdb);
         track->shortLabel = tdb->shortLabel;
+        track->longLabel = tdb->longLabel;
         slAddHead(&currentComposite->trackList, track);
         }
     }
 
 //struct trackDb *fullTrackList = getFullTrackList(cart);
 doUi(database, groupList, wigTracks, currentComposite, compositeList);
 
 outputCompositeHub(database, hubName,  compositeList, nameHash);
 cartCheckout(&cart);
 cgiExitTime("hgComposite", enteredMainTime);
 return 0;
 }