9ab880cbeaee49b0bd54a84f436445961044b820 braney Mon Jul 15 15:59:39 2019 -0700 in bbi files (bigWig, bigBed, etc.) check for chroms without 'chr' preface if otherwise chromosome isn't found diff --git src/lib/bbiRead.c src/lib/bbiRead.c index 4a9945d..ba6573a 100644 --- src/lib/bbiRead.c +++ src/lib/bbiRead.c @@ -171,31 +171,35 @@ { if (isSwapped) { idSize->chromId = byteSwap32(idSize->chromId); idSize->chromSize = byteSwap32(idSize->chromSize); } } struct fileOffsetSize *bbiOverlappingBlocks(struct bbiFile *bbi, struct cirTreeFile *ctf, char *chrom, bits32 start, bits32 end, bits32 *retChromId) /* Fetch list of file blocks that contain items overlapping chromosome range. */ { struct bbiChromIdSize idSize; if (!bptFileFind(bbi->chromBpt, chrom, strlen(chrom), &idSize, sizeof(idSize))) + { + // 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); if (retChromId != NULL) *retChromId = idSize.chromId; return cirTreeFindOverlappingBlocks(ctf, idSize.chromId, start, end); } struct chromNameCallbackContext /* Some stuff that the bPlusTree traverser needs for context. */ { struct bbiChromInfo *list; /* The list we are building. */ boolean isSwapped; /* Need to byte-swap things? */ }; static void chromNameCallback(void *context, void *key, int keySize, void *val, int valSize) /* Callback that captures chromInfo from bPlusTree. */