043102a443731a0d579d9766157ff57968d30d02 braney Tue Jan 9 14:52:24 2018 -0800 implement missing data and reading of WIB files into mathWigs. diff --git src/hg/hgTracks/bigWigTrack.c src/hg/hgTracks/bigWigTrack.c index b1b2d2e..1b1e71d 100644 --- src/hg/hgTracks/bigWigTrack.c +++ src/hg/hgTracks/bigWigTrack.c @@ -5,30 +5,31 @@ #include "common.h" #include "hash.h" #include "linefile.h" #include "jksql.h" #include "hdb.h" #include "hgTracks.h" #include "localmem.h" #include "wigCommon.h" #include "bbiFile.h" #include "bigWig.h" #include "errCatch.h" #include "container.h" #include "bigWarn.h" #include "mathWig.h" +#include "float.h" struct preDrawContainer *bigWigLoadPreDraw(struct track *tg, int seqStart, int seqEnd, int width) /* Do bits that load the predraw buffer tg->preDrawContainer. */ { /* Just need to do this once... */ if (tg->preDrawContainer != NULL) return tg->preDrawContainer; struct preDrawContainer *preDrawList = NULL; /* protect against temporary network error */ struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { /* Allocate predraw area. */ @@ -152,104 +153,109 @@ int preDrawZero = pre->preDrawZero; unsigned size = winEnd - winStart; double dataPerPixel = size / (double) insideWidth; int pixel; for (pixel=0; pixelpreDraw[pixel + preDrawZero]; double startReal = pixel * dataPerPixel; double endReal = (pixel + 1) * dataPerPixel; unsigned startUns = startReal; unsigned endUns = endReal; double realCount, realSum, realSumSquares, max, min; realCount = realSum = realSumSquares = 0.0; - max = min = data[startUns]; + max = -DBL_MAX; + min = DBL_MAX; assert(startUns != endUns); unsigned ceilUns = ceil(startReal); - if (ceilUns != startUns) + if ((ceilUns != startUns) && !isnan(data[startUns])) { /* need a fraction of the first count */ double frac = (double)ceilUns - startReal; realCount = frac; realSum = frac * data[startUns]; realSumSquares = realSum * realSum; + if (max < data[startUns]) + max = data[startUns]; + if (min > data[startUns]) + min = data[startUns]; startUns++; } // add in all the data that are totally in this pixel for(; startUns < endUns; startUns++) { + if (!isnan(data[startUns])) + { realCount += 1.0; realSum += data[startUns]; realSumSquares += data[startUns] * data[startUns]; if (max < data[startUns]) max = data[startUns]; if (min > data[startUns]) min = data[startUns]; } + } // add any fraction of the count that's only partially in this pixel double lastFrac = endReal - endUns; double lastSum = lastFrac * data[endUns]; - if ((lastFrac > 0.0) && (endUns < size)) + if ((lastFrac > 0.0) && (endUns < size) && !isnan(data[endUns])) { if (max < data[endUns]) max = data[endUns]; if (min > data[endUns]) min = data[endUns]; realCount += lastFrac; realSum += lastSum; realSumSquares += lastSum * lastSum; } pe->count = normalizeCount(pe, realCount, min, max, realSum, realSumSquares); } } static void dataToPixels(double *data, struct preDrawContainer *pre) /* Sample data into pixels. */ { unsigned size = winEnd - winStart; double dataPerPixel = size / (double) insideWidth; if (dataPerPixel <= 1.0) dataToPixelsUp(data, pre); else dataToPixelsDown(data, pre); } static void mathWigLoadItems(struct track *tg) /* Fill up tg->items with bedGraphItems derived from a bigWig file */ { char *missingSetting; -boolean missingIsZero = FALSE; +boolean missingIsZero = TRUE; if ((missingSetting = trackDbSetting(tg->tdb, "missingMethod")) != NULL) { - missingIsZero = sameString(missingSetting, "missing"); + missingIsZero = differentString(missingSetting, "missing"); } char *equation = cloneString(trackDbSetting(tg->tdb, "mathDataUrl")); struct preDrawContainer *pre = tg->preDrawContainer = initPreDrawContainer(insideWidth); double *data; -if (missingIsZero) - data = mathWigGetValuesMissing(equation, chromName, winStart, winEnd); -else - data = mathWigGetValues(equation, chromName, winStart, winEnd); +data = mathWigGetValues(database, equation, chromName, winStart, winEnd, missingIsZero); dataToPixels(data, pre); free(data); } static void bigWigLoadItems(struct track *tg) /* Fill up tg->items with bedGraphItems derived from a bigWig file */ { char *extTableString = trackDbSetting(tg->tdb, "extTable"); if (tg->bbiFile == NULL) { /* Figure out bigWig file name. */ if (tg->parallelLoading) // do not use mysql during parallel-fetch {