Cosmetic change to list sampling functions: the typical usage of n and k were reversed. No change in functionality of the classes has been made and unit tests still pass.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1736 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
39598f1f0a
commit
5662a88ee1
|
|
@ -75,7 +75,7 @@ public class CoverageEvalWalker extends LocusWalker<List<String>, String> {
|
|||
for (int coverage : coverage_levels) {
|
||||
coverage = Math.min(coverage_available, coverage); // don't exceed max available coverage
|
||||
for (int r=0; r<downsampling_repeats; r++) {
|
||||
List<Integer> subset_indices = ListUtils.sampleIndicesWithReplacement(coverage, coverage_available);
|
||||
List<Integer> subset_indices = ListUtils.sampleIndicesWithReplacement(coverage_available, coverage);
|
||||
List<SAMRecord> sub_reads = ListUtils.sliceListByIndices(subset_indices, reads);
|
||||
List<Integer> sub_offsets = ListUtils.sliceListByIndices(subset_indices, offsets);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Integer> sampleIndicesWithReplacement(int n, int k) {
|
||||
|
||||
ArrayList<Integer> chosen_balls = new ArrayList <Integer>();
|
||||
for (int i=0; i<n; i++) {
|
||||
ArrayList<Integer> chosen_balls = new ArrayList <Integer>(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<Integer> sampleIndicesWithoutReplacement(int n, int k) {
|
||||
ArrayList<Integer> chosen_balls = new ArrayList<Integer>(k);
|
||||
|
|
|
|||
|
|
@ -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<Integer> Five = new ArrayList<Integer>();
|
||||
Collections.addAll(Five, 0, 1, 2, 3, 4);
|
||||
List<Integer> BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5);
|
||||
List<Integer> 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<Character> FiveAlpha = new ArrayList<Character>();
|
||||
Collections.addAll(FiveAlpha, 'a', 'b', 'c', 'd', 'e');
|
||||
List<Integer> BigFive = ListUtils.sampleIndicesWithReplacement(10000, 5);
|
||||
List<Integer> BigFive = ListUtils.sampleIndicesWithReplacement(5, 10000);
|
||||
List<Character> BigFiveAlpha = ListUtils.sliceListByIndices(BigFive, FiveAlpha);
|
||||
Assert.assertTrue(BigFiveAlpha.containsAll(FiveAlpha));
|
||||
Assert.assertTrue(FiveAlpha.containsAll(BigFiveAlpha));
|
||||
|
|
|
|||
Loading…
Reference in New Issue