8933db12a9efed4981ada1fcc16e51a364147b0a braney Tue Jun 4 16:57:53 2019 -0700 look for BAM index by just adding .bai to the end of the bam file, and if that does NOT work , try replacing the old suffix (presumably .bam) with .bai and try that. Also, we weren't adding the whole URL to bigDataIndex in hubs, so now we do. diff --git src/lib/bamFile.c src/lib/bamFile.c index 6e9e003..ce3674d 100644 --- src/lib/bamFile.c +++ src/lib/bamFile.c @@ -15,35 +15,51 @@ #include "psl.h" // If KNETFILE_HOOKS is used (as recommended!), then we can simply call bam_index_load // without worrying about the samtools lib creating local cache files in cgi-bin: static bam_index_t *bamOpenIndexGivenUrl(samfile_t *sam, char *fileOrUrl, char *baiFileOrUrl) /* If fileOrUrl has a valid accompanying .bai file, parse and return the index; * otherwise return NULL. baiFileOrUrl can be NULL. * The difference to bamOpenIndex is that the URL/filename of the bai file can be specified. */ { if (sam->format.format == cram) return sam_index_load(sam, fileOrUrl); // assume that index is a .bai file char indexName[4096]; +bam_index_t *ret = NULL; if (baiFileOrUrl==NULL) + { + // first try tacking .bai on the end of the bam file name safef(indexName, sizeof indexName, "%s.bai", fileOrUrl); + if ((ret = sam_index_load2(sam, fileOrUrl, indexName)) == NULL) + { + // since the open didn't work, try replacing suffix (if any) with .bai + safef(indexName, sizeof indexName - sizeof(".bai"), "%s", fileOrUrl); + char *lastDot = strrchr(indexName, '.'); + if (lastDot) + { + strcpy(lastDot, ".bai"); + ret = sam_index_load2(sam, fileOrUrl, indexName); + } + } + } else - safef(indexName, sizeof indexName, "%s", baiFileOrUrl); -return sam_index_load2(sam, fileOrUrl, indexName); + ret = sam_index_load2(sam, fileOrUrl, baiFileOrUrl); + +return ret; } static void bamCloseIdx(bam_index_t **pIdx) /* Free unless already NULL. */ { if (pIdx != NULL && *pIdx != NULL) { free(*pIdx); // Not freeMem, freez etc -- sam just uses malloc/calloc. *pIdx = NULL; } } static bam_index_t *bamOpenIdx(samfile_t *sam, char *fileOrUrl) /* If fileOrUrl has a valid accompanying .bai file, parse and return the index;