diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageEvalWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageEvalWalker.java index 905ee2a68..ebd3cfa95 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageEvalWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/CoverageEvalWalker.java @@ -75,7 +75,7 @@ public class CoverageEvalWalker extends LocusWalker, String> { for (int coverage : coverage_levels) { coverage = Math.min(coverage_available, coverage); // don't exceed max available coverage for (int r=0; r subset_indices = ListUtils.sampleIndicesWithReplacement(coverage, coverage_available); + List subset_indices = ListUtils.sampleIndicesWithReplacement(coverage_available, coverage); List sub_reads = ListUtils.sliceListByIndices(subset_indices, reads); List sub_offsets = ListUtils.sliceListByIndices(subset_indices, offsets); diff --git a/java/src/org/broadinstitute/sting/utils/ListUtils.java b/java/src/org/broadinstitute/sting/utils/ListUtils.java index 15790c495..022fde37e 100644 --- a/java/src/org/broadinstitute/sting/utils/ListUtils.java +++ b/java/src/org/broadinstitute/sting/utils/ListUtils.java @@ -18,16 +18,16 @@ public class ListUtils { /** * Returns n random indices drawn with replacement from the range 0..(k-1) * - * @param n the number of random indices to draw (with replacement) - * @param k the total number of indices allowed - * @return a list of random indices ranging from 0 to (k-1) with possible duplicates + * @param n the total number of indices sampled from + * @param k the number of random indices to draw (with replacement) + * @return a list of k random indices ranging from 0 to (n-1) with possible duplicates */ static public ArrayList sampleIndicesWithReplacement(int n, int k) { - ArrayList chosen_balls = new ArrayList (); - for (int i=0; i chosen_balls = new ArrayList (k); + for (int i=0; i< k; i++) { //Integer chosen_ball = balls[rand.nextInt(k)]; - chosen_balls.add(rand.nextInt(k)); + chosen_balls.add(rand.nextInt(n)); //balls.remove(chosen_ball); } @@ -37,9 +37,9 @@ public class ListUtils { /** * Returns n random indices drawn without replacement from the range 0..(k-1) * - * @param n the number of random indices to draw (without replacement) - * @param k the total number of indices allowed - * @return a list of random indices ranging from 0 to (k-1) without duplicates + * @param n the total number of indices sampled from + * @param k the number of random indices to draw (without replacement) + * @return a list of k random indices ranging from 0 to (n-1) without duplicates */ static public ArrayList sampleIndicesWithoutReplacement(int n, int k) { ArrayList chosen_balls = new ArrayList(k); diff --git a/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java b/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java index 723a16476..7a0ee69d6 100644 --- a/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java +++ b/java/test/org/broadinstitute/sting/utils/ListUtilsTest.java @@ -4,10 +4,8 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.broadinstitute.sting.BaseTest; -import org.broadinstitute.sting.utils.MathUtils; -import java.io.File; import java.util.List; import java.util.ArrayList; import java.util.Collections; @@ -27,15 +25,15 @@ public class ListUtilsTest extends BaseTest { logger.warn("Executing testRandomIndicesWithReplacement"); // Check that the size of the list returned is correct - Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(0, 5).size() == 0); - Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(1, 5).size() == 1); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(5, 0).size() == 0); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(5, 1).size() == 1); Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(5, 5).size() == 5); - Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(1000, 5).size() == 1000); + Assert.assertTrue(ListUtils.sampleIndicesWithReplacement(5, 1000).size() == 1000); // Check that the list contains only the k element range that as asked for - no more, no less List Five = new ArrayList(); Collections.addAll(Five, 0, 1, 2, 3, 4); - List BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5); + List BigFive = ListUtils.sampleIndicesWithReplacement(5, 10000); Assert.assertTrue(BigFive.containsAll(Five)); Assert.assertTrue(Five.containsAll(BigFive)); } @@ -53,7 +51,7 @@ public class ListUtilsTest extends BaseTest { Collections.addAll(Five, 0, 1, 2, 3, 4); List FiveAlpha = new ArrayList(); Collections.addAll(FiveAlpha, 'a', 'b', 'c', 'd', 'e'); - List BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5); + List BigFive = ListUtils.sampleIndicesWithReplacement(5, 10000); List BigFiveAlpha = ListUtils.sliceListByIndices(BigFive, FiveAlpha); Assert.assertTrue(BigFiveAlpha.containsAll(FiveAlpha)); Assert.assertTrue(FiveAlpha.containsAll(BigFiveAlpha));