### Question:
BigWigManager { public double[] groupBy(Region region, int windowSize) { int zoomLevel = -1; for (int level = 0; level < zoomWindowSizes.size(); level++) { if (windowSize < zoomWindowSizes.get(level)) { break; } zoomLevel++; } windowSize = Math.max(1, windowSize); int start = region.getStart(); int end = region.getEnd(); int numWindows = (end - start + 1) / windowSize; if ((end - start + 1) % windowSize != 0) { numWindows++; end = start + (numWindows * windowSize - 1); } double[] chunks = new double[numWindows]; if (zoomLevel == -1) { BigWigIterator bigWigIterator = iterator(new Region(region.getChromosome(), start, end)); WigItem wItem; int length, chunkStart, chunkEnd; while (bigWigIterator.hasNext()) { wItem = bigWigIterator.next(); chunkStart = (Math.max(start, wItem.getStartBase()) - start) / windowSize; chunkEnd = (Math.min(end, wItem.getEndBase()) - start) / windowSize; for (int chunk = chunkStart; chunk <= chunkEnd; chunk++) { length = Math.min(wItem.getEndBase() - start, chunk * windowSize + windowSize) - Math.max(wItem.getStartBase() - start, chunk * windowSize); if (chunk < chunks.length) { chunks[chunk] += (wItem.getWigValue() * length); } } } } else { ZoomLevelIterator zoomIterator = iterator(new Region(region.getChromosome(), start, end), zoomLevel + 1); ZoomDataRecord wItem; int length, chunkStart, chunkEnd; while (zoomIterator.hasNext()) { wItem = zoomIterator.next(); chunkStart = (Math.max(start, wItem.getChromStart()) - start) / windowSize; chunkEnd = (Math.min(end, wItem.getChromEnd()) - start) / windowSize; for (int chunk = chunkStart; chunk <= chunkEnd; chunk++) { length = Math.min(wItem.getChromEnd() - start, chunk * windowSize + windowSize) - Math.max(wItem.getChromStart() - start, chunk * windowSize); if (chunk < chunks.length) { chunks[chunk] += (wItem.getMeanVal() * length); } } } } for (int i = 0; i < chunks.length; i++) { chunks[i] /= windowSize; } return chunks; } BigWigManager(Path bigwigPath); @Deprecated  BigWigManager(Path bigwigPath, Path indexPath); double[] query(Region region); BigWigIterator iterator(Region region); ZoomLevelIterator iterator(Region region, int zoomLevel); double[] groupBy(Region region, int windowSize); List<Integer> getZoomWindowSizes(); BBFileReader getBbFileReader(); @Deprecated
    static final String BIGWIG_DB; }### Answer:
@Test public void groupBy() throws Exception { Path bwPath = Paths.get(getClass().getResource("/wigVarStepExampleSmallChr21.bw").toURI()); String chrom = "chr21"; int start = 9480000; int end = 9500000; int windowSize = 10000; BigWigManager bigWigManager = new BigWigManager(bwPath); Region region = new Region(chrom, start, end); double[] coverage = bigWigManager.groupBy(region, windowSize); for (int i = 0; i < coverage.length ; i++) { System.out.println(i + ": " + coverage[i]); } }