76541502f60ad17d6f23dec970af30a07e9ebc84 braney Fri Sep 14 15:59:34 2018 -0700 oops, forgot to close bigWig files after reading. #22088 diff --git src/hg/lib/mathWig.c src/hg/lib/mathWig.c index 12c790f..5c0de5f 100644 --- src/hg/lib/mathWig.c +++ src/hg/lib/mathWig.c @@ -134,31 +134,42 @@ struct wiggle *nextWiggle; for(wiggle = wiggleList; wiggle; wiggle = nextWiggle) { nextWiggle = wiggle->next; if (wiggle->span == minSpan) getWigDataFromFile(wiggle, array, winStart, winEnd); freez(&wiggle); } } void getBigWigData(char *file, char *chrom, unsigned winStart, unsigned winEnd, double *array) /* Query a bigBed file to find the wiggle values we need for a specified range. */ { struct lm *lm = lmInit(0); -struct bbiFile *bwf = bigWigFileOpen(hReplaceGbdb(file)); +static char *fileName = NULL; +static struct bbiFile *bwf = NULL; + +if ((fileName == NULL) || differentString(fileName, file)) + { + if (bwf != NULL) + bbiFileClose(&bwf); + + fileName = cloneString(file); + bwf = bigWigFileOpen(hReplaceGbdb(file)); + } + struct bbiInterval *iv, *ivList = bigWigIntervalQuery(bwf, chrom, winStart, winEnd, lm); unsigned width = winEnd - winStart; for (iv = ivList; iv != NULL; iv = iv->next) { unsigned start = max(0, iv->start - winStart); unsigned end = min(width, iv->end - winStart); int ii; for (ii = start; ii < end; ii++) array[ii] = iv->val; } } double *mathWigGetValues(char *db, char *equation, char *chrom, unsigned winStart, unsigned winEnd, boolean missingIsZero)