be07e4273228ea43ed8f24dc076af4a633e7916f kent Sun Jul 3 14:58:45 2022 -0700 Adding twoBitHasSeq function to query if a sequence exists in file. diff --git src/lib/twoBit.c src/lib/twoBit.c index 035a572..28d38cb 100644 --- src/lib/twoBit.c +++ src/lib/twoBit.c @@ -543,30 +543,45 @@ posVal = pos[startIx]; if (posVal <= val || startIx == 0) return startIx; else return startIx-1; } midIx = ((startIx + endIx)>>1); posVal = pos[midIx]; if (posVal < val) startIx = midIx+1; else endIx = midIx; } } +boolean twoBitHasSeq(struct twoBitFile *tbf, char *name) +/* Return TRUE if sequence of given name exists in two bit file */ +{ +if (tbf->bpt) + { + bits64 offset; + return bptFileFind(tbf->bpt, name, strlen(name), &offset, sizeof(offset)); + } +else + { + struct twoBitIndex *index = hashFindVal(tbf->hash, name); + return index != NULL; + } +} + static void twoBitSeekTo(struct twoBitFile *tbf, char *name) /* Seek to start of named record. Abort if can't find it. */ { if (tbf->bpt) { 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);