WeightedPloidyHistogram { static int peakBucket(int bucketBuffer, @NotNull double[] histogram) { int maxBucket = -1; double maxBucketWeight = 0; for (int i = 0; i < histogram.length; i++) { if (Doubles.greaterThan(histogram[i], 0)) { double bucketWeight = 0; for (int j = Math.max(0, i - bucketBuffer); j <= Math.min(histogram.length - 1, i + bucketBuffer); j++) { bucketWeight += histogram[j]; } if (Doubles.greaterThan(bucketWeight, maxBucketWeight)) { maxBucketWeight = bucketWeight; maxBucket = i; } } } return maxBucket; } WeightedPloidyHistogram(final double maxPloidy, final double binWidth);   WeightedPloidyHistogram(final double maxPloidy, final double binWidth, final double offset); @NotNull double[] histogram(@NotNull final Collection<? extends WeightedPloidy> ploidies);  }
@Test public void testHistogramPeak() { assertEquals(2, WeightedPloidyHistogram.peakBucket(1, new double[]{10, 11, 1, 18, 8})); assertEquals(3, WeightedPloidyHistogram.peakBucket(1, new double[]{10, 11, 0, 18, 8})); assertEquals(1, WeightedPloidyHistogram.peakBucket(2, new double[]{10, 11, 0, 18, 8})); }