本文整理了Java中org.broadinstitute.gatk.utils.Utils.getRandomGenerator()
方法的一些代码示例,展示了Utils.getRandomGenerator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getRandomGenerator()
方法的具体详情如下:
包路径:org.broadinstitute.gatk.utils.Utils
类名称:Utils
方法名:getRandomGenerator
暂无
代码示例来源:origin: broadgsa/gatk
/**
* Get a random int between min and max (inclusive) using the global GATK random number generator
*
* @param min lower bound of the range
* @param max upper bound of the range
* @return a random int >= min and <= max
*/
public static int randomIntegerInRange( final int min, final int max ) {
return Utils.getRandomGenerator().nextInt(max - min + 1) + min;
}
代码示例来源:origin: broadgsa/gatk
/**
* Create random read qualities
*
* @param length the length of the read
* @return an array with randomized base qualities between 0 and 50
*/
public static byte[] createRandomReadQuals(int length) {
Random random = Utils.getRandomGenerator();
byte[] quals = new byte[length];
for (int i = 0; i < length; i++)
quals[i] = (byte) random.nextInt(50);
return quals;
}
代码示例来源:origin: broadgsa/gatk
/**
* Return a random base index, excluding some base index.
*
* @param excludeBaseIndex the base index to exclude
* @return a random base index, excluding the one specified (A=0, C=1, G=2, T=3)
*/
static public int getRandomBaseIndex(int excludeBaseIndex) {
int randomBaseIndex = excludeBaseIndex;
while (randomBaseIndex == excludeBaseIndex) {
randomBaseIndex = Utils.getRandomGenerator().nextInt(4);
}
return randomBaseIndex;
}
代码示例来源:origin: broadgsa/gatk
/**
* Returns n random indices drawn with replacement from the range 0..(k-1)
*
* @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(final int n, final int k) {
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(Utils.getRandomGenerator().nextInt(n));
//balls.remove(chosen_ball);
}
return chosen_balls;
}
代码示例来源:origin: broadgsa/gatk-protected
public List<VariantDatum> getRandomDataForPlotting( final int numToAdd, final List<VariantDatum> trainingData, final List<VariantDatum> antiTrainingData, final List<VariantDatum> evaluationData ) {
final List<VariantDatum> returnData = new ExpandingArrayList<>();
Collections.shuffle(trainingData, Utils.getRandomGenerator());
Collections.shuffle(antiTrainingData, Utils.getRandomGenerator());
Collections.shuffle(evaluationData, Utils.getRandomGenerator());
returnData.addAll(trainingData.subList(0, Math.min(numToAdd, trainingData.size())));
returnData.addAll(antiTrainingData.subList(0, Math.min(numToAdd, antiTrainingData.size())));
returnData.addAll(evaluationData.subList(0, Math.min(numToAdd, evaluationData.size())));
Collections.shuffle(returnData, Utils.getRandomGenerator());
return returnData;
}
代码示例来源:origin: broadgsa/gatk
@Override
public void submit( final T newRead ) {
if ( Utils.getRandomGenerator().nextInt(10000) < cutoffForInclusion || doNotDiscardItem(newRead) ) {
selectedReads.add(newRead);
}
else {
numDiscardedItems++;
}
}
代码示例来源:origin: broadgsa/gatk
@BeforeClass
public void init() {
random = Utils.getRandomGenerator();
}
代码示例来源:origin: broadgsa/gatk-protected
private List<Integer> generateElementCollection(final int elementCount, final int maxElement) {
final Random rnd = Utils.getRandomGenerator();
final List<Integer> elementList = new ArrayList<>(elementCount);
for (int i = 0; i < elementCount; i++)
elementList.add(rnd.nextInt(maxElement + 1));
return elementList;
}
代码示例来源:origin: broadgsa/gatk-protected
private Map<Allele,List<Allele>> randomAlleleMap(final Allele[] fromAlleles, final Allele[] toAlleles) {
final Map<Allele,List<Allele>> result = new HashMap<>(toAlleles.length);
for (final Allele toAllele : toAlleles )
result.put(toAllele,new ArrayList<Allele>(fromAlleles.length));
final ArrayList<Allele> remaining = new ArrayList<>(Arrays.asList(fromAlleles));
int nextToIndex = 0;
final Random rnd = Utils.getRandomGenerator();
for (int i = 0; i < fromAlleles.length; i++) {
final int fromAlleleIndex = rnd.nextInt(remaining.size());
result.get(toAlleles[nextToIndex]).add(remaining.remove(fromAlleleIndex));
nextToIndex = (nextToIndex + 1) % toAlleles.length;
}
return result;
}
代码示例来源:origin: broadgsa/gatk
private byte[] getDeterministicRandomData ( int size ) {
Utils.resetRandomGenerator();
Random rand = Utils.getRandomGenerator();
byte[] randomData = new byte[size];
rand.nextBytes(randomData);
return randomData;
}
}
代码示例来源:origin: broadgsa/gatk-protected
private AlleleList<Allele> discardAllelesAtRandom(final AlleleList<Allele> likelihoods, final int discardAlleleCount) {
final Random rnd = Utils.getRandomGenerator();
final ArrayList<Allele> subset = new ArrayList<>(AlleleListUtils.asList(likelihoods));
for (int i = 0; i < discardAlleleCount; i++) {
subset.remove(rnd.nextInt(subset.size()));
}
return new IndexedAlleleList<>(subset);
}
代码示例来源:origin: broadgsa/gatk-protected
private void addBaseErrors(final byte[] readBases, final int phredScaledErrorRate) {
double errorProbability = QualityUtils.qualToErrorProb((byte)phredScaledErrorRate);
for (int k=0; k < readBases.length; k++) {
if (Utils.getRandomGenerator().nextDouble() < errorProbability) {
// random offset
int offset = BaseUtils.simpleBaseToBaseIndex(readBases[k]); //0..3
offset += (Utils.getRandomGenerator().nextInt(3)+1); // adds 1,2 or 3
offset %= 4;
readBases[k] = BaseUtils.baseIndexToSimpleBase(offset);
}
}
}
}
代码示例来源:origin: broadgsa/gatk-protected
@Test(dataProvider = "capacityData")
public void testCapacity(final int initialCapacity, final int elementCount) {
final IntMaxHeap heap = new IntMaxHeap(initialCapacity);
final Random rnd = Utils.getRandomGenerator();
for (int i = 0; i < elementCount; i++) {
final int v = rnd.nextInt();
heap.add(v);
}
}
代码示例来源:origin: broadgsa/gatk-protected
private double[][][] fillWithRandomLikelihoods(final String[] samples, final Allele[] alleles, final ReadLikelihoods<Allele> result) {
final Random rnd = Utils.getRandomGenerator();
final double[][][] likelihoods = new double[samples.length][alleles.length][];
for (int s = 0; s < likelihoods.length; s++) {
final ReadLikelihoods.Matrix<Allele> sampleLikelihoods = result.sampleMatrix(s);
for (int a = 0; a < likelihoods[s].length; a++) {
likelihoods[s][a] = new double[result.sampleReadCount(s)];
for (int r = 0; r < likelihoods[s][a].length; r++)
sampleLikelihoods.set(a,r,likelihoods[s][a][r] = -Math.abs(rnd.nextGaussian()));
}
}
return likelihoods;
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "SimplePositionalDownsamplerTestDataProvider")
public Object[][] createSimplePositionalDownsamplerTestData() {
Utils.resetRandomGenerator();
for ( int targetCoverage = 1; targetCoverage <= 10000; targetCoverage *= 10 ) {
for ( int contigs = 1; contigs <= 2; contigs++ ) {
for ( int numStacks = 0; numStacks <= 10; numStacks++ ) {
List<Integer> stackSizes = new ArrayList<Integer>(numStacks);
for ( int stack = 1; stack <= numStacks; stack++ ) {
stackSizes.add(Utils.getRandomGenerator().nextInt(targetCoverage * 2) + 1);
}
new SimplePositionalDownsamplerTest(targetCoverage, stackSizes, contigs > 1);
}
}
}
return SimplePositionalDownsamplerTest.getTests(SimplePositionalDownsamplerTest.class);
}
代码示例来源:origin: broadgsa/gatk
private static GenotypesContext createGenotypesContext(final int numGenotypes, final List<Allele> alleles) {
Utils.resetRandomGenerator();
final Random random = Utils.getRandomGenerator();
final GenotypesContext gc = GenotypesContext.create();
for ( int i = 0; i < numGenotypes; i++ ) {
// choose alleles at random
final List<Allele> myAlleles = new ArrayList<Allele>();
myAlleles.add(alleles.get(random.nextInt(2)));
myAlleles.add(alleles.get(random.nextInt(2)));
final Genotype g = new GenotypeBuilder(String.format("%d", i)).alleles(myAlleles).make();
gc.add(g);
}
return gc;
}
代码示例来源:origin: broadgsa/gatk-protected
@Test(dataProvider = "capacityData", dependsOnMethods = {"testEmptynessAndSize"})
public void testClear(final int initialCapacity, final int elementCount) {
final IntMaxHeap heap = new IntMaxHeap(initialCapacity);
final Random rnd = Utils.getRandomGenerator();
for (int i = 0; i < elementCount; i++) {
final int v = rnd.nextInt();
heap.add(v);
}
heap.clear();
Assert.assertEquals(heap.size(),0);
Assert.assertTrue(heap.isEmpty());
}
代码示例来源:origin: broadgsa/gatk
@Test (enabled = true)
public void testGetBasesReverseComplement() {
int iterations = 1000;
Random random = Utils.getRandomGenerator();
while(iterations-- > 0) {
final int l = random.nextInt(1000);
GATKSAMRecord read = GATKSAMRecord.createRandomRead(l);
byte [] original = read.getReadBases();
byte [] reconverted = new byte[l];
String revComp = ReadUtils.getBasesReverseComplement(read);
for (int i=0; i<l; i++) {
reconverted[l-1-i] = BaseUtils.getComplement((byte) revComp.charAt(i));
}
Assert.assertEquals(reconverted, original);
}
}
代码示例来源:origin: broadgsa/gatk-protected
@Test(dataProvider = "capacityData", dependsOnMethods = {"testCapacity"})
public void testPeek(final int initialCapacity, final int elementCount) {
final IntMaxHeap heap = new IntMaxHeap(initialCapacity);
final Random rnd = Utils.getRandomGenerator();
int top = rnd.nextInt();
heap.add(top);
Assert.assertEquals(heap.peek(),top);
for (int i = 1; i < elementCount; i++) {
final int v = rnd.nextInt();
if (v > top) top = v;
heap.add(v);
Assert.assertEquals(heap.peek(),top);
}
}
代码示例来源:origin: broadgsa/gatk-protected
@Test(dataProvider = "capacityData",dependsOnMethods = {"testCapacity"})
public void testEmptynessAndSize(final int initialCapacity, final int elementCount) {
final IntMaxHeap heap = new IntMaxHeap(initialCapacity);
final Random rnd = Utils.getRandomGenerator();
Assert.assertEquals(heap.size(),0);
Assert.assertTrue(heap.isEmpty());
for (int i = 0; i < elementCount; i++) {
final int v = rnd.nextInt();
heap.add(v);
Assert.assertEquals(heap.size(),i+1);
Assert.assertFalse(heap.isEmpty());
}
}
内容来源于网络,如有侵权,请联系作者删除!