6cd85926d8a333eb909f877365c4cabfdc4fbc8d
braney
  Fri Aug 23 17:13:49 2013 -0700
fix bug in #11441 where switching to an assembly with a non-existantgroup would cause an internal error.

diff --git src/hg/hgTables/hgTables.c src/hg/hgTables/hgTables.c
index 82ea9ef..3c8920f 100644
--- src/hg/hgTables/hgTables.c
+++ src/hg/hgTables/hgTables.c
@@ -867,32 +867,30 @@
 struct trackDb *track = NULL;
 
 if (name != NULL)
     {
     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();
 	}
     }
 return track;
 }
 
 struct grp *makeGroupList(struct trackDb *trackList, struct grp **pHubGrpList, boolean allTablesOk)
 /* Get list of groups that actually have something in them. */
 {
 struct grp *groupsAll, *groupList = NULL, *group;
 struct hash *groupsInTrackList = newHash(0);
 struct hash *groupsInDatabase = newHash(0);
 struct trackDb *track;
 
 /* Stream through track list building up hash of active groups. */
 for (track = trackList; track != NULL; track = track->next)
@@ -911,30 +909,33 @@
 	hashAdd(groupsInDatabase, group->name, group);
 	}
     else
         grpFree(&group);
     }
 
 /* if we have custom tracks, we want to add the track hubs
  * after that group */
 struct grp *addAfter = NULL;
 if ((groupList != NULL) && sameString(groupList->name, "user"))
     addAfter = groupList;
 
 /* Add in groups from hubs. */
 for (group = slPopHead(pHubGrpList); group != NULL; group = slPopHead(pHubGrpList))
     {
+    // if the group isn't represented in any track, don't add it to list
+    if (!hashLookup(groupsInTrackList,group->name))
+	continue;
     /* check to see if we're inserting hubs rather than
      * adding them to the front of the list */
     if (addAfter != NULL)
 	{
 	group->next = addAfter->next;
 	addAfter->next = group;
 	}
     else
 	slAddHead(&groupList, group);
     hashAdd(groupsInDatabase, group->name, group);
     }
 
 /* Do some error checking for tracks with group names that are
  * not in database.  Just warn about them. */
 if (!trackHubDatabase(database))
@@ -1925,31 +1926,36 @@
 return hash;
 }
 
 void initGroupsTracksTables()
 /* 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 grp *hubGrpList = NULL;
 fullTrackList = getFullTrackList( &hubGrpList);
 fullTrackHash = hashTrackList(fullTrackList);
 fullTableToTdbHash = hashNew(0);
 rAddTablesToHash(fullTrackList, fullTableToTdbHash);
 curTrack = findSelectedTrack(fullTrackList, NULL, hgtaTrack);
 fullGroupList = makeGroupList(fullTrackList, &hubGrpList, allowAllTables());
+
+// if there isn't a current track, then use the default group
+if (curTrack != NULL)
     curGroup = findSelectedGroup(fullGroupList, hgtaGroup);
+else
+    curGroup = fullGroupList;
 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;
     }
 }
 
 void hgTables()