bd5ab545fd2f8439916541d8ba0bd74f7d16e504
kent
  Tue Mar 20 15:33:58 2012 -0700
Replacing a hash that gives a tdb for a track name with one that gives tdb for a table name. Addresses redmine 7222.
diff --git src/hg/hgTables/hgTables.c src/hg/hgTables/hgTables.c
index 648ccd1..77cacce 100644
--- src/hg/hgTables/hgTables.c
+++ src/hg/hgTables/hgTables.c
@@ -45,31 +45,34 @@
   "options:\n"
   "   -xxx=XXX\n"
   );
 }
 
 /* Global variables. */
 struct cart *cart;	/* This holds cgi and other variables between clicks. */
 struct hash *oldVars;	/* The cart before new cgi stuff added. */
 char *genome;		/* Name of genome - mouse, human, etc. */
 char *database;		/* Current genome database - hg17, mm5, etc. */
 char *freezeName;	/* Date of assembly. */
 struct grp *fullGroupList;	/* List of all groups. */
 struct grp *curGroup;	/* Currently selected group. */
 struct trackDb *fullTrackList;	/* List of all tracks in database. */
 struct hash *fullTrackHash;     /* Hash of all tracks in fullTrackList keyed by ->track field. */
-struct hash *fullTrackAndSubtrackHash;  /* All tracks and subtracks keyed by track field. */
+#ifdef UNUSED
+struct hash *fullTrackAndSubtrackHash;  /* All tracks and subtracks keyed by tdb->track field. */
+#endif /* UNUSED */
+struct hash *fullTableToTdbHash;        /* All tracks and subtracks keyed by tdb->table field. */
 struct trackDb *forbiddenTrackList; /* List of tracks with 'tableBrowser off' setting. */
 struct trackDb *curTrack;	/* Currently selected track. */
 char *curTable;		/* Currently selected table. */
 struct joiner *allJoiner;	/* Info on how to join tables. */
 
 static struct pipeline *compressPipeline = (struct pipeline *)NULL;
 
 boolean allowAllTables(void)
 /* determine if all tables should is allowed by configuration */
 {
 return !cfgOptionBooleanDefault("hgta.disableAllTables", FALSE);
 }
 
 /* --------------- HTML Helpers ----------------- */
 
@@ -291,31 +294,31 @@
 	    trackDbPrioritizeContainerItems(tdbList);
 	    if (tdbList != NULL)
 		{
 		list = slCat(list, tdbList);
 		struct grp *grp = grpFromHub(hubStatus);
 		slAddHead(pHubGroups, grp);
 		}
 	    }
 	
 	// clear this so it isn't free'd later
 	hubStatus->trackHub = NULL;
 	}
     }
 slReverse(pHubGroups);
 
-/* Create dummy group for custom tracks if any */
+/* Create dummy group for custom tracks if any. Add custom tracks to list */
 ctList = getCustomTracks();
 for (ct = ctList; ct != NULL; ct = ct->next)
     {
     slAddHead(&list, ct->tdb);
     }
 
 return list;
 }
 
 boolean fullGenomeRegion()
 /* Return TRUE if region is full genome. */
 {
 char *regionType = cartUsualString(cart, hgtaRegionType, "genome");
 return sameString(regionType, "genome");
 }
@@ -612,31 +615,31 @@
     AllocVar(hti);
     hti->rootName = cloneString(tdb->track);
     hti->isPos = TRUE;
     hti->type = cloneString(tdb->type);
     }
 return hti;
 }
 
 struct hTableInfo *maybeGetHti(char *db, char *table, struct sqlConnection *conn)
 /* Return primary table info, but don't abort if table not there. Conn should be open to db. */
 {
 struct hTableInfo *hti = NULL;
 
 if (isHubTrack(table))
     {
-    struct trackDb *tdb = hashMustFindVal(fullTrackAndSubtrackHash, table);
+    struct trackDb *tdb = hashMustFindVal(fullTableToTdbHash, table);
     hti = hubTrackTableInfo(tdb);
     }
 else if (isBigBed(database, table, curTrack, ctLookupName))
     hti = bigBedToHti(table, conn);
 else if (isBamTable(table))
     hti = bamToHti(table);
 else if (isVcfTable(table))
     hti = vcfToHti(table);
 else if (isCustomTrack(table))
     {
     struct customTrack *ct = ctLookupName(table);
     hti = ctToHti(ct);
     }
 else if (sameWord(table, WIKI_TRACK_TABLE))
     {
@@ -837,33 +840,30 @@
 	errAbort("Track %s doesn't exist in database %s.", name, database);
     }
 return track;
 }
 
 struct trackDb *findSelectedTrack(struct trackDb *trackList,
 	struct grp *group, char *varName)
 /* Find selected track - from CGI variable if possible, else
  * via various defaults. */
 {
 char *name = cartOptionalString(cart, varName);
 struct trackDb *track = NULL;
 
 if (name != NULL)
     {
-    /* getFullTrackList tweaks tdb->table mrna to all_mrna, so in
-     * case mrna is passed in (e.g. from hgc link to schema page)
-     * tweak it here too: */
     track = findTrackInGroup(name, trackList, group);
     }
 if (track == NULL)
     {
     if (group == NULL || sameString(group->name, "all"))
         track = trackList;
     else
 	{
 	for (track = trackList; track != NULL; track = track->next)
 	    if (sameString(track->grp, group->name))
 	         break;
 	if (track == NULL)
 	    internalErr();
 	}
     }
@@ -1864,63 +1864,65 @@
 else if (cartVarExists(cart, hgtaDoSubmitUserRegions))
     doSubmitUserRegions(conn);
 else if (cartVarExists(cart, hgtaDoClearSetUserRegionsText))
     doClearSetUserRegionsText(conn);
 else if (cartVarExists(cart, hgtaDoClearUserRegions))
     doClearUserRegions(conn);
 else if (cartVarExists(cart, hgtaDoMetaData))
     doMetaData(conn);
 else	/* Default - put up initial page. */
     doMainPage(conn);
 cartRemovePrefix(cart, hgtaDo);
 }
 
 char *excludeVars[] = {"Submit", "submit", NULL};
 
-static void rAddTracksToHash(struct trackDb *tdbList, struct hash *hash)
-/* Add tracks in list to hash */
+static void rAddTablesToHash(struct trackDb *tdbList, struct hash *hash)
+/* Add tracks in list to hash, keyed by tdb->table*/
 {
 struct trackDb *tdb;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
-    hashAdd(hash, tdb->track, tdb);
+    hashAdd(hash, tdb->table, tdb);
     if (tdb->subtracks)
-        rAddTracksToHash(tdb->subtracks, hash);
+        rAddTablesToHash(tdb->subtracks, hash);
     }
 }
 
 static struct hash *hashTrackList(struct trackDb *tdbList)
 /* Return hash full of trackDb's from list, keyed by tdb->track */
 {
 struct hash *hash = hashNew(0);
 struct trackDb *tdb;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
     {
     hashAdd(hash, tdb->track, tdb);
     }
 return hash;
 }
 
 void initGroupsTracksTables()
-/* Get list of groups that actually have something in them. */
+/* Get list of groups that actually have something in them, prepare hashes
+ * containing all tracks and all tables. Set global variables that correspond
+ * to the group, track, and table specified in the cart. */
 {
 struct hubConnectStatus *hubList = hubConnectStatusListFromCart(cart);
 struct grp *hubGrpList = NULL;
 fullTrackList = getFullTrackList(hubList, &hubGrpList);
 fullTrackHash = hashTrackList(fullTrackList);
-fullTrackAndSubtrackHash = hashNew(0);
-rAddTracksToHash(fullTrackList, fullTrackAndSubtrackHash);
+fullTableToTdbHash = hashNew(0);
+rAddTablesToHash(fullTrackList, fullTableToTdbHash);
 curTrack = findSelectedTrack(fullTrackList, NULL, hgtaTrack);
 fullGroupList = makeGroupList(fullTrackList, &hubGrpList, allowAllTables());
 curGroup = findSelectedGroup(fullGroupList, hgtaGroup);
 if (sameString(curGroup->name, "allTables"))
     curTrack = NULL;
 curTable    = findSelectedTable(curTrack, hgtaTable);
 if (curTrack == NULL)
     {
     struct trackDb *tdb  = hTrackDbForTrack(database, curTable);
     struct trackDb *cTdb = hCompositeTrackDbForSubtrack(database, tdb);
     if (cTdb)
         curTrack = cTdb;
     else
         curTrack = tdb;
     }