2d0f1f1f85b147f9176abe594f56106b364229e8
angie
  Mon Sep 12 14:09:52 2022 -0700
trackHubOpen doesn't actually connect the hub; use hubConnectLoadHubs so if/when the user selects the hub, it is connected.

diff --git src/hg/hgPhyloPlace/phyloPlace.c src/hg/hgPhyloPlace/phyloPlace.c
index 07fbf0f..c54637d 100644
--- src/hg/hgPhyloPlace/phyloPlace.c
+++ src/hg/hgPhyloPlace/phyloPlace.c
@@ -1,54 +1,57 @@
 /* Place SARS-CoV-2 sequences in phylogenetic tree using usher program. */
 
 /* Copyright (C) 2020 The Regents of the University of California */
 
 #include "common.h"
 #include "bigBed.h"
+#include "cart.h"
 #include "cheapcgi.h"
 #include "errCatch.h"
 #include "fa.h"
 #include "genePred.h"
+#include "grp.h"
 #include "hCommon.h"
 #include "hash.h"
 #include "hgConfig.h"
 #include "htmshell.h"
+#include "hubConnect.h"
 #include "hui.h"
 #include "iupac.h"
 #include "jsHelper.h"
 #include "linefile.h"
 #include "obscure.h"
 #include "parsimonyProto.h"
 #include "phyloPlace.h"
 #include "phyloTree.h"
 #include "pipeline.h"
 #include "psl.h"
 #include "ra.h"
 #include "regexHelper.h"
 #include "trackHub.h"
 #include "trashDir.h"
 #include "vcf.h"
 
 // Globals:
 static boolean measureTiming = FALSE;
 
 // Parameter constants:
 int maxGenotypes = 1000;        // Upper limit on number of samples user can upload at once.
 boolean showParsimonyScore = FALSE;
 
 
-struct slName *phyloPlaceDbList()
+struct slName *phyloPlaceDbList(struct cart *cart)
 /* Each subdirectory of PHYLOPLACE_DATA_DIR that contains a config.ra file is a supported db
  * or track hub name (without the hub_number_ prefix).  Return a list of them, or NULL if none
  * are found. */
 {
 struct slName *dbList = NULL;
 // I was hoping the pattern would be wildMatch'd only against filenames so I could use "config.ra",
 // but both directories and files must match the pattern so must use "*".
 struct slName *dataDirPaths = pathsInDirAndSubdirs(PHYLOPLACE_DATA_DIR, "*");
 struct slName *path;
 for (path = dataDirPaths;  path != NULL;  path = path->next)
     {
     if (endsWith(path->name, "/config.ra"))
         {
         char dir[PATH_LEN], name[FILENAME_LEN], extension[FILEEXT_LEN];
         splitPath(path->name, dir, name, extension);
@@ -70,40 +73,42 @@
                 {
                 // Not connected to session currently.  If the name looks like an NCBI Assembly ID
                 // then try connecting to the corresponding UCSC assembly hub.
                 regmatch_t substrs[5];
                 if (regexMatchSubstr(db, "^(GC[AF])_([0-9]{3})([0-9]{3})([0-9]{3})\\.[0-9]$",
                                      substrs, ArraySize(substrs)))
                     {
                     char gcPrefix[4], first3[4], mid3[4], last3[4];
                     regexSubstringCopy(db, substrs[1], gcPrefix, sizeof gcPrefix);
                     regexSubstringCopy(db, substrs[2], first3, sizeof first3);
                     regexSubstringCopy(db, substrs[3], mid3, sizeof mid3);
                     regexSubstringCopy(db, substrs[4], last3, sizeof last3);
                     struct dyString *dy = dyStringCreate("https://hgdownload.soe.ucsc.edu/hubs/%s/%s/%s/"
                                                          "%s/%s/hub.txt",
                                                          gcPrefix, first3, mid3, last3, db);
+                    // Use cart variables to pretend user clicked to connect to this hub.
+                    cartSetString(cart, hgHubDataText, dy->string);
+                    cartSetString(cart, hgHubGenome, db);
                     struct errCatch *errCatch = errCatchNew();
-                    struct trackHub *hub = NULL;
+                    char *hubDb = NULL;
                     if (errCatchStart(errCatch))
                         {
-                        hub = trackHubOpen(dy->string, db);
+                        hubDb = hubConnectLoadHubs(cart);
                         }
                     errCatchEnd(errCatch);
-                    if (hub != NULL && hub->genomeList != NULL &&
-                        endsWith(hub->genomeList->name, db))
-                        slNameAddHead(&dbList, hub->genomeList->name);
+                    if (hubDb != NULL)
+                        slNameAddHead(&dbList, hubDb);
                     }
                 }
             }
         }
     }
 // Reverse alphabetical sort to put wuhCor1/SARS-CoV-2 first
 slNameSort(&dbList);
 slReverse(&dbList);
 return dbList;
 }
 
 char *phyloPlaceDbSetting(char *db, char *settingName)
 /* Return a setting from hgPhyloPlaceData/<db>/config.ra or NULL if not found. */
 {
 static struct hash *configHash = NULL;
@@ -2573,52 +2578,47 @@
     }
 else
     {
     int i;
     for (i = 0;  i < node->numEdges;  i++)
         rAddLeafNames(node->edges[i], condensedNodes, nameHash, addComponents);
     }
 }
 
 static void addAliases(struct hash *nameHash, char *aliasFile)
 /* If there is an aliasFile, then add its mappings of ID/alias to full tree name to nameHash. */
 {
 if (isNotEmpty(aliasFile) && fileExists(aliasFile))
     {
     struct lineFile *lf = lineFileOpen(aliasFile, TRUE);
-    int missCount = 0;
     char *missExample = NULL;
     char *line;
     while (lineFileNextReal(lf, &line))
         {
         char *words[3];
         int wordCount = chopTabs(line, words);
         lineFileExpectWords(lf, 2, wordCount);
         char *fullName = hashFindVal(nameHash, words[1]);
         if (fullName)
             hashAdd(nameHash, words[0], fullName);
         else
             {
-            missCount++;
             if (missExample == NULL)
                 missExample = cloneString(words[1]);
             }
         }
     lineFileClose(&lf);
-    if (missCount > 0 && verboseLevel() > 1)
-        fprintf(stderr, "aliasFile %s: %d values in second column were not found in tree, "
-                "e.g. '%s'", aliasFile, missCount, missExample);
     }
 }
 
 static struct hash *getTreeNames(struct mutationAnnotatedTree *bigTree, char *aliasFile,
                                  boolean addComponents)
 /* Make a hash of full names of leaves of bigTree; if addComponents, also map components of those
  * names to the full names in case the user gives us partial names/IDs. */
 {
 int nodeCount = bigTree->nodeHash->elCount;
 struct hash *nameHash = hashNew(digitsBaseTwo(nodeCount) + 3);
 rAddLeafNames(bigTree->tree, bigTree->condensedNodes, nameHash, addComponents);
 addAliases(nameHash, aliasFile);
 return nameHash;
 }