double twoStdsOverMean(struct bbiFile *bbi) /* Figure out what is two standard deviations over mean for a bigWig file. This is * an often useful threshold. */ { struct bbiSummaryElement sum = bbiTotalSummary(bbi); double mean = sum.sumData/sum.validCount; double std = calcStdFromSums(sum.sumData, sum.sumSquares, sum.validCount); return mean + 2*std; }
double bigWigStd(struct bbiFile* bw) /* return the mean value of a bigWig */ { double na = NANUM; struct bbiSummaryElement bbs = bbiTotalSummary(bw); if (bbs.validCount == 0) return na; else return calcStdFromSums(bbs.sumData, bbs.sumSquares, bbs.validCount); }
double bigWigMean(struct bbiFile* bw) /* return the mean value of a bigWig */ { double na = NANUM; struct bbiSummaryElement bbs = bbiTotalSummary(bw); if (bbs.validCount == 0) return na; else return bbs.sumData / bbs.validCount; }
void bigWigInfo(char *fileName) /* bigWigInfo - Print out information about bigWig file.. */ { struct bbiFile *bwf = bigWigFileOpen(fileName); if (optionExists("minMax")) { struct bbiSummaryElement sum = bbiTotalSummary(bwf); printf("%f %f\n", sum.minVal, sum.maxVal); return; } printf("version: %d\n", bwf->version); printf("isCompressed: %s\n", (bwf->uncompressBufSize > 0 ? "yes" : "no")); printf("isSwapped: %d\n", bwf->isSwapped); printLabelAndLongNumber("primaryDataSize", bwf->unzoomedIndexOffset - bwf->unzoomedDataOffset); if (bwf->levelList != NULL) { long long indexEnd = bwf->levelList->dataOffset; printLabelAndLongNumber("primaryIndexSize", indexEnd - bwf->unzoomedIndexOffset); } printf("zoomLevels: %d\n", bwf->zoomLevels); if (optionExists("zooms")) { struct bbiZoomLevel *zoom; for (zoom = bwf->levelList; zoom != NULL; zoom = zoom->next) printf("\t%d\t%d\n", zoom->reductionLevel, (int)(zoom->indexOffset - zoom->dataOffset)); } struct bbiChromInfo *chrom, *chromList = bbiChromList(bwf); printf("chromCount: %d\n", slCount(chromList)); if (optionExists("chroms")) for (chrom=chromList; chrom != NULL; chrom = chrom->next) printf("\t%s %d %d\n", chrom->name, chrom->id, chrom->size); struct bbiSummaryElement sum = bbiTotalSummary(bwf); printLabelAndLongNumber("basesCovered", sum.validCount); printf("mean: %f\n", sum.sumData/sum.validCount); printf("min: %f\n", sum.minVal); printf("max: %f\n", sum.maxVal); printf("std: %f\n", calcStdFromSums(sum.sumData, sum.sumSquares, sum.validCount)); }
struct bigBedInterval *bigBedSelectRange(struct track *track, char *chrom, int start, int end, struct lm *lm) /* Return list of intervals in range. */ { struct bigBedInterval *result = NULL; /* protect against temporary network error */ struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { struct bbiFile *bbi = fetchBbiForTrack(track); int maxItems = min(BIGBEDMAXIMUMITEMS, maximumTrackItems(track)); // do not allow it to exceed BIGBEDMAXIMUMITEMS for bigBed result = bigBedIntervalQuery(bbi, chrom, start, end, maxItems + 1, lm); if (slCount(result) > maxItems) { track->limitedVis = tvDense; track->limitedVisSet = TRUE; result = NULL; AllocArray(track->summary, insideWidth); if (bigBedSummaryArrayExtended(bbi, chrom, start, end, insideWidth, track->summary)) { char *denseCoverage = trackDbSettingClosestToHome(track->tdb, "denseCoverage"); if (denseCoverage != NULL) { double endVal = atof(denseCoverage); if (endVal <= 0) { AllocVar(track->sumAll); *track->sumAll = bbiTotalSummary(bbi); } } } else freez(&track->summary); } bbiFileClose(&bbi); track->bbiFile = NULL; } errCatchEnd(errCatch); if (errCatch->gotError) { track->networkErrMsg = cloneString(errCatch->message->string); track->drawItems = bigDrawWarning; track->totalHeight = bigWarnTotalHeight; result = NULL; } errCatchFree(&errCatch); return result; }
char *printBigWigViewInfo(FILE *f, char *indent, struct view *view, struct composite *comp, struct taggedFile *tfList) /* Print out info for a bigWig view, including subtracks. */ { /* Look at all tracks in this view and calculate overall limits. */ double sumOfSums = 0, sumOfSumSquares = 0; bits64 sumOfN = 0; struct taggedFile *tf; for (tf = tfList; tf != NULL; tf = tf->next) { if (sameString(tf->manifest->outputType, view->name)) { char *relativeName = tf->manifest->fileName; char *path = relativeName; struct bbiFile *bbi = bigWigFileOpen(path); struct bbiSummaryElement sum = bbiTotalSummary(bbi); sumOfSums += sum.sumData; sumOfSumSquares += sum.sumSquares; sumOfN = sum.validCount; bigWigFileClose(&bbi); } } double mean = sumOfSums/sumOfN; double std = calcStdFromSums(sumOfSums, sumOfSumSquares, sumOfN); double clipMax = mean + 6*std; /* Output view stanza. */ char type[64]; safef(type, sizeof(type), "bigWig %g %g", 0.0, clipMax); fprintf(f, "%stype %s\n", indent, type); fprintf(f, "%sviewLimits 0:%g\n", indent, clipMax); fprintf(f, "%sminLimit 0\n", indent); fprintf(f, "%smaxLimit %g\n", indent, clipMax); fprintf(f, "%sautoScale off\n", indent); fprintf(f, "%smaxHeightPixels 100:32:16\n", indent); fprintf(f, "%swindowingFunction mean+whiskers\n", indent); return cloneString(type); }