b622d147b7dbac52dbf3ba26928cd18e02d42bd8
braney
  Sat Feb 26 12:34:37 2022 -0800
add support for using a bigBed as the chromAlias file

diff --git src/lib/bbiRead.c src/lib/bbiRead.c
index e5840b0..f1ae799 100644
--- src/lib/bbiRead.c
+++ src/lib/bbiRead.c
@@ -65,42 +65,42 @@
 if (isSwapped)
     {
     magic = byteSwap32(magic);
     if (magic != sig)
         return FALSE;
     }
 else
     {
     if (magic != sig)
         return FALSE;
     }
 
 return TRUE;
 }
 
-struct bbiFile *bbiFileOpenAlias(char *fileName, bits32 sig, char *typeName, struct hash *aliasHash)
+struct bbiFile *bbiFileOpenAlias(char *fileName, bits32 sig, char *typeName, aliasFunc aliasFunc)
 /* Open up big wig or big bed file using a chrom alias hash if non-NULL */
 {
 /* This code needs to agree with code in two other places currently - bigBedFileCreate,
  * and bigWigFileCreate.  I'm thinking of refactoring to share at least between
  * bigBedFileCreate and bigWigFileCreate.  It'd be great so it could be structured
  * so that it could send the input in one chromosome at a time, and send in the zoom
  * stuff only after all the chromosomes are done.  This'd potentially reduce the memory
  * footprint by a factor of 2 or 4.  Still, for now it works. -JK */
 struct bbiFile *bbi;
 AllocVar(bbi);
-bbi->aliasHash = aliasHash;
+bbi->aliasFunc = aliasFunc;
 bbi->fileName = cloneString(fileName);
 struct udcFile *udc = bbi->udc = udcFileOpen(fileName, udcDefaultDir());
 
 /* Read magic number at head of file and use it to see if we are proper file type, and
  * see if we are byte-swapped. */
 bits32 magic;
 boolean isSwapped = FALSE;
 udcMustRead(udc, &magic, sizeof(magic));
 if (magic != sig)
     {
     magic = byteSwap32(magic);
     isSwapped = TRUE;
     if (magic != sig)
        errAbort("%s is not a %s file", fileName, typeName);
     }
@@ -181,42 +181,42 @@
     idSize->chromId = byteSwap32(idSize->chromId);
     idSize->chromSize = byteSwap32(idSize->chromSize);
     }
 }
 
 
 static struct bbiChromIdSize *getChromIdSize(struct bbiFile *bbi, char *chrom)
 /* Return idSize for given chrom, using chrom alias if available. */
 {
 struct bbiChromIdSize *idSize;
 AllocVar(idSize);
 
 // first look for the given chrom name
 if (!bptFileFind(bbi->chromBpt, chrom, strlen(chrom), idSize, sizeof(idSize)))
     {
-    if (bbi->aliasHash)
+    if (bbi->aliasFunc)
         {
-        // didn't find chrom name, but have an alias hash.  Try the aliases
-        struct hashEl *hel = hashLookup(bbi->aliasHash, chrom);
+        // didn't find chrom name, but have an alias function.  Try the aliases it returns.
+	struct slName *aliases = (*bbi->aliasFunc)(chrom);
 
-        for(; hel;  hel = hashLookupNext(hel))
+	for(; aliases; aliases = aliases->next)
             {
-            char *alias = hel->val;
+            char *alias = aliases->name;
             if (bptFileFind(bbi->chromBpt, alias, strlen(alias), idSize, sizeof(idSize)))
                 break;
             }
-        if (hel == NULL)   // did we run out of aliases to try?
+        if (aliases == NULL)   // did we run out of aliases to try?
             return NULL;
         }
     else
         {
         // if chrom is not found and the chrom starts with "chr", try without "chr"
         if (!startsWith("chr", chrom) || !bptFileFind(bbi->chromBpt, &chrom[3], strlen(chrom) - 3, idSize, sizeof(idSize)))
             return NULL;
         }
     }
 chromIdSizeHandleSwapped(bbi->isSwapped, idSize);
 
 return idSize;
 }
 
 struct fileOffsetSize *bbiOverlappingBlocks(struct bbiFile *bbi, struct cirTreeFile *ctf,