本文整理了Java中org.broadinstitute.gatk.utils.Utils.makePermutations()
方法的一些代码示例,展示了Utils.makePermutations()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.makePermutations()
方法的具体详情如下:
包路径:org.broadinstitute.gatk.utils.Utils
类名称:Utils
方法名:makePermutations
[英]Make all combinations of N size of objects if objects = [A, B, C] if N = 1 => [[A], [B], [C]] if N = 2 => [[A, A], [B, A], [C, A], [A, B], [B, B], [C, B], [A, C], [B, C], [C, C]]
[中]如果对象=[A,B,C]如果N=1=>[[A],[B],[C]]如果N=2=>[[A,A],[B,A],[C,A],[A,B],[B,B],[C,B],[C,C],[C,C]]
代码示例来源:origin: broadgsa/gatk
/**
* Make all combinations of N size of objects
*
* if objects = [A, B, C]
* if N = 1 => [[A], [B], [C]]
* if N = 2 => [[A, A], [B, A], [C, A], [A, B], [B, B], [C, B], [A, C], [B, C], [C, C]]
*
* @param objects list of objects
* @param n size of each combination
* @param withReplacement if false, the resulting permutations will only contain unique objects from objects
* @return a list with all combinations with size n of objects.
*/
public static <T> List<List<T>> makePermutations(final List<T> objects, final int n, final boolean withReplacement) {
final List<List<T>> combinations = new ArrayList<List<T>>();
if ( n == 1 ) {
for ( final T o : objects )
combinations.add(Collections.singletonList(o));
} else if (n > 1) {
final List<List<T>> sub = makePermutations(objects, n - 1, withReplacement);
for ( List<T> subI : sub ) {
for ( final T a : objects ) {
if ( withReplacement || ! subI.contains(a) )
combinations.add(Utils.cons(a, subI));
}
}
}
return combinations;
}
代码示例来源:origin: broadgsa/gatk-protected
@DataProvider(name = "GetBasesData")
public Object[][] makeGetBasesData() {
List<Object[]> tests = new ArrayList<>();
final List<String> frags = Arrays.asList("ACT", "GAC", "CAT");
for ( int n = 1; n <= frags.size(); n++ ) {
for ( final List<String> comb : Utils.makePermutations(frags, n, false) ) {
tests.add(new Object[]{comb});
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "ArrayMinData")
public Object[][] makeArrayMinData() {
List<Object[]> tests = new ArrayList<>();
// this functionality can be adapted to provide input data for whatever you might want in your data
tests.add(new Object[]{Arrays.asList(10), 10});
tests.add(new Object[]{Arrays.asList(-10), -10});
for ( final List<Integer> values : Utils.makePermutations(Arrays.asList(1,2,3), 3, false) ) {
tests.add(new Object[]{values, 1});
}
for ( final List<Integer> values : Utils.makePermutations(Arrays.asList(1,2,-3), 3, false) ) {
tests.add(new Object[]{values, -3});
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "MedianData")
public Object[][] makeMedianData() {
final List<Object[]> tests = new ArrayList<>();
// this functionality can be adapted to provide input data for whatever you might want in your data
tests.add(new Object[]{Arrays.asList(10), 10});
tests.add(new Object[]{Arrays.asList(1, 10), 10});
for ( final List<Integer> values : Utils.makePermutations(Arrays.asList(1,2,-3), 3, false) ) {
tests.add(new Object[]{values, 1});
}
for ( final List<Double> values : Utils.makePermutations(Arrays.asList(1.1,2.1,-3.1), 3, false) ) {
tests.add(new Object[]{values, 1.1});
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk-protected
@DataProvider(name = "ThetaNTests")
public Object[][] makeThetaNTests() {
List<Object[]> tests = new ArrayList<Object[]>();
final List<Double> log10LAlleles = Arrays.asList(0.0, -1.0, -2.0, -3.0, -4.0);
for ( final double log10pRef : Arrays.asList(-1, -2, -3) ) {
for ( final int ploidy : Arrays.asList(1, 2, 3, 4) ) {
for ( List<Double> permutations : Utils.makePermutations(log10LAlleles, ploidy, true)) {
tests.add(new Object[]{permutations, Math.pow(10, log10pRef)});
}
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk-protected
@DataProvider(name = "MultiplicityData")
public Object[][] makeMultiplicityData() {
List<Object[]> tests = new ArrayList<>();
final List<Integer> countsPerSample = Arrays.asList(0, 1, 2, 3, 4, 5);
for ( final int numSamplesPruning : Arrays.asList(1, 2, 3) ) {
for ( final int nSamples : Arrays.asList(1, 2, 3, 4, 5)) {
for ( final List<Integer> perm : Utils.makePermutations(countsPerSample, nSamples, false) ) {
tests.add(new Object[]{new MultiplicityTestProvider(perm, numSamplesPruning)});
}
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk
@Test(enabled = !DEBUG, dataProvider = "ForwardClippingData")
public void testForwardClipping(final List<String> alleleStrings, final int expectedClip) {
final List<Allele> alleles = new LinkedList<Allele>();
for ( final String alleleString : alleleStrings )
alleles.add(Allele.create(alleleString));
for ( final List<Allele> myAlleles : Utils.makePermutations(alleles, alleles.size(), false)) {
final int actual = GATKVariantContextUtils.computeForwardClipping(myAlleles);
Assert.assertEquals(actual, expectedClip);
}
}
代码示例来源:origin: broadgsa/gatk
private final List<List<CigarElement>> makeCigarElementCombinations() {
// this functionality can be adapted to provide input data for whatever you might want in your data
final List<CigarElement> cigarElements = new LinkedList<CigarElement>();
for ( final int size : Arrays.asList(0, 10) ) {
for ( final CigarOperator op : CigarOperator.values() ) {
cigarElements.add(new CigarElement(size, op));
}
}
final List<List<CigarElement>> combinations = new LinkedList<List<CigarElement>>();
for ( final int nElements : Arrays.asList(1, 2, 3) ) {
combinations.addAll(Utils.makePermutations(cigarElements, nElements, true));
}
return combinations;
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "StateTest")
public Object[][] createStateTest() {
for ( final int nThreads : Arrays.asList(3) ) {
//final List<EfficiencyMonitoringThreadFactory.State> allStates = Arrays.asList(EfficiencyMonitoringThreadFactory.State.WAITING_FOR_IO);
final List<EfficiencyMonitoringThreadFactory.State> allStates = Arrays.asList(EfficiencyMonitoringThreadFactory.State.USER_CPU, EfficiencyMonitoringThreadFactory.State.WAITING, EfficiencyMonitoringThreadFactory.State.BLOCKING);
//final List<EfficiencyMonitoringThreadFactory.State> allStates = Arrays.asList(EfficiencyMonitoringThreadFactory.State.values());
for (final List<EfficiencyMonitoringThreadFactory.State> states : Utils.makePermutations(allStates, nThreads, true) ) {
//if ( Collections.frequency(states, Thread.State.BLOCKED) > 0)
new StateTest(states);
}
}
return StateTest.getTests(StateTest.class);
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "ReadMetaDataTrackerTests")
public Object[][] createTrackerTests() {
List<Object[]> tests = new ArrayList<Object[]>();
final Object[][] singleTests = ReadMetaDataTrackerRODStreamTest.getTests(ReadMetaDataTrackerRODStreamTest.class);
final List<ReadMetaDataTrackerRODStreamTest> multiSiteTests = new ArrayList<ReadMetaDataTrackerRODStreamTest>();
for ( final Object[] singleTest : singleTests ) {
if ( ((ReadMetaDataTrackerRODStreamTest)singleTest[0]).intervals.size() > 1 )
multiSiteTests.add((ReadMetaDataTrackerRODStreamTest)singleTest[0]);
}
for ( final boolean testStateless : Arrays.asList(true, false) ) {
// all pairwise tests
for ( List<ReadMetaDataTrackerRODStreamTest> singleTest : Utils.makePermutations(multiSiteTests, 2, false)) {
tests.add(new Object[]{singleTest, testStateless});
}
// all 3 way pairwise tests
//for ( List<ReadMetaDataTrackerRODStreamTest> singleTest : Utils.makePermutations(multiSiteTests, 3, false)) {
// tests.add(new Object[]{singleTest, testStateless});
//}
}
logger.warn("Creating " + tests.size() + " tests for ReadMetaDataTrackerTests");
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk-protected
@Test
public void testComparison() {
final List<String> rawStrings = Arrays.asList("A", "C", "AC", "CT", "GTC", "ACGT");
final List<String> lexStrings = new ArrayList<String>(rawStrings);
Collections.sort(lexStrings);
for ( final List<String> seqs : Utils.makePermutations(lexStrings, lexStrings.size(), false) ) {
final List<Haplotype> haps = new ArrayList<Haplotype>(seqs.size());
for ( final String seq : seqs ) {
haps.add(new Haplotype(seq.getBytes(), false));
}
Collections.sort(haps, new HaplotypeBaseComparator());
for ( int i = 0; i < lexStrings.size(); i++ )
Assert.assertEquals(haps.get(i).getBaseString(), lexStrings.get(i), "Failed sort " + haps + " expected " + lexStrings);
}
}
}
代码示例来源:origin: broadgsa/gatk-protected
@Test
public void testComparison() {
// desired ordering is by size first, subordered by lexacographic relationship between bases
final List<String> rawStrings = Arrays.asList("A", "C", "AC", "CC", "CT", "AAT", "ACT", "GAT", "ACGT");
final List<String> lexStrings = new ArrayList<>(rawStrings);
for ( final List<String> seqs : Utils.makePermutations(lexStrings, lexStrings.size(), false) ) {
final List<Haplotype> haps = new ArrayList<>(seqs.size());
for ( final String seq : seqs ) {
haps.add(new Haplotype(seq.getBytes(), false));
}
Collections.sort(haps, new HaplotypeSizeAndBaseComparator());
for ( int i = 0; i < lexStrings.size(); i++ )
Assert.assertEquals(haps.get(i).getBaseString(), lexStrings.get(i), "Failed sort " + haps + " expected " + lexStrings);
}
}
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "LIBSTest")
public Object[][] createLIBSTests(final List<Integer> cigarLengths, final List<Integer> combinations) {
final List<Object[]> tests = new LinkedList<Object[]>();
final List<CigarOperator> allOps = Arrays.asList(CigarOperator.values());
final List<CigarElement> singleCigars = new LinkedList<CigarElement>();
for ( final int len : cigarLengths )
for ( final CigarOperator op : allOps )
singleCigars.add(new CigarElement(len, op));
for ( final int complexity : combinations ) {
for ( final List<CigarElement> elements : Utils.makePermutations(singleCigars, complexity, true) ) {
final LIBSTest test = makePermutationTest(elements);
if ( test != null ) tests.add(new Object[]{test});
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk-protected
@Test
public void testComparison() {
final List<Double> scores = Arrays.asList(3.0, 2.0, 1.0);
for ( final List<Double> myScores : Utils.makePermutations(scores, scores.size(), false) ) {
final List<Haplotype> haps = new ArrayList<Haplotype>(myScores.size());
for ( final double score : myScores ) {
final Haplotype h = new Haplotype("ACT".getBytes(), false);
h.setScore(score);
haps.add(h);
}
Collections.sort(haps, new HaplotypeScoreComparator());
for ( int i = 0; i < myScores.size(); i++ )
Assert.assertEquals(haps.get(i).getScore(), scores.get(i));
}
}
}
代码示例来源:origin: broadgsa/gatk-protected
@DataProvider(name = "polyTestProviderLotsOfAlleles")
public Object[][] makepolyTestProviderLotsOfAlleles() {
List<Object[]> tests = new ArrayList<Object[]>();
// list of all high-quality models in the system
final List<AFCalculatorImplementation> models = Arrays.asList(AFCalculatorImplementation.EXACT_INDEPENDENT);
final List<Integer> alleleCounts = Arrays.asList(0, 1, 2, 3, 4, 5, 10, 20);
final int nonTypePLs = 1000;
final int nAlleles = 4;
for ( final AFCalculatorImplementation model : models ) {
for ( final List<Integer> ACs : Utils.makePermutations(alleleCounts, nAlleles, true) ) {
final List<Boolean> isPoly = new ArrayList<Boolean>(ACs.size());
for ( final int ac : ACs ) isPoly.add(ac > 0);
final double acSum = MathUtils.sum(ACs);
for ( final int nSamples : Arrays.asList(1, 10, 100) ) {
if ( nSamples < acSum ) continue;
final AFCalculatorTestBuilder testBuilder
= new AFCalculatorTestBuilder(nSamples, nAlleles, model, AFCalculatorTestBuilder.PriorType.human);
tests.add(new Object[]{testBuilder, ACs, nonTypePLs, isPoly});
}
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "ReducerThreadTest")
public Object[][] createReducerThreadTest() {
List<Object[]> tests = new ArrayList<Object[]>();
for ( final int groupSize : Arrays.asList(-1, 1, 5, 50, 500, 5000, 50000) ) {
for ( final int nElements : Arrays.asList(0, 1, 3, 5) ) {
if ( groupSize < nElements ) {
for ( final List<MapResult<Integer>> jobs : Utils.makePermutations(makeJobs(nElements), nElements, false) ) {
tests.add(new Object[]{ new ListOfJobs(jobs), groupSize });
}
}
}
for ( final int nElements : Arrays.asList(10, 100, 1000, 10000, 100000, 1000000) ) {
if ( groupSize < nElements ) {
tests.add(new Object[]{ new ListOfJobs(makeJobs(nElements)), groupSize });
}
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk
@DataProvider(name = "PrevAndNextTest")
public Object[][] makePrevAndNextTest() {
final List<Object[]> tests = new LinkedList<Object[]>();
final List<CigarOperator> operators = Arrays.asList(CigarOperator.I, CigarOperator.P, CigarOperator.S);
for ( final CigarOperator firstOp : Arrays.asList(CigarOperator.M) ) {
for ( final CigarOperator lastOp : Arrays.asList(CigarOperator.M, CigarOperator.D) ) {
for ( final int nIntermediate : Arrays.asList(1, 2, 3) ) {
for ( final List<CigarOperator> combination : Utils.makePermutations(operators, nIntermediate, false) ) {
final int readLength = 2 + combination.size();
GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read", 0, 1, readLength);
read.setReadBases(Utils.dupBytes((byte) 'A', readLength));
read.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
String cigar = "1" + firstOp;
for ( final CigarOperator op : combination ) cigar += "1" + op;
cigar += "1" + lastOp;
read.setCigarString(cigar);
tests.add(new Object[]{read, firstOp, lastOp, combination});
}
}
}
}
return tests.toArray(new Object[][]{});
}
代码示例来源:origin: broadgsa/gatk-protected
@DataProvider(name = "wellFormedGLs")
public Object[][] createSimpleGLsData() {
final List<Genotype> biAllelicSamples = Arrays.asList(AA1, AB1, BB1);
final List<Genotype> triAllelicSamples = Arrays.asList(AA2, AB2, BB2, AC2, BC2, CC2);
for ( final int nSamples : Arrays.asList(1, 2, 3, 4) ) {
List<AFCalculator> calcs = createAFCalculators(Arrays.asList(AFCalculatorImplementation.values()), MAX_ALT_ALLELES, PLOIDY);
//number of entries in the priors array, one for AC=[0,2*nSamples]
final int nPriorValues = 2*nSamples+1;
//total number of chromosomes in our samples -- here we're assuming diploid
final int totalPloidy = 2*nSamples;
final double theta = 0.001;
final double[] flatPriors = MathUtils.normalizeFromLog10(new double[nPriorValues], true); // flat priors
final AFPriorProvider log10priorProvider = UnifiedGenotypingEngine.composeAlleleFrequencyPriorProvider(totalPloidy, theta, new ArrayList<Double>());
final double[] humanPriors = log10priorProvider.forTotalPloidy(totalPloidy);
for ( final double[] priors : Arrays.asList(flatPriors, humanPriors) ) { // , humanPriors) ) {
for ( AFCalculator model : calcs ) {
final String priorName = priors == humanPriors ? "human" : "flat";
// bi-allelic
if ( INCLUDE_BIALLELIC && nSamples <= biAllelicSamples.size() )
for ( List<Genotype> genotypes : Utils.makePermutations(biAllelicSamples, nSamples, true) )
new GetGLsTest(model, 1, genotypes, priors, priorName);
// tri-allelic
if ( INCLUDE_TRIALLELIC && ( ! priorName.equals("human") || Guillermo_FIXME ) && ! ( model instanceof OriginalDiploidExactAFCalculator) ) // || model != generalCalc ) )
for ( List<Genotype> genotypes : Utils.makePermutations(triAllelicSamples, nSamples, true) )
new GetGLsTest(model, 2, genotypes, priors, priorName);
}
}
}
return GetGLsTest.getTests(GetGLsTest.class);
}
代码示例来源:origin: broadgsa/gatk
@Test(enabled = !DEBUG)
public void testSubsetToRef() {
final Map<Genotype, Genotype> tests = new LinkedHashMap<>();
for ( final List<Allele> alleles : Arrays.asList(Arrays.asList(Aref), Arrays.asList(C), Arrays.asList(Aref, C), Arrays.asList(Aref, C, C) ) ) {
for ( final String name : Arrays.asList("test1", "test2") ) {
final GenotypeBuilder builder = new GenotypeBuilder(name, alleles);
builder.DP(10);
builder.GQ(30);
builder.AD(alleles.size() == 1 ? new int[]{1} : (alleles.size() == 2 ? new int[]{1, 2} : new int[]{1, 2, 3}));
builder.PL(alleles.size() == 1 ? new int[]{1} : (alleles.size() == 2 ? new int[]{1, 2} : new int[]{1, 2, 3}));
builder.attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY,
alleles.size() == 1 ? new int[]{1, 2} : (alleles.size() == 2 ? new int[]{1, 2, 3, 4} : new int[]{1, 2, 3, 4, 5, 6}));
final List<Allele> refs = Collections.nCopies(alleles.size(), Aref);
tests.put(builder.make(), builder.alleles(refs).noAD().noPL().attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, null).make());
}
}
for ( final int n : Arrays.asList(1, 2, 3) ) {
for ( final List<Genotype> genotypes : Utils.makePermutations(new ArrayList<>(tests.keySet()), n, false) ) {
final VariantContext vc = new VariantContextBuilder("test", "20", 1, 1, Arrays.asList(Aref, C)).genotypes(genotypes).make();
final GenotypesContext gc = GATKVariantContextUtils.subsetToRefOnly(vc, 2);
Assert.assertEquals(gc.size(), genotypes.size());
for ( int i = 0; i < genotypes.size(); i++ ) {
assertGenotypesAreEqual(gc.get(i), tests.get(genotypes.get(i)));
}
}
}
}
代码示例来源:origin: broadgsa/gatk
@Test(enabled = !DEBUG, dataProvider = "SplitBiallelics", dependsOnMethods = "testSplitBiallelicsNoGenotypes")
public void testSplitBiallelicsGenotypes(final VariantContext vc, final List<VariantContext> expectedBiallelics) {
final List<Genotype> genotypes = new ArrayList<Genotype>();
int sampleI = 0;
for ( final List<Allele> alleles : Utils.makePermutations(vc.getAlleles(), 2, true) ) {
genotypes.add(GenotypeBuilder.create("sample" + sampleI++, alleles));
}
genotypes.add(GenotypeBuilder.createMissing("missing", 2));
final VariantContext vcWithGenotypes = new VariantContextBuilder(vc).genotypes(genotypes).make();
final List<VariantContext> biallelics = GATKVariantContextUtils.splitVariantContextToBiallelics(vcWithGenotypes);
for ( int i = 0; i < biallelics.size(); i++ ) {
final VariantContext actual = biallelics.get(i);
Assert.assertEquals(actual.getNSamples(), vcWithGenotypes.getNSamples()); // not dropping any samples
for ( final Genotype inputGenotype : genotypes ) {
final Genotype actualGenotype = actual.getGenotype(inputGenotype.getSampleName());
Assert.assertNotNull(actualGenotype);
if ( ! vc.isVariant() || vc.isBiallelic() )
Assert.assertEquals(actualGenotype, vcWithGenotypes.getGenotype(inputGenotype.getSampleName()));
else
Assert.assertTrue(actualGenotype.isNoCall());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!