1ff13b05ec6129e0fad8708bee411fab56443b14 braney Tue Feb 1 17:41:59 2022 -0800 deal properly with chroms with no items on any chroms, including aliases diff --git src/lib/bbiRead.c src/lib/bbiRead.c index 2c7fadc..e5840b0 100644 --- src/lib/bbiRead.c +++ src/lib/bbiRead.c @@ -186,38 +186,38 @@ 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) { // didn't find chrom name, but have an alias hash. Try the aliases struct hashEl *hel = hashLookup(bbi->aliasHash, chrom); - while(hel) + for(; hel; hel = hashLookupNext(hel)) { char *alias = hel->val; if (bptFileFind(bbi->chromBpt, alias, strlen(alias), idSize, sizeof(idSize))) break; - - hel = hashLookupNext(hel); } + if (hel == 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, char *chrom, bits32 start, bits32 end, bits32 *retChromId)