e63eaf218669b968f124b81ca45ea0c287943f75
braney
  Fri Mar 11 16:26:26 2022 -0800
use bpt index if available for 2bit assembly hubs

diff --git src/hg/lib/trackHub.c src/hg/lib/trackHub.c
index 038e584..81bb420 100644
--- src/hg/lib/trackHub.c
+++ src/hg/lib/trackHub.c
@@ -336,40 +336,49 @@
 
 char *trackHubDefaultChrom(char *database)
 /* Return the default chromosome for this track hub assembly. */
 {
 struct slName *chromList = trackHubAllChromNames(database);
 
 if (chromList == NULL)
     return NULL;
 
 char *defaultName = cloneString( chromList->name);
 slFreeList(&chromList);
 
 return defaultName;
 }
 
+static struct twoBitFile *openTwoBit(struct trackHubGenome *genome)
+/* Open a twoBit file that may or may not have a bpt index. */
+{
+if (genome->twoBitBptUrl)
+    return twoBitOpenExternalBptIndex(genome->twoBitPath, genome->twoBitBptUrl);
+else
+    return twoBitOpen(genome->twoBitPath);
+}
+
 struct chromInfo *trackHubMaybeChromInfo(char *database, char *chrom)
 /* Return a chromInfo structure for just this chrom in this database. 
  * Return NULL if chrom doesn't exist. */
 {
 struct trackHubGenome *genome = trackHubGetGenome(database);
 if (genome == NULL)
     return NULL;
 
 if (genome->tbf == NULL)
-    genome->tbf = twoBitOpen(genome->twoBitPath);
+    genome->tbf = openTwoBit(genome);
 if (!twoBitIsSequence(genome->tbf, chrom))
     return NULL;
 
 struct chromInfo *ci;
 AllocVar(ci);
 ci->chrom = cloneString(chrom);
 ci->fileName = genome->twoBitPath;
 ci->size = twoBitSeqSize(genome->tbf, chrom);
 
 return ci;
 }
 
 struct chromInfo *trackHubChromInfo(char *database, char *chrom)
 /* Return a chromInfo structure for just this chrom in this database. 
  * errAbort if chrom doesn't exist. */
@@ -422,31 +431,31 @@
 /* see if this assembly hub has an alias file, return url if present
  * returns NULL when not present
  */
 {
 return assemblyHubGenomeSetting(database, "chromAlias");
 }
 
 struct chromInfo *trackHubAllChromInfo(char *database)
 /* Return a chromInfo structure for all the chroms in this database. */
 {
 struct trackHubGenome *genome = trackHubGetGenome(database);
 if (genome == NULL)
     return NULL;
 
 if (genome->tbf == NULL)
-    genome->tbf = twoBitOpen(genome->twoBitPath);
+    genome->tbf = openTwoBit(genome);
 struct chromInfo *ci, *ciList = NULL;
 struct slName *chromList = twoBitSeqNames(genome->twoBitPath);
 
 for(; chromList; chromList = chromList->next)
     {
     AllocVar(ci);
     ci->chrom = cloneString(chromList->name);
     ci->fileName = cloneString(genome->twoBitPath);
     ci->size = twoBitSeqSize(genome->tbf, chromList->name);
     slAddHead(&ciList, ci);
     }
 slFreeList(&chromList);
 return ciList;
 }
 
@@ -601,30 +610,31 @@
 {
 struct lineFile *lf = udcWrapShortLineFile(url, NULL, MAX_HUB_GENOME_FILE_SIZE);
 struct trackHubGenome *list = NULL, *el;
 struct hash *hash = hub->genomeHash;
 
 struct hash *ra;
 while ((ra = raNextRecord(lf)) != NULL)
     {
     // allow that trackDb+hub+genome is in one single file
     if (hashFindVal(ra, "hub"))
         continue;
     if (hashFindVal(ra, "track"))
         break;
 
     char *twoBitPath = hashFindVal(ra, "twoBitPath");
+    char *twoBitBptUrl = hashFindVal(ra, "twoBitBptUrl");
     char *genome, *trackDb;
     if (twoBitPath != NULL)
 	genome = addHubName(hashFindVal(ra, "genome"), hub->name);
     else
 	genome = hashFindVal(ra, "genome");
     if (hub->defaultDb == NULL)
 	hub->defaultDb = genome;
     if (genome == NULL)
         badGenomeStanza(lf);
     if (hashLookup(hash, genome) != NULL)
         errAbort("Duplicate genome %s in stanza ending line %d of %s",
 		genome, lf->lineIx, lf->fileName);
     if (singleFile == NULL)
         {
         trackDb = hashFindVal(ra, "trackDb");
@@ -646,30 +656,32 @@
     char *groups = hashFindVal(ra, "groups");
     if (twoBitPath != NULL)
 	{
 	el->description  = hashFindVal(ra, "description");
 	char *organism = hashFindVal(ra, "organism");
 	if (organism == NULL)
 	    errAbort("must have 'organism' set in assembly hub in stanza ending line %d of %s",
 		     lf->lineIx, lf->fileName);
 	el->organism  = addHubName(organism, hub->name);
 	hashReplace(ra, "organism", el->organism);
 	el->defaultPos  = hashFindVal(ra, "defaultPos");
 	if (el->defaultPos == NULL)
 	    errAbort("must have 'defaultPos' set in assembly hub in stanza ending line %d of %s",
 		     lf->lineIx, lf->fileName);
 	el->twoBitPath = trackHubRelativeUrl(url, twoBitPath);
+        if (twoBitBptUrl != NULL)
+            el->twoBitBptUrl = trackHubRelativeUrl(url, twoBitBptUrl);
 
 	char *htmlPath = hashFindVal(ra, "htmlPath");
 	if (htmlPath != NULL)
 	    hashReplace(ra, "htmlPath",trackHubRelativeUrl(url, htmlPath));
 	if (groups != NULL)
 	    el->groups = trackHubRelativeUrl(url, groups);
 	addAssembly(genome, el, hub);
 	}
     el->settingsHash = ra;
     hashAdd(ra, "hubName", hub->shortLabel);
     }
 
 /* Clean up and go home. */
 lineFileClose(&lf);
 slReverse(&list);