Index: src/hg/hgTrackUi/hgTrackUi.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTrackUi/hgTrackUi.c,v
retrieving revision 1.510
retrieving revision 1.511
diff -b -B -U 4 -r1.510 -r1.511
--- src/hg/hgTrackUi/hgTrackUi.c	11 Dec 2009 15:14:44 -0000	1.510
+++ src/hg/hgTrackUi/hgTrackUi.c	4 Jan 2010 19:12:24 -0000	1.511
@@ -539,21 +539,24 @@
 printf("&nbsp;Trim to triangle<BR>\n");
 
 if (tdbIsComposite(tdb))
     {
-    struct trackDb *subTdb;
     printf("<BR>&nbsp;&nbsp;&nbsp;");
-    slSort(&(tdb->subtracks), trackDbCmp);
-    for (subTdb = tdb->subtracks;  subTdb != NULL;  subTdb = subTdb->next)
+    struct slRef *tdbRefList = trackDbListGetRefsToDescendantLeaves(tdb->subtracks);
+    slSort(tdbRefList, trackDbRefCmp);
+    struct slRef *tdbRef;
+    for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next)
 	{
+	struct trackDb *subTdb = tdbRef->val;
 	if (hTableExists(database, subTdb->tableName))
 	    {
 	    safef(var, sizeof(var), "%s_inv", subTdb->tableName);
 	    cgiMakeCheckBox(var, cartUsualBoolean(cart, var, ldInvDefault));
 	    printf("&nbsp;Invert display for %s<BR>&nbsp;&nbsp;\n",
 		   subTdb->longLabel);
 	    }
 	}
+    slFreeList(&tdbRefList);
     }
 else
     {
     safef(var, sizeof(var), "%s_inv", tdb->tableName);
@@ -2233,9 +2236,9 @@
 struct trackDb *tdb;
 printf("<P><TABLE CELLPADDING=2>");
 for (tdb = superTdb->subtracks; tdb != NULL; tdb = tdb->next)
     {
-    if (!hTableOrSplitExists(database, tdb->tableName) && trackDbSetting(tdb, "compositeTrack") == NULL) // NOTE: tdb if composite, is not yet populated with it's own subtracks!
+    if (!hTableOrSplitExists(database, tdb->tableName) && trackDbLocalSetting(tdb, "compositeTrack") == NULL) // NOTE: tdb if composite, is not yet populated with it's own subtracks!
         continue;
     printf("<TR>");
     printf("<TD NOWRAP><A HREF=\"%s?%s=%u&c=%s&g=%s\">%s</A>&nbsp;</TD>",
                 hgTrackUiName(), cartSessionVarName(), cartSessionId(cart),
@@ -2520,10 +2523,10 @@
 
 /* Print link for supertrack */
 if (tdbIsSuperTrackChild(tdb))
     {
-    assert((tdb->parentName));
-    struct trackDb *superTdb = hTrackDbForTrack(database, tdb->parentName);
+    struct trackDb *superTdb = tdb->parent;
+    assert(superTdb != NULL);
     if (superTdb)
         {
         char *encodedMapName = cgiEncode(superTdb->tableName);
         printf("<H3>Member of super-track: <A HREF=\"%s?%s=%u&c=%s&g=%s\">%s</A></H3>",
@@ -2692,17 +2695,18 @@
     }
 else if (sameString(track, "hgPcrResult"))
     tdb = pcrResultFakeTdb();
 else
+    {
     tdb = hTrackDbForTrack(database, track);
+    }
 if (tdb == NULL)
    errAbort("Can't find %s in track database %s chromosome %s",
 	    track, database, chromosome);
 char *super = trackDbGetSupertrackName(tdb);
 if (super)
     {
     /* configured as a supertrack member in trackDb */
-    tdb->parent = hTrackDbForTrack(database, super);    // TODO: Parent will not point to children
     if (tdb->parent)
         {
         /* the supertrack is also configured, so use supertrack defaults */
         tdbMarkAsSuperTrack(tdb->parent);

