57d153c3caf42b22dd4cff6138a54c1b8545333f kent Fri Mar 8 15:25:37 2013 -0800 Fixing a bug where sometimes zoom summaries would not be written out by bedGraphToBigWig. I'm seeing a lot of code that can be shared between bedGraphToBigWig and bedToBigBed. Refactored to share some now, will do more shortly. diff --git src/lib/bbiWrite.c src/lib/bbiWrite.c index aa9730e..72c817c 100644 --- src/lib/bbiWrite.c +++ src/lib/bbiWrite.c @@ -224,30 +224,59 @@ errAbort("%s is not sorted at line %d. Please use \"sort -k1,1 -k2,2n\" or bedSort and try again.", lf->fileName, lf->lineIx); minDiff = diff; } } lastStart = start; } slReverse(&usageList); *retMinDiff = minDiff; *retAveSize = (double)totalBases/bedCount; *retBedCount = bedCount; freeHash(&uniqHash); return usageList; } +int bbiCalcResScalesAndSizes(int aveSize, + int resScales[bbiMaxZoomLevels], int resSizes[bbiMaxZoomLevels]) +/* Fill in resScales with amount to zoom at each level, and zero out resSizes based + * on average span. Returns the number of zoom levels we actually will use. */ +{ +int resTryCount = bbiMaxZoomLevels, resTry; +int resIncrement = bbiResIncrement; +int minZoom = 10; +int res = aveSize; +if (res < minZoom) + res = minZoom; +for (resTry = 0; resTry < resTryCount; ++resTry) + { + resSizes[resTry] = 0; + resScales[resTry] = res; + // if aveSize is large, then the initial value of res is large, and we + // and we cannot do all 10 levels without overflowing res* integers and other related variables. + if (res > 1000000000) + { + resTryCount = resTry + 1; + verbose(2, "resTryCount reduced from 10 to %d\n", resTryCount); + break; + } + res *= resIncrement; + } +return resTryCount; +} + + int bbiCountSectionsNeeded(struct bbiChromUsage *usageList, int itemsPerSlot) /* Count up number of sections needed for data. */ { struct bbiChromUsage *usage; int count = 0; for (usage = usageList; usage != NULL; usage = usage->next) { int countOne = (usage->itemCount + itemsPerSlot - 1)/itemsPerSlot; count += countOne; verbose(2, "%s %d, %d blocks of %d\n", usage->name, usage->itemCount, countOne, itemsPerSlot); } return count; }