93f1aea8db760b6d02766ab35413a0c3e2a63df8
braney
  Tue Oct 10 11:16:09 2017 -0700
fix hgc clicks on custom tracks in collections

diff --git src/hg/hgCollection/hgCollection.c src/hg/hgCollection/hgCollection.c
index 84526e1..ea987bd 100644
--- src/hg/hgCollection/hgCollection.c
+++ src/hg/hgCollection/hgCollection.c
@@ -472,61 +472,67 @@
 char *longLabel = collection->longLabel;
 fprintf(f,"track %s\n\
 shortLabel %s\n\
 compositeTrack on\n\
 autoScale on\n\
 aggregate  none\n\
 longLabel %s\n\
 %s on\n\
 color %ld,%ld,%ld \n\
 type wig \n\
 visibility full\n\n", parent, shortLabel, longLabel, CUSTOM_COMPOSITE_SETTING,
  0xff& (collection->color >> 16),0xff& (collection->color >> 8),0xff& (collection->color));
 
 }
 
+static void modifyName(struct trackDb *tdb, char *hubName, struct hash  *collectionNameHash)
+/* If this is a new track in the collection we want to make sure
+ * it gets a different name than the track in trackDb.
+ * If it's a custom track, we want to squirrel away the original track name. */
+{
+if ((tdb->grp == NULL) || differentString(tdb->grp, hubName))
+    {
+    hashStore(collectionNameHash,  tdb->track);
+
+    if (isCustomTrack(tdb->track))
+        hashAdd(tdb->settingsHash, "origTrackName", tdb->track);
+    }
+}
+
 static int outView(FILE *f, struct sqlConnection *conn, char *db, struct track *view, char *parent, struct hash *nameHash, struct hash *collectionNameHash, int priority, char *hubName)
 // output a view to a trackhub
 {
 fprintf(f,"\ttrack %s\n\
 \tshortLabel %s\n\
 \tlongLabel %s\n\
 \tview %s \n\
 \tcontainer mathWig\n\
 \tautoScale on  \n\
 \tparent %s \n\
 \tcolor %ld,%ld,%ld \n\
 \tpriority %d\n\
 \tviewFunc %s \n\
 \tvisibility %s\n", view->name, view->shortLabel, view->longLabel, view->name, parent, 0xff& (view->color >> 16),0xff& (view->color >> 8),0xff& (view->color), priority++, view->viewFunc, view->visibility);
-//fprintf(f,"\tequation +\n");
 fprintf(f, "\n");
 
-//int useColor = 0;
 struct track *track = view->trackList;
 for(; track; track = track->next)
     {
     struct trackDb *tdb = hashMustFindVal(nameHash, track->name);
-    if ((tdb->grp == NULL) || differentString(tdb->grp, hubName))
-        {
-        // this is a new track in the collection.  We want to make sure
-        // it gets a different name than the track in trackDb
-        hashStore(collectionNameHash,  tdb->track);
-        }
+    modifyName(tdb, hubName, collectionNameHash);
 
     outTdb(conn, db, f, track->name,tdb, view->name, track->visibility, track->color, track,  nameHash, collectionNameHash, 2, priority++);
-    //useColor++;
     }
 
 return priority;
 }
 
 static void updateHub(struct cart *cart, char *db, struct track *collectionList, struct hash *nameHash)
 // save our state to the track hub
 {
 char *filename = getHubName(cart, db);
 char *hubName = hubNameFromUrl(filename);
 
 FILE *f = mustOpen(filename, "w");
 chmod(filename, 0666);
 
 struct hash *collectionNameHash = newHash(6);
@@ -537,36 +543,31 @@
 for(collection = collectionList; collection; collection = collection->next)
     {
     outComposite(f, collection);
     struct trackDb *tdb;
     struct track *track;
     int priority = 1;
     for (track = collection->trackList; track; track = track->next)
         {
         if (track->viewFunc != NULL)
             {
             priority = outView(f, conn, db, track, collection->name,  nameHash, collectionNameHash, priority, hubName);
             }
         else
             {
             tdb = hashMustFindVal(nameHash, track->name);
-            if ((tdb->grp == NULL) || differentString(tdb->grp, hubName))
-                {
-                // this is a new track in the collection.  We want to make sure
-                // it gets a different name than the track in trackDb
-                hashStore(collectionNameHash,  tdb->track);
-                }
+            modifyName(tdb, hubName, collectionNameHash);
 
             outTdb(conn, db, f, track->name,tdb, collection->name, track->visibility, track->color, track,  nameHash, collectionNameHash, 1, priority++);
             }
         }
     }
 fclose(f);
 hFreeConn(&conn);
 }
 
 static unsigned long hexStringToLong(char *str)
 {
 return strtol(&str[1], NULL, 16);
 }
 
 struct jsonParseData