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

diff --git src/lib/twoBit.c src/lib/twoBit.c
index a5f7da3..035a572 100644
--- src/lib/twoBit.c
+++ src/lib/twoBit.c
@@ -505,31 +505,34 @@
         index->offset = (*tbf->ourReadBits64)(f, isSwapped);
     else
         index->offset = (*tbf->ourReadBits32)(f, isSwapped);
     hashAddSaveName(hash, name, index, &index->name);
     slAddHead(&tbf->indexList, index);
     }
 slReverse(&tbf->indexList);
 return tbf;
 }
 
 struct twoBitFile *twoBitOpenExternalBptIndex(char *twoBitName, char *bptName)
 /* Open file, read in header, but not regular index.  Instead use
  * bpt index.   Beware if you use this the indexList field will be NULL
  * as will the hash. */
 {
-struct twoBitFile *tbf = twoBitOpenReadHeader(twoBitName, FALSE);
+boolean useUdc = FALSE;
+if (hasProtocol(twoBitName))
+    useUdc = TRUE;
+struct twoBitFile *tbf = twoBitOpenReadHeader(twoBitName, useUdc);
 tbf->bpt = bptFileOpen(bptName);
 if (tbf->seqCount != tbf->bpt->itemCount)
     errAbort("%s and %s don't have same number of sequences!", twoBitName, bptName);
 return tbf;
 }
 
 
 static int findGreatestLowerBound(int blockCount, bits32 *pos, 
 	int val)
 /* Find index of greatest element in posArray that is less 
  * than or equal to val using a binary search. */
 {
 int startIx=0, endIx=blockCount-1, midIx;
 int posVal;
 
@@ -545,31 +548,31 @@
 	}
     midIx = ((startIx + endIx)>>1);
     posVal = pos[midIx];
     if (posVal < val)
         startIx = midIx+1;
     else
         endIx = midIx;
     }
 }
 
 static void twoBitSeekTo(struct twoBitFile *tbf, char *name)
 /* Seek to start of named record.  Abort if can't find it. */
 {
 if (tbf->bpt)
     {
-    bits32 offset;
+    bits64 offset;
     if (!bptFileFind(tbf->bpt, name, strlen(name), &offset, sizeof(offset)))
 	 errAbort("%s is not in %s", name, tbf->bpt->fileName);
     (*tbf->ourSeek)(tbf->f, offset);
     }
 else
     {
     struct twoBitIndex *index = hashFindVal(tbf->hash, name);
     if (index == NULL)
 	 errAbort("%s is not in %s", name, tbf->fileName);
     (*tbf->ourSeek)(tbf->f, index->offset);
     }
 }
 
 static void readBlockCoords(struct twoBitFile *tbf, boolean isSwapped, bits32 *retBlockCount,
 			    bits32 **retBlockStarts, bits32 **retBlockSizes)
@@ -1300,30 +1303,35 @@
 /* return the size of the all the sequence in file, not counting N's*/
 {
 struct twoBitIndex *index;
 long long totalSize = 0;
 for (index = tbf->indexList; index != NULL; index = index->next)
     {
     int size = twoBitSeqSizeNoNs(tbf, index->name);
     totalSize += size;
     }
 return totalSize;
 }
 
 boolean twoBitIsSequence(struct twoBitFile *tbf, char *chromName)
 /* Return TRUE if chromName is in 2bit file. */
 {
+if (tbf->bpt)
+    {
+    bits64 offset;
+    return  bptFileFind(tbf->bpt, chromName, strlen(chromName), &offset, sizeof(offset));
+    }
 return (hashFindVal(tbf->hash, chromName) != NULL);
 }
 
 struct hash *twoBitChromHash(char *fileName)
 /* Build a hash of chrom names with their sizes. */
 {
 struct twoBitFile *tbf = twoBitOpen(fileName);
 struct twoBitIndex *index;
 struct hash *hash = hashNew(digitsBaseTwo(tbf->seqCount));
 for (index = tbf->indexList; index != NULL; index = index->next)
     {
     hashAddInt(hash, index->name, twoBitSeqSize(tbf, index->name));
     }
 
 twoBitClose(&tbf);