4e91fbccad6b04384ba5792bce44f933b5a1c1ff
tdreszer
  Tue Oct 4 11:56:27 2011 -0700
Further fixes to the cfgByType consistency logic, prompted by side by side comparisons on hg18 tracks.
diff --git src/hg/hgTrackUi/hgTrackUi.c src/hg/hgTrackUi/hgTrackUi.c
index 3916174..b860670 100644
--- src/hg/hgTrackUi/hgTrackUi.c
+++ src/hg/hgTrackUi/hgTrackUi.c
@@ -1699,63 +1699,30 @@
 radioButton(logicTypeVar, logicTypeVal, "and");
 radioButton(logicTypeVar, logicTypeVal, "or");
 printf("<BR>\n");
 
 /* List various fields you can filter on. */
 printf("<table border=0 cellspacing=1 cellpadding=1 width=%d>\n", CONTROL_TABLE_WIDTH);
 cg = startControlGrid(4, NULL);
 for (fil = mud->filterList; fil != NULL; fil = fil->next)
     oneMrnaFilterUi(cg, fil->label, fil->key, cart);
 endControlGrid(&cg);
 baseColorDrawOptDropDown(cart, tdb);
 indelShowOptions(cart, tdb);
 }
 
 
-
-static void filterByChrom(struct trackDb *tdb)
-{
-char *filterSetting;
-char filterVar[256];
-char *filterVal = "";
-
-printf("<p><b>Filter by chromosome (e.g. chr10):</b> ");
-snprintf(filterVar, sizeof(filterVar), "%s.chromFilter", tdb->track);
-filterSetting = cartUsualString(cart, filterVar, filterVal);
-cgiMakeTextVar(filterVar, cartUsualString(cart, filterVar, ""), 15);
-}
-
-void crossSpeciesUi(struct trackDb *tdb)
-/* Put up UI for selecting rainbow chromosome color or intensity score. */
-{
-char colorVar[256];
-char *colorSetting;
-/* initial value of chromosome coloring option is "on", unless
- * overridden by the colorChromDefault setting in the track */
-char *colorDefault = trackDbSettingOrDefault(tdb, "colorChromDefault", "on");
-
-printf("<p><b>Color track based on chromosome:</b> ");
-snprintf(colorVar, sizeof(colorVar), "%s.color", tdb->track);
-colorSetting = cartUsualString(cart, colorVar, colorDefault);
-cgiMakeRadioButton(colorVar, "on", sameString(colorSetting, "on"));
-printf(" on ");
-cgiMakeRadioButton(colorVar, "off", sameString(colorSetting, "off"));
-printf(" off ");
-printf("<br><br>");
-filterByChrom(tdb);
-}
-
 void transRegCodeUi(struct trackDb *tdb)
 /* Put up UI for transcriptional regulatory code - not
  * much more than score UI. */
 {
 printf("%s",
 	"<P>The scoring ranges from 0 to 1000 and is based on the number of lines "
 	"of evidence that support the motif being active.  Each of the two "
 	"<I>sensu stricto</I> species in which the motif was conserved counts "
 	"as a line of evidence.  If the ChIP-chip data showed good (P &le; 0.001) "
 	"evidence of binding to the transcription factor associated with the "
 	"motif, that counts as two lines of evidence.  If the ChIP-chip data "
 	"showed weaker (P &le; 0.005) evidence of binding, that counts as just one line "
 	"of evidence.  The following table shows the relationship between lines "
 	"of evidence and score:");
 printf("<P>");
@@ -1847,31 +1814,31 @@
     }
 
 }
 
 void chainColorUi(struct trackDb *tdb)
 /* UI for the chain tracks */
 {
 boolean normScoreAvailable = chainDbNormScoreAvailable(tdb);
 boolean compositeTrack = tdbIsComposite(tdb);
 
 if (compositeTrack)
     return;	// configuration taken care of by hCompositeUi() later
 else if (normScoreAvailable)
     chainCfgUi(database, cart, tdb, tdb->track, NULL, FALSE, chromosome);
 else
-    crossSpeciesUi(tdb);
+    crossSpeciesCfgUi(cart,tdb);
 }
 
 void chromGraphUi(struct trackDb *tdb)
 /* UI for the wiggle track */
 {
 char varName[chromGraphVarNameMaxSize];
 struct sqlConnection *conn = NULL;
 char *track = tdb->track;
 if (!isCustomTrack(track))
     conn = hAllocConn(database);
 double minVal,maxVal;
 struct chromGraphSettings *cgs = chromGraphSettingsGet(track,
 	conn, tdb, cart);
 
 printf("<b>Track height:&nbsp;</b>");
@@ -2355,30 +2322,39 @@
 	  "&list_uids=%s&dopt=Abstract&tool=genome.ucsc.edu\" TARGET=_BLANK>%s</A>", pmId, ref);
     labelArr[refCount] = cloneString(label);
     valueArr[refCount++] = cloneString(pmId);
     if (! filterPmIdInCart)
 	slNameAddHead(&checked, pmId);
     if (refCount >= MAX_DGV_REFS)
 	errAbort("dgvUi: %s has too many references (max %d)", tdb->track, MAX_DGV_REFS);
     }
 sqlFreeResult(&sr);
 jsMakeCheckboxGroupSetClearButton(cartVarName, TRUE);
 jsMakeCheckboxGroupSetClearButton(cartVarName, FALSE);
 cgiMakeCheckboxGroupWithVals(cartVarName, labelArr, valueArr, refCount, checked, 4);
 hFreeConn(&conn);
 }
 
+static void factorSourceUi(char *db,struct trackDb *tdb)
+{
+printf("<BR><B>Cell Abbreviations:</B><BR>\n");
+char *sourceTable = trackDbRequiredSetting(tdb, "sourceTable");
+struct sqlConnection *conn = hAllocConn(db);
+hPrintAbbreviationTable(conn, sourceTable, "Cell Type");
+hFreeConn(&conn);
+}
+
 #ifdef UNUSED
 static boolean isInTrackList(struct trackDb *tdbList, struct trackDb *target)
 /* Return TRUE if target is in tdbList. */
 {
 struct trackDb *tdb;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     if (tdb == target)
         return TRUE;
 return FALSE;
 }
 #endif /* UNUSED */
 
 void superTrackUi(struct trackDb *superTdb, struct trackDb *tdbList)
 /* List tracks in this collection, with visibility controls and UI links */
 {
@@ -2435,31 +2411,38 @@
         // TODO: use hTrackUiName()
         printf("<p><b>NOTE</b>: Early access to additional track data may be available on the <a target=_blank href='http://%s/cgi-bin/hgTrackUi?db=%s&g=%s'>Preview Browser</A>.",
             "genome-preview.ucsc.edu", db, tdb->track);
         }
     }
 }
 
 void specificUi(struct trackDb *tdb, struct trackDb *tdbList, struct customTrack *ct, boolean ajax)
 /* Draw track specific parts of UI. */
 {
 char *track = tdb->track;
 // Ideally check cfgTypeFromTdb()/cfgByCfgType() first, but with all these special cases already in
 //    place, lets be cautious at this time.
 // NOTE: Developer, please try to use cfgTypeFromTdb()/cfgByCfgType().
 
-if (sameString(track, "stsMap"))
+// UI precedence:
+// 1) supers to get them out of the way: they have no controls
+// 2) special cases based upon track name (developer please avoid)
+// 3) cfgTypeFromTdb()/cfgByCfgType() <== prefered method
+// 4) special cases falling through the cracks but based upon type
+if (tdbIsSuperTrack(tdb))
+    superTrackUi(tdb, tdbList);
+else if (sameString(track, "stsMap"))
     stsMapUi(tdb);
 else if (sameString(track, "affyTxnPhase2"))
     affyTxnPhase2Ui(tdb);
 else if (sameString(track, "cgapSage"))
     cgapSageUi(tdb);
 else if (sameString(track, "stsMapMouseNew"))
     stsMapMouseUi(tdb);
 else if (sameString(track, "stsMapRat"))
     stsMapRatUi(tdb);
 else if (sameString(track, "snpMap"))
     snpMapUi(tdb);
 else if (sameString(track, "snp"))
     snpUi(tdb);
 else if (snpVersion(track) >= 125)
     snp125Ui(tdb);
@@ -2518,138 +2501,111 @@
     rosettaUi(tdb);
 else if (startsWith("blastDm", track))
     blastFBUi(tdb);
 else if (sameString(track, "blastSacCer1SG"))
     blastSGUi(tdb);
 else if (sameString(track, "blastHg17KG")
      ||  sameString(track, "blastHg16KG")
      ||  sameString(track, "blastCe3WB")
      ||  sameString(track, "blastHg18KG")
      ||  sameString(track, "blatzHg17KG")
      ||  startsWith("mrnaMap", track)
      ||  startsWith("mrnaXeno", track))
     blastUi(tdb);
 else if (sameString(track, "hgPcrResult"))
     pcrResultUi(tdb);
-else if (startsWith("chromGraph", tdb->type))
-    chromGraphUi(tdb);
 else if (sameString(track, "ancientR"))
     ancientRUi(tdb);
 else if (sameString(track, "zoo") || sameString(track, "zooNew" ))
     zooWiggleUi(tdb);
 else if (sameString(track, "humMusL")
      ||  sameString( track, "musHumL")
      ||  sameString( track, "regpotent")
      ||  sameString( track, "mm3Rn2L" )
      ||  sameString( track, "mm3Hg15L" )
      ||  sameString( track, "hg15Mm3L" ))
     humMusUi(tdb,7);
 else if (startsWith("chain", track)
      || endsWith("chainSelf", track))
     chainColorUi(tdb);
 else if (sameString(track, "orthoTop4") // still used ??
      ||  sameString(track, "mouseOrtho")
      ||  sameString(track, "mouseSyn"))
-    // NOTE: type psl xeno <otherDb> tracks use crossSpeciesUi, so
+    // NOTE: type psl xeno <otherDb> tracks use crossSpeciesCfgUi, so
     // add explicitly here only if track has another type (bed, chain).
-    // For crossSpeciesUi, the
+    // For crossSpeciesCfgUi, the
     // default for chrom coloring is "on", unless track setting
     // colorChromDefault is set to "off"
-    crossSpeciesUi(tdb);
+    crossSpeciesCfgUi(cart,tdb);
 else if (sameString(track, "affyTranscriptome"))
     affyTranscriptomeUi(tdb);
-else if (startsWith("sample", tdb->type))
-    genericWiggleUi(tdb,7);
 else if (sameString(track, WIKI_TRACK_TABLE))
     wikiTrackUi(tdb);
 else if (sameString(track, RULER_TRACK_NAME))
     rulerUi(tdb);
 else if (sameString(track, OLIGO_MATCH_TRACK_NAME))
     oligoMatchUi(tdb);
 else if (sameString(track, CUTTERS_TRACK_NAME))
     cutterUi(tdb);
 else if(sameString(track, "affyTransfrags"))
     affyTransfragUi(tdb);
 else if (sameString(track, "gvPos"))
     gvUi(tdb);
 else if (sameString(track, "oreganno"))
     oregannoUi(tdb);
 else if (startsWith("retroposons", track))
     retroposonsUi(tdb);
 else if (sameString(track, "tfbsConsSites"))
     tfbsConsSitesUi(tdb);
 else if (sameString(track, "CGHBreastCancerUCSF"))
     ucsfdemoUi(tdb);
 else if (startsWith("hapmapSnps", track))
     hapmapSnpsUi(tdb);
 else if (sameString(track, "switchDbTss"))
     switchDbScoreUi(tdb);
 else if (sameString(track, "dgv")
      || (startsWith("dgvV", track) && isdigit(track[4])))
     dgvUi(tdb);
-else
+else if (tdb->type != NULL)
     {   // NOTE for developers: please avoid special cases and use cfgTypeFromTdb//cfgByCfgType()
         //  When you do, then multi-view cfg and subtrack cfg will work.
     eCfgType cType = cfgTypeFromTdb(tdb,FALSE);
     if (cType != cfgNone)
         {
         boolean boxed = trackDbSettingClosestToHomeOn(tdb, "boxedCfg");
         cfgByCfgType(cType,database, cart, tdb,tdb->track, NULL, boxed);
         }
-    else if (tdb->type != NULL)
-        {
-        /* handle all tracks with type genePred or bed or "psl xeno <otherDb>" */
-        char *typeLine = cloneString(tdb->type);
-        char *words[8];
-        int wordCount = 0;
-        wordCount = chopLine(typeLine, words);
-        if (wordCount > 0)
-            {
-            if (sameWord(words[0], "expRatio"))
+    // NOTE: these cases that fall through the cracks should probably get folded into cfgByCfgType()
+    else if (startsWithWord("expRatio", tdb->type))
                 expRatioUi(tdb);
-            else if (sameWord(words[0], "array")) /* not quite the same as an "expRatio" type (custom tracks) */
+    else if (startsWith("chromGraph", tdb->type))
+        chromGraphUi(tdb);
+    else if (startsWith("sample", tdb->type))
+        genericWiggleUi(tdb,7);
+    else if (startsWithWord("array",tdb->type)) /* not quite the same as an "expRatio" type (custom tracks) */
                 expRatioCtUi(tdb);
-            else if (sameWord(words[0], "psl"))
-                {
-                if (wordCount == 3)
-                if (sameWord(words[1], "xeno"))
-                    crossSpeciesUi(tdb);
-                baseColorDrawOptDropDown(cart, tdb);
-                indelShowOptions(cart, tdb);
-                }
-            else if (sameWord(words[0], "factorSource"))
-                {
-                printf("<BR><B>Cell Abbreviations:</B><BR>\n");
-                char *sourceTable = trackDbRequiredSetting(tdb, "sourceTable");
-                struct sqlConnection *conn = hAllocConn(database);
-                hPrintAbbreviationTable(conn, sourceTable, "Cell Type");
-                hFreeConn(&conn);
-                }
-            }
-            freeMem(typeLine);
-        }
-    }
-if (tdbIsSuperTrack(tdb))
-    {
-    superTrackUi(tdb, tdbList);
+    else if (startsWithWord("factorSource",tdb->type))
+        factorSourceUi(database,tdb);
     }
-else if (tdbIsComposite(tdb))  // for the moment generalizing this to include other containers...
+
+if (!ajax) // ajax asks for a simple cfg dialog for right-click popup or hgTrackUi subtrack cfg
     {
+    // Composites *might* have had their top level controls just printed, but almost certainly have additional controls
+    if (tdbIsComposite(tdb))  // for the moment generalizing this to include other containers...
     hCompositeUi(database, cart, tdb, NULL, NULL, MAIN_FORM, trackHash);
-    }
-if (!ajax)
-    {
+
+    // Additional special case navigation links may be added
     previewLinks(database, tdb);
     extraUiLinks(database,tdb, trackHash);
     }
 }
 
 #ifdef UNUSED
 static void findSuperChildrenAndSettings(struct trackDb *tdbList, struct trackDb *super)
 /* Find the tracks that have super as a parent and stuff references to them on
  * super's children list. Also do some visibility and parentName futzing. */
 {
 struct trackDb *tdb;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
     if (tdb->parent == super)
         {