From 95b45443ae584cbc01250a3359b3bdc1906f8dea Mon Sep 17 00:00:00 2001 From: Valentin Ruano-Rubio Date: Wed, 10 Sep 2014 13:42:57 -0400 Subject: [PATCH] Updated test according to changes in the AF calculator framework. Changes: ------- * Updated current unit and integration test to use the new API components. * Added unit tests for new classes AFPriorProvider and AFCalculatorProviders. * Added integration test for mixed ploidy GenotypeGVCFs and CombineGVCFs --- .../afcalc/AFCalcPerformanceTest.java | 24 +-- .../UnifiedGenotyperEngineUnitTest.java | 4 +- ...perGeneralPloidySuite1IntegrationTest.java | 6 +- ...perGeneralPloidySuite2IntegrationTest.java | 2 +- ...dGenotyperIndelCallingIntegrationTest.java | 2 +- ...GenotyperNormalCallingIntegrationTest.java | 4 +- .../afcalc/AFCalcPerformanceUnitTest.java | 17 +- .../genotyper/afcalc/AFCalcUnitTest.java | 98 +++++++---- .../FixedAFCalculatorProviderUnitTest.java | 166 ++++++++++++++++++ ...neralPloidyAFCalculationModelUnitTest.java | 9 +- ...yFailOverAFCalculatorProviderUnitTest.java | 162 +++++++++++++++++ ...dentAllelesDiploidExactAFCalcUnitTest.java | 8 +- .../AFPriorProviderUnitTest.java | 143 +++++++++++++++ ...plotypeCallerGenotypingEngineUnitTest.java | 101 ----------- .../CombineGVCFsIntegrationTest.java | 18 +- .../GenotypeGVCFsIntegrationTest.java | 16 +- .../variant/GATKVariantContextUtils.java | 2 +- .../GATKVariantContextUtilsUnitTest.java | 29 +++ 18 files changed, 631 insertions(+), 180 deletions(-) create mode 100644 protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/FixedAFCalculatorProviderUnitTest.java create mode 100644 protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyFailOverAFCalculatorProviderUnitTest.java create mode 100644 protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/AFPriorProviderUnitTest.java diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java index 4895ab303..266a7abe0 100644 --- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java +++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java @@ -60,6 +60,7 @@ import htsjdk.variant.variantcontext.Allele; import htsjdk.variant.variantcontext.Genotype; import htsjdk.variant.variantcontext.VariantContext; import htsjdk.variant.variantcontext.VariantContextBuilder; +import org.broadinstitute.gatk.utils.variant.HomoSapiensConstants; import java.io.*; import java.util.*; @@ -106,7 +107,7 @@ public class AFCalcPerformanceTest { final VariantContext vc = testBuilder.makeACTest(ACs, 0, nonTypePL); timer.start(); - final AFCalcResult resultTracker = calc.getLog10PNonRef(vc, priors); + final AFCalcResult resultTracker = calc.getLog10PNonRef(vc, HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles, priors); final long runtime = timer.getElapsedTimeNano(); int otherAC = 0; @@ -172,7 +173,7 @@ public class AFCalcPerformanceTest { vcb.genotypes(genotypes); timer.start(); - final AFCalcResult resultTracker = calc.getLog10PNonRef(vcb.make(), priors); + final AFCalcResult resultTracker = calc.getLog10PNonRef(vcb.make(), HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles, priors); final long runtime = timer.getElapsedTimeNano(); final List columns = new LinkedList(coreValues); @@ -202,7 +203,7 @@ public class AFCalcPerformanceTest { final VariantContext vc = testBuilder.makeACTest(ac, nNonInformative, nonTypePL); timer.start(); - final AFCalcResult resultTracker = calc.getLog10PNonRef(vc, priors); + final AFCalcResult resultTracker = calc.getLog10PNonRef(vc, HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles, priors); final long runtime = timer.getElapsedTimeNano(); final List columns = new LinkedList(coreValues); @@ -214,10 +215,10 @@ public class AFCalcPerformanceTest { } private static class ModelParams { - final AFCalcFactory.Calculation modelType; + final AFCalculatorImplementation modelType; final int maxBiNSamples, maxTriNSamples; - private ModelParams(AFCalcFactory.Calculation modelType, int maxBiNSamples, int maxTriNSamples) { + private ModelParams(AFCalculatorImplementation modelType, int maxBiNSamples, int maxTriNSamples) { this.modelType = modelType; this.maxBiNSamples = maxBiNSamples; this.maxTriNSamples = maxTriNSamples; @@ -238,6 +239,7 @@ public class AFCalcPerformanceTest { SINGLE, EXACT_LOG } + public static void main(final String[] args) throws Exception { final TTCCLayout layout = new TTCCLayout(); layout.setThreadPrinting(false); @@ -270,11 +272,11 @@ public class AFCalcPerformanceTest { for ( final ExactCallLogger.ExactCall call : loggedCalls ) { final AFCalcTestBuilder testBuilder = new AFCalcTestBuilder(call.vc.getNSamples(), 1, - AFCalcFactory.Calculation.EXACT_INDEPENDENT, + AFCalculatorImplementation.EXACT_INDEPENDENT, AFCalcTestBuilder.PriorType.human); logger.info(call); final SimpleTimer timer = new SimpleTimer().start(); - final AFCalcResult result = testBuilder.makeModel().getLog10PNonRef(call.vc, testBuilder.makePriors()); + final AFCalcResult result = testBuilder.makeModel().getLog10PNonRef(call.vc, HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles,testBuilder.makePriors()); final long newNanoTime = timer.getElapsedTimeNano(); if ( call.originalCall.anyPolymorphic(-1) || result.anyPolymorphic(-1) ) { logger.info("**** ONE IS POLY"); @@ -298,13 +300,13 @@ public class AFCalcPerformanceTest { final int ac = Integer.valueOf(args[2]); final AFCalcTestBuilder testBuilder = new AFCalcTestBuilder(nSamples, 1, - AFCalcFactory.Calculation.EXACT_INDEPENDENT, + AFCalculatorImplementation.EXACT_INDEPENDENT, AFCalcTestBuilder.PriorType.human); final VariantContext vc = testBuilder.makeACTest(new int[]{ac}, 0, 100); final SimpleTimer timer = new SimpleTimer().start(); - final AFCalcResult resultTracker = testBuilder.makeModel().getLog10PNonRef(vc, testBuilder.makePriors()); + final AFCalcResult resultTracker = testBuilder.makeModel().getLog10PNonRef(vc, HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles, testBuilder.makePriors()); final long runtime = timer.getElapsedTimeNano(); logger.info("result " + resultTracker.getLog10PosteriorOfAFGT0()); logger.info("runtime " + runtime); @@ -317,9 +319,9 @@ public class AFCalcPerformanceTest { final PrintStream out = new PrintStream(new FileOutputStream(args[1])); final List modelParams = Arrays.asList( - new ModelParams(AFCalcFactory.Calculation.EXACT_REFERENCE, 10000, 10), + new ModelParams(AFCalculatorImplementation.EXACT_REFERENCE, 10000, 10), // new ModelParams(AFCalcTestBuilder.ModelType.GeneralExact, 100, 10), - new ModelParams(AFCalcFactory.Calculation.EXACT_INDEPENDENT, 10000, 1000)); + new ModelParams(AFCalculatorImplementation.EXACT_INDEPENDENT, 10000, 1000)); final boolean ONLY_HUMAN_PRIORS = false; final List priorTypes = ONLY_HUMAN_PRIORS diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java index 77c30eb19..62cafb898 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperEngineUnitTest.java @@ -56,6 +56,7 @@ import htsjdk.variant.variantcontext.VariantContext; import htsjdk.variant.variantcontext.VariantContextBuilder; import org.broadinstitute.gatk.engine.GenomeAnalysisEngine; import org.broadinstitute.gatk.engine.arguments.GATKArgumentCollection; +import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.FixedAFCalculatorProvider; import org.broadinstitute.gatk.utils.BaseTest; import org.broadinstitute.gatk.utils.MathUtils; import org.broadinstitute.gatk.utils.Utils; @@ -78,7 +79,8 @@ public class UnifiedGenotyperEngineUnitTest extends BaseTest { final UnifiedArgumentCollection args = new UnifiedArgumentCollection(); final SampleList fakeSamples = SampleListUtils.singletonList("fake"); - ugEngine = new UnifiedGenotypingEngine(args,fakeSamples,engine.getGenomeLocParser(),engine.getArguments().BAQMode); + ugEngine = new UnifiedGenotypingEngine(args,fakeSamples,engine.getGenomeLocParser(), + new FixedAFCalculatorProvider(args,null,true),engine.getArguments().BAQMode); } private UnifiedGenotypingEngine getEngine() { diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java index 270d2c3c9..231e1512c 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java @@ -69,16 +69,16 @@ public class UnifiedGenotyperGeneralPloidySuite1IntegrationTest extends WalkerTe @Test(enabled = true) public void testBOTH_GGA_Pools() { - executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_BOTH_GGA", "BOTH", "39cccae4a26c64e09631e28f17db2792"); + executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_BOTH_GGA", "BOTH", "c731cd0ddb0fa153bffa7bc19586bfa6"); } @Test(enabled = true) public void testINDEL_GGA_Pools() { - executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 1 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_INDEL_GGA", "INDEL", "5e4013183ca26b0d7c48ea2ec147d9d7"); + executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 1 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_INDEL_GGA", "INDEL", "b6ed1729a25670d81aff61099fb13998"); } @Test(enabled = true) public void testINDEL_maxAltAlleles2_ploidy1_Pools_noRef() { - executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 1", "LSV_INDEL_DISC_NOREF_p1", "INDEL", "af69cf83a27d082d76b18fede7ac2699"); + executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 1", "LSV_INDEL_DISC_NOREF_p1", "INDEL", "54d718401c413fdbc1f801061bf8e7d1"); } } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java index 5326eb5b2..54282b05c 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java @@ -58,7 +58,7 @@ public class UnifiedGenotyperGeneralPloidySuite2IntegrationTest extends WalkerTe @Test(enabled = true) public void testINDEL_maxAltAlleles2_ploidy3_Pools_noRef() { - executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 3","LSV_INDEL_DISC_NOREF_p3","INDEL","68a2aa0b213fa5a53e925542e340fbe8"); + executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 3","LSV_INDEL_DISC_NOREF_p3","INDEL","1426e311501a7bd96ecb75ed839f7c64"); } @Test(enabled = true) diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperIndelCallingIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperIndelCallingIntegrationTest.java index c7b510301..c1d43f328 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperIndelCallingIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperIndelCallingIntegrationTest.java @@ -135,7 +135,7 @@ public class UnifiedGenotyperIndelCallingIntegrationTest extends WalkerTest { WalkerTest.WalkerTestSpec spec2 = new WalkerTest.WalkerTestSpec( baseCommandIndels + " --genotyping_mode GENOTYPE_GIVEN_ALLELES -alleles " + result.get(0).getAbsolutePath() + " -I " + validationDataLocation + "low_coverage_CEU.chr1.10k-11k.bam -o %s -L " + result.get(0).getAbsolutePath(), 1, - Arrays.asList("8084abd2460e934e483403aff76a3698")); + Arrays.asList("34a92dd832bbb8ed53abf21ba88c6faa")); executeTest("test MultiSample Pilot1 CEU indels using GENOTYPE_GIVEN_ALLELES", spec2); } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperNormalCallingIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperNormalCallingIntegrationTest.java index 7fb019f10..ae34ca172 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperNormalCallingIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperNormalCallingIntegrationTest.java @@ -65,7 +65,7 @@ public class UnifiedGenotyperNormalCallingIntegrationTest extends WalkerTest{ public void testMultiSamplePilot1() { WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec( baseCommand + " -I " + validationDataLocation + "low_coverage_CEU.chr1.10k-11k.bam -o %s -L 1:10,022,000-10,025,000", 1, - Arrays.asList("9824ea30340fd3632bad672fc6ade114")); + Arrays.asList("a15a28d854789c71ef2879dd4c606b1a")); executeTest("test MultiSample Pilot1", spec); } @@ -97,7 +97,7 @@ public class UnifiedGenotyperNormalCallingIntegrationTest extends WalkerTest{ public void testMultipleSNPAlleles() { WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec( "-T UnifiedGenotyper --contamination_fraction_to_filter 0.05 --disableDithering -R " + b37KGReference + " --no_cmdline_in_header -glm BOTH --dbsnp " + b37dbSNP129 + " -I " + privateTestDir + "multiallelic.snps.bam -o %s -L " + privateTestDir + "multiallelic.snps.intervals", 1, - Arrays.asList("2474c60302fc79f28bb0c721d305c09b")); + Arrays.asList("1a36b5c036e0452f526dc1a5fdd60929")); executeTest("test Multiple SNP alleles", spec); } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceUnitTest.java index bdbc475a6..4b56d16bb 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceUnitTest.java @@ -52,6 +52,7 @@ import org.broadinstitute.gatk.utils.Utils; import org.broadinstitute.gatk.utils.collections.Pair; import htsjdk.variant.variantcontext.Allele; import htsjdk.variant.variantcontext.VariantContext; +import org.broadinstitute.gatk.utils.variant.HomoSapiensConstants; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -66,12 +67,12 @@ public class AFCalcPerformanceUnitTest extends BaseTest { List tests = new ArrayList(); // list of all high-quality models in the system - final List biAllelicModels = Arrays.asList( - AFCalcFactory.Calculation.EXACT_INDEPENDENT, - AFCalcFactory.Calculation.EXACT_REFERENCE); + final List biAllelicModels = Arrays.asList( + AFCalculatorImplementation.EXACT_INDEPENDENT, + AFCalculatorImplementation.EXACT_REFERENCE); - final List multiAllelicModels = Arrays.asList( - AFCalcFactory.Calculation.EXACT_INDEPENDENT); + final List multiAllelicModels = Arrays.asList( + AFCalculatorImplementation.EXACT_INDEPENDENT); // for ( final int nonTypePLs : Arrays.asList(100) ) { // for ( final int nSamples : Arrays.asList(10000) ) { @@ -81,8 +82,8 @@ public class AFCalcPerformanceUnitTest extends BaseTest { for ( final int nSamples : Arrays.asList(100, 1000) ) { final List alleleCounts = Arrays.asList(0, 1, 2, 3, 4, 5, 10, 50, 500); for ( final int nAltAlleles : Arrays.asList(1, 2, 3) ) { - final List models = nAltAlleles > 1 ? multiAllelicModels : biAllelicModels; - for ( final AFCalcFactory.Calculation model : models ) { + final List models = nAltAlleles > 1 ? multiAllelicModels : biAllelicModels; + for ( final AFCalculatorImplementation model : models ) { for ( final List ACs : Utils.makePermutations(alleleCounts, nAltAlleles, true) ) { if ( MathUtils.sum(ACs) < nSamples * 2 ) { final AFCalcTestBuilder testBuilder @@ -118,7 +119,7 @@ public class AFCalcPerformanceUnitTest extends BaseTest { final AFCalc calc = testBuilder.makeModel(); final double[] priors = testBuilder.makePriors(); final VariantContext vc = testBuilder.makeACTest(ACs, 0, nonTypePL); - final AFCalcResult result = calc.getLog10PNonRef(vc, priors); + final AFCalcResult result = calc.getLog10PNonRef(vc, HomoSapiensConstants.DEFAULT_PLOIDY, testBuilder.numAltAlleles, priors); final Pair expectedNEvaluation = estNumberOfEvaluations(testBuilder, vc, nonTypePL); final int minEvals = expectedNEvaluation.getFirst(); final int maxEvals = expectedNEvaluation.getSecond(); diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcUnitTest.java index 0bbc0ecfa..3052921ec 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcUnitTest.java @@ -46,13 +46,14 @@ package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc; +import htsjdk.variant.variantcontext.*; import org.apache.commons.lang.ArrayUtils; -import org.broadinstitute.gatk.utils.BaseTest; import org.broadinstitute.gatk.tools.walkers.genotyper.UnifiedGenotypingEngine; +import org.broadinstitute.gatk.utils.BaseTest; import org.broadinstitute.gatk.utils.MathUtils; import org.broadinstitute.gatk.utils.QualityUtils; import org.broadinstitute.gatk.utils.Utils; -import htsjdk.variant.variantcontext.*; +import org.broadinstitute.gatk.utils.variant.HomoSapiensConstants; import org.testng.Assert; import org.testng.annotations.BeforeSuite; import org.testng.annotations.DataProvider; @@ -76,6 +77,19 @@ public class AFCalcUnitTest extends BaseTest { final private static boolean Guillermo_FIXME = false; // TODO -- can only be enabled when GdA fixes bug final private static boolean DEBUG_ONLY = false; + protected static List createAFCalculators(final List calcs, final int maxAltAlleles, final int ploidy) { + final List AFCalcs = new LinkedList<>(); + + for ( final AFCalculatorImplementation calc : calcs ) { + if (calc.usableForParams(ploidy,maxAltAlleles)) + AFCalcs.add(calc.newInstance()); + else + throw new IllegalStateException("cannot use " + calc + " calculator instance with combination " + maxAltAlleles + " " + ploidy); + } + + return AFCalcs; + } + @BeforeSuite public void before() { AA1 = makePL(Arrays.asList(A, A), 0, 20, 20); @@ -109,7 +123,7 @@ public class AFCalcUnitTest extends BaseTest { private GetGLsTest(final AFCalc calc, int numAltAlleles, List arg, final double[] priors, final String priorName) { super(GetGLsTest.class); - GLs = GenotypesContext.create(new ArrayList(arg)); + GLs = GenotypesContext.create(new ArrayList<>(arg)); this.numAltAlleles = numAltAlleles; this.calc = calc; this.priors = priors; @@ -126,12 +140,12 @@ public class AFCalcUnitTest extends BaseTest { } public AFCalcResult execute() { - return getCalc().getLog10PNonRef(getVC(), getPriors()); + return getCalc().getLog10PNonRef(getVC(), HomoSapiensConstants.DEFAULT_PLOIDY, numAltAlleles, getPriors()); } public AFCalcResult executeRef() { - final AFCalc ref = AFCalcFactory.createAFCalc(AFCalcFactory.Calculation.EXACT_REFERENCE, getCalc().nSamples, getCalc().getMaxAltAlleles()); - return ref.getLog10PNonRef(getVC(), getPriors()); + final AFCalc ref = AFCalculatorImplementation.EXACT_REFERENCE.newInstance(); + return ref.getLog10PNonRef(getVC(), HomoSapiensConstants.DEFAULT_PLOIDY, numAltAlleles, getPriors()); } public double[] getPriors() { @@ -165,13 +179,18 @@ public class AFCalcUnitTest extends BaseTest { } } + + private static final int MAX_ALT_ALLELES = 2; + private static final int PLOIDY = 2; + + @DataProvider(name = "wellFormedGLs") public Object[][] createSimpleGLsData() { final List biAllelicSamples = Arrays.asList(AA1, AB1, BB1); final List triAllelicSamples = Arrays.asList(AA2, AB2, BB2, AC2, BC2, CC2); for ( final int nSamples : Arrays.asList(1, 2, 3, 4) ) { - List calcs = AFCalcFactory.createAFCalcs( Arrays.asList( AFCalcFactory.Calculation.values() ), 4, 2, 2); + List calcs = createAFCalculators(Arrays.asList(AFCalculatorImplementation.values()), MAX_ALT_ALLELES, PLOIDY); final int nPriorValues = 2*nSamples+1; final double[] flatPriors = MathUtils.normalizeFromLog10(new double[nPriorValues], true); // flat priors @@ -261,12 +280,12 @@ public class AFCalcUnitTest extends BaseTest { samples.addAll(Collections.nCopies(nNonInformative, testData.nonInformative)); final int nSamples = samples.size(); - List calcs = AFCalcFactory.createAFCalcs(Arrays.asList(AFCalcFactory.Calculation.values()), 4, 2, 2); + List calcs = createAFCalculators(Arrays.asList(AFCalculatorImplementation.values()), MAX_ALT_ALLELES, PLOIDY); final double[] priors = MathUtils.normalizeFromLog10(new double[2*nSamples+1], true); // flat priors for ( AFCalc model : calcs ) { - if ( testData.nAltAlleles > 1 && model instanceof OriginalDiploidExactAFCalc ) + if ( testData.nAltAlleles > 1 && model instanceof OriginalDiploidExactAFCalc) continue; final GetGLsTest onlyInformative = new GetGLsTest(model, testData.nAltAlleles, testData.called, priors, "flat"); @@ -289,15 +308,18 @@ public class AFCalcUnitTest extends BaseTest { final AFCalcResult actual = withNonInformative.execute(); testResultSimple(withNonInformative); - compareAFCalcResults(actual, expected, onlyInformative.getCalc(), true); + compareAFCalcResults(actual, expected, onlyInformative.getCalc(), onlyInformative.numAltAlleles, true); } private void testResultSimple(final GetGLsTest cfg) { final AFCalcResult refResultTracker = cfg.executeRef(); final AFCalcResult resultTracker = cfg.execute(); - - compareAFCalcResults(resultTracker, refResultTracker, cfg.getCalc(), true); - + try { + compareAFCalcResults(resultTracker, refResultTracker, cfg.getCalc(), cfg.numAltAlleles, true); + } catch (Throwable t) { + cfg.execute(); + throw new RuntimeException(t); + } Assert.assertNotNull(resultTracker.getAllelesUsedInGenotyping()); Assert.assertTrue(cfg.getAlleles().containsAll(resultTracker.getAllelesUsedInGenotyping()), "Result object has alleles not in our initial allele list"); @@ -310,9 +332,9 @@ public class AFCalcUnitTest extends BaseTest { } } - private void compareAFCalcResults(final AFCalcResult actual, final AFCalcResult expected, final AFCalc calc, final boolean onlyPosteriorsShouldBeEqual) { + private void compareAFCalcResults(final AFCalcResult actual, final AFCalcResult expected, final AFCalc calc, final int maxAltAlleles, final boolean onlyPosteriorsShouldBeEqual) { // note we cannot really test the multi-allelic case because we actually meaningfully differ among the models here - final double TOLERANCE = calc.getMaxAltAlleles() > 1 ? 1000 : 0.1; // much tighter constraints on bi-allelic results + final double TOLERANCE = maxAltAlleles > 1 ? 1000 : 0.1; // much tighter constraints on bi-allelic results if ( ! onlyPosteriorsShouldBeEqual ) { Assert.assertEquals(actual.getLog10PriorOfAFEq0(), expected.getLog10PriorOfAFEq0(), TOLERANCE, "Priors AF == 0"); @@ -322,7 +344,7 @@ public class AFCalcUnitTest extends BaseTest { } Assert.assertEquals(actual.getLog10PosteriorOfAFEq0(), expected.getLog10PosteriorOfAFEq0(), TOLERANCE, "Posteriors AF == 0"); Assert.assertEquals(actual.getLog10PosteriorOfAFGT0(), expected.getLog10PosteriorOfAFGT0(), TOLERANCE, "Posteriors AF > 0"); - Assert.assertEquals(actual.getAlleleCountsOfMLE(), expected.getAlleleCountsOfMLE(), "MLE ACs"); + Assert.assertTrue(Arrays.equals(actual.getAlleleCountsOfMLE(), expected.getAlleleCountsOfMLE()), "MLE ACs "); Assert.assertEquals(actual.getAllelesUsedInGenotyping(), expected.getAllelesUsedInGenotyping(), "Alleles used in genotyping"); for ( final Allele a : expected.getAllelesUsedInGenotyping() ) { @@ -369,14 +391,14 @@ public class AFCalcUnitTest extends BaseTest { final Genotype g; final double pNonRef, tolerance; final boolean canScale; - final List badModels; + final List badModels; final VariantContext vc; private PNonRefData(final VariantContext vc, Genotype g, double pNonRef, double tolerance, final boolean canScale) { - this(vc, g, pNonRef, tolerance, canScale, Collections.emptyList()); + this(vc, g, pNonRef, tolerance, canScale, Collections.emptyList()); } - private PNonRefData(final VariantContext vc, Genotype g, double pNonRef, double tolerance, final boolean canScale, final List badModels) { + private PNonRefData(final VariantContext vc, Genotype g, double pNonRef, double tolerance, final boolean canScale, final List badModels) { this.g = g; this.pNonRef = pNonRef; this.tolerance = tolerance; @@ -433,7 +455,7 @@ public class AFCalcUnitTest extends BaseTest { new PNonRefData(vc3, makePL(GG, 10, 10, 10, 10, 10, 0), 0.9166667, TOLERANCE, false) ); - for ( AFCalcFactory.Calculation modelType : Arrays.asList(AFCalcFactory.Calculation.EXACT_REFERENCE, AFCalcFactory.Calculation.EXACT_INDEPENDENT) ) { + for ( AFCalculatorImplementation modelType : Arrays.asList(AFCalculatorImplementation.EXACT_REFERENCE, AFCalculatorImplementation.EXACT_INDEPENDENT) ) { for ( int nNonInformative = 0; nNonInformative < 3; nNonInformative++ ) { for ( final PNonRefData rootData : initialPNonRefData ) { for ( int plScale = 1; plScale <= 100000; plScale *= 10 ) { @@ -451,7 +473,7 @@ public class AFCalcUnitTest extends BaseTest { @Test(enabled = true && ! DEBUG_ONLY, dataProvider = "PNonRef") private void testPNonRef(final VariantContext vcRoot, - AFCalcFactory.Calculation modelType, + AFCalculatorImplementation modelType, AFCalcTestBuilder.PriorType priorType, final List genotypes, final double expectedPNonRef, @@ -463,7 +485,7 @@ public class AFCalcUnitTest extends BaseTest { final VariantContextBuilder vcb = new VariantContextBuilder(vcRoot); vcb.genotypes(genotypes); - final AFCalcResult resultTracker = testBuilder.makeModel().getLog10PNonRef(vcb.make(), testBuilder.makePriors()); + final AFCalcResult resultTracker = testBuilder.makeModel().getLog10PNonRef(vcb.make(), PLOIDY, MAX_ALT_ALLELES, testBuilder.makePriors()); Assert.assertEquals(resultTracker.getLog10PosteriorOfAFGT0(), Math.log10(expectedPNonRef), tolerance, "Actual pNonRef not within tolerance " + tolerance + " of expected"); @@ -476,12 +498,12 @@ public class AFCalcUnitTest extends BaseTest { final List bigNonRefPLs = Arrays.asList(0, 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 100, 1000); final List> bigDiploidPLs = removeBadPLs(Utils.makePermutations(bigNonRefPLs, 3, true)); - for ( AFCalcFactory.Calculation modelType : AFCalcFactory.Calculation.values() ) { + for ( AFCalculatorImplementation modelType : AFCalculatorImplementation.values() ) { if ( false ) { // for testing only tests.add(new Object[]{modelType, toGenotypes(Arrays.asList(Arrays.asList(0,100,0)))}); } else { - if ( modelType == AFCalcFactory.Calculation.EXACT_GENERAL_PLOIDY ) continue; // TODO -- GENERAL_PLOIDY DOESN'T WORK + if ( modelType == AFCalculatorImplementation.EXACT_GENERAL_PLOIDY ) continue; // TODO -- GENERAL_PLOIDY DOESN'T WORK // test all combinations of PLs for 1 sample for ( final List> PLsPerSample : Utils.makePermutations(bigDiploidPLs, 1, true) ) { @@ -539,16 +561,16 @@ public class AFCalcUnitTest extends BaseTest { } @Test(enabled = true && ! DEBUG_ONLY, dataProvider = "PNonRefBiallelicSystematic") - private void PNonRefBiallelicSystematic(AFCalcFactory.Calculation modelType, final List genotypes) { + private void PNonRefBiallelicSystematic(AFCalculatorImplementation modelType, final List genotypes) { //logger.warn("Running " + modelType + " with " + genotypes); - final AFCalcTestBuilder refBuilder = new AFCalcTestBuilder(genotypes.size(), 1, AFCalcFactory.Calculation.EXACT_REFERENCE, AFCalcTestBuilder.PriorType.human); + final AFCalcTestBuilder refBuilder = new AFCalcTestBuilder(genotypes.size(), 1, AFCalculatorImplementation.EXACT_REFERENCE, AFCalcTestBuilder.PriorType.human); final AFCalcTestBuilder testBuilder = new AFCalcTestBuilder(genotypes.size(), 1, modelType, AFCalcTestBuilder.PriorType.human); final VariantContextBuilder vcb = new VariantContextBuilder("x", "1", 1, 1, Arrays.asList(A, C)); vcb.genotypes(genotypes); - final AFCalcResult refResult = refBuilder.makeModel().getLog10PNonRef(vcb.make(), testBuilder.makePriors()); - final AFCalcResult testResult = testBuilder.makeModel().getLog10PNonRef(vcb.make(), testBuilder.makePriors()); + final AFCalcResult refResult = refBuilder.makeModel().getLog10PNonRef(vcb.make(), PLOIDY, MAX_ALT_ALLELES, testBuilder.makePriors()); + final AFCalcResult testResult = testBuilder.makeModel().getLog10PNonRef(vcb.make(), PLOIDY, MAX_ALT_ALLELES, testBuilder.makePriors()); final double tolerance = 1e-3; Assert.assertEquals(testResult.getLog10PosteriorOfAFGT0(), refResult.getLog10PosteriorOfAFGT0(), tolerance, @@ -567,9 +589,9 @@ public class AFCalcUnitTest extends BaseTest { public Object[][] makeModels() { List tests = new ArrayList(); - for ( final AFCalcFactory.Calculation calc : AFCalcFactory.Calculation.values() ) { + for ( final AFCalculatorImplementation calc : AFCalculatorImplementation.values() ) { if ( calc.usableForParams(2, 4) ) - tests.add(new Object[]{AFCalcFactory.createAFCalc(calc, 2, 4)}); + tests.add(new Object[]{AFCalcFactory.createCalculatorForDiploidAnalysis()}); } return tests.toArray(new Object[][]{}); @@ -656,14 +678,14 @@ public class AFCalcUnitTest extends BaseTest { List tests = new ArrayList(); // list of all high-quality models in the system - final List models = Arrays.asList( - AFCalcFactory.Calculation.getDefaultModel(), - AFCalcFactory.Calculation.EXACT_REFERENCE, - AFCalcFactory.Calculation.EXACT_INDEPENDENT); + final List models = Arrays.asList( + AFCalculatorImplementation.DEFAULT, + AFCalculatorImplementation.EXACT_REFERENCE, + AFCalculatorImplementation.EXACT_INDEPENDENT); // note that we cannot use small PLs here or the thresholds are hard to set for ( final int nonTypePLs : Arrays.asList(100, 1000) ) { - for ( final AFCalcFactory.Calculation model : models ) { + for ( final AFCalculatorImplementation model : models ) { for ( final int allele1AC : Arrays.asList(0, 1, 2, 10, 100, 1000, 10000) ) { for ( final int nSamples : Arrays.asList(1, 10, 100, 1000, 10000) ) { // for ( final int nonTypePLs : Arrays.asList(10) ) { @@ -713,13 +735,13 @@ public class AFCalcUnitTest extends BaseTest { List tests = new ArrayList(); // list of all high-quality models in the system - final List models = Arrays.asList(AFCalcFactory.Calculation.EXACT_INDEPENDENT); + final List models = Arrays.asList(AFCalculatorImplementation.EXACT_INDEPENDENT); final List alleleCounts = Arrays.asList(0, 1, 2, 3, 4, 5, 10, 20); final int nonTypePLs = 1000; final int nAlleles = 4; - for ( final AFCalcFactory.Calculation model : models ) { + for ( final AFCalculatorImplementation model : models ) { for ( final List ACs : Utils.makePermutations(alleleCounts, nAlleles, true) ) { final List isPoly = new ArrayList(ACs.size()); for ( final int ac : ACs ) isPoly.add(ac > 0); @@ -746,7 +768,7 @@ public class AFCalcUnitTest extends BaseTest { final AFCalc calc = testBuilder.makeModel(); final double[] priors = testBuilder.makePriors(); final VariantContext vc = testBuilder.makeACTest(ACs, 0, nonTypePL); - final AFCalcResult result = calc.getLog10PNonRef(vc, priors); + final AFCalcResult result = calc.getLog10PNonRef(vc, PLOIDY, testBuilder.numAltAlleles, priors); boolean anyPoly = false; for ( final boolean onePoly : expectedPoly ) anyPoly = anyPoly || onePoly; diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/FixedAFCalculatorProviderUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/FixedAFCalculatorProviderUnitTest.java new file mode 100644 index 000000000..086a617f6 --- /dev/null +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/FixedAFCalculatorProviderUnitTest.java @@ -0,0 +1,166 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ +package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc; + +import org.broadinstitute.gatk.engine.GenomeAnalysisEngine; +import org.broadinstitute.gatk.engine.arguments.GATKArgumentCollection; +import org.broadinstitute.gatk.engine.arguments.GenotypeCalculationArgumentCollection; +import org.broadinstitute.gatk.engine.arguments.StandardCallerArgumentCollection; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.*; + +/** + * Tests {@link org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.FixedAFCalculatorProvider} + * + * @author Valentin Ruano-Rubio <valentin@broadinstitute.org> + */ +public class FixedAFCalculatorProviderUnitTest { + + @Test(dataProvider="nonThreadSafeConstructorsData") + public void testNonThreadSafeConstructors(final int ploidy, final int maxAltAlleles, final AFCalculatorImplementation preferred) { + final GenotypeCalculationArgumentCollection args = new GenotypeCalculationArgumentCollection(); + args.MAX_ALTERNATE_ALLELES = maxAltAlleles; + args.samplePloidy = ploidy; + final StandardCallerArgumentCollection callerArgs = new StandardCallerArgumentCollection(); + if (preferred != null ) callerArgs.requestedAlleleFrequencyCalculationModel = preferred; + callerArgs.genotypeArgs = args; + final FixedAFCalculatorProvider providerCallerArgs = new FixedAFCalculatorProvider(callerArgs,null,true); + final FixedAFCalculatorProvider providerGenotypingArgs = new FixedAFCalculatorProvider(args,null,true); + + Assert.assertNotNull(providerCallerArgs.getInstance(ploidy,maxAltAlleles)); + Assert.assertTrue(AFCalculatorImplementation.fromCalculatorClass(providerCallerArgs.getInstance(ploidy,maxAltAlleles).getClass()).usableForParams(ploidy,maxAltAlleles)); + Assert.assertNotNull(providerGenotypingArgs.getInstance(ploidy,maxAltAlleles)); + Assert.assertTrue(AFCalculatorImplementation.fromCalculatorClass(providerGenotypingArgs.getInstance(ploidy,maxAltAlleles).getClass()).usableForParams(ploidy,maxAltAlleles)); + + if (preferred != null && preferred.usableForParams(ploidy,maxAltAlleles)) { + Assert.assertEquals(AFCalculatorImplementation.fromCalculatorClass(providerCallerArgs.getInstance(ploidy, maxAltAlleles).getClass()), preferred); + } + } + + @Test(dataProvider="threadSafeFactoryData") + public void testThreadSafeConstructors(final int ploidy, final int maxAltAlleles, final AFCalculatorImplementation impl, final int cpuThreadCount, final int dataThreadCount) { + final GenomeAnalysisEngine toolkit = new GenomeAnalysisEngine(); + final GATKArgumentCollection gatkArguments = new GATKArgumentCollection(); + gatkArguments.numberOfCPUThreadsPerDataThread =cpuThreadCount; + gatkArguments.numberOfDataThreads = dataThreadCount; + toolkit.setArguments(gatkArguments); + final StandardCallerArgumentCollection callerArgs = new StandardCallerArgumentCollection(); + if (impl != null) callerArgs.requestedAlleleFrequencyCalculationModel = impl; + final GenotypeCalculationArgumentCollection genotypeArgs = new GenotypeCalculationArgumentCollection(); + callerArgs.genotypeArgs = genotypeArgs; + genotypeArgs.samplePloidy = ploidy; + genotypeArgs.MAX_ALTERNATE_ALLELES = maxAltAlleles; + final AFCalculatorProvider provider = FixedAFCalculatorProvider.createThreadSafeProvider(toolkit,callerArgs,null); + final Hashtable perThreadProvider = new Hashtable(cpuThreadCount * dataThreadCount); + final List threads = new ArrayList<>(); + // execute different threads. + for (int i = 0; i < cpuThreadCount; i++) + for (int j = 0; j < cpuThreadCount; j++) { + final Thread thread = new Thread(new Runnable() { + @Override + public void run() { + synchronized (perThreadProvider) { + perThreadProvider.put(Thread.currentThread(), provider.getInstance(ploidy, maxAltAlleles)); + } + } + }); + thread.start(); + threads.add(thread); + } + // wait all threads to have finished. + for (final Thread thread : threads) + try { + thread.join(); + } catch (InterruptedException e) { + Assert.fail(); + } + // check that each thread gave a different calculator. + final Set calculators = new HashSet<>(perThreadProvider.values()); + Assert.assertEquals(calculators.size(),threads.size()); + } + + private final static int[] PLOIDIES = new int[] { 1,2,3,4,10 }; + private final static int[] MAX_ALT_ALLELES = new int[] { 1,2,3,4,10}; + private final static int[] CPU_THREAD_COUNT = new int[] { 1, 2, 3, 4, 10}; + private final static int[] DATA_THREAD_COUNT = new int[] { 1, 2, 3, 4, 10}; + + @DataProvider(name="nonThreadSafeConstructorsData") + public Object[][] nonThreadSafeConstructorsData() { + final Object[][] result = new Object[PLOIDIES.length * MAX_ALT_ALLELES.length * (AFCalculatorImplementation.values().length + 1)][]; + int idx = 0; + for (int i = 0; i < PLOIDIES.length; i++) { + for (int j = 0; j < MAX_ALT_ALLELES.length; j++) { + result[idx++] = new Object[] { PLOIDIES[i], MAX_ALT_ALLELES[j], null }; + for (final AFCalculatorImplementation impl : AFCalculatorImplementation.values()) { + result[idx++] = new Object[]{PLOIDIES[i], MAX_ALT_ALLELES[j], impl}; + } + } + } + return result; + } + + @DataProvider(name="threadSafeFactoryData") + public Object[][] threadSafeFactoryData() { + final Object[][] result = new Object[DATA_THREAD_COUNT.length * CPU_THREAD_COUNT.length * PLOIDIES.length * MAX_ALT_ALLELES.length * (AFCalculatorImplementation.values().length + 1)][]; + int idx = 0; + for (int i = 0; i < PLOIDIES.length; i++) { + for (int j = 0; j < MAX_ALT_ALLELES.length; j++) { + for (int k = 0; k < CPU_THREAD_COUNT.length; k++) { + for (int l = 0; l < DATA_THREAD_COUNT.length; l++) { + result[idx++] = new Object[]{PLOIDIES[i], MAX_ALT_ALLELES[j], null, CPU_THREAD_COUNT[k], DATA_THREAD_COUNT[l]}; + for (final AFCalculatorImplementation impl : AFCalculatorImplementation.values()) { + result[idx++] = new Object[]{PLOIDIES[i], MAX_ALT_ALLELES[j], impl, CPU_THREAD_COUNT[k], DATA_THREAD_COUNT[l]}; + } + } + } + } + } + return result; + } +} diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyAFCalculationModelUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyAFCalculationModelUnitTest.java index f2658a4c5..ca874e4c1 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyAFCalculationModelUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyAFCalculationModelUnitTest.java @@ -186,12 +186,13 @@ public class GeneralPloidyAFCalculationModelUnitTest extends BaseTest { final int len = GeneralPloidyGenotypeLikelihoods.getNumLikelihoodElements(1 + cfg.numAltAlleles, cfg.ploidy * cfg.GLs.size()); double[] priors = new double[len]; // flat priors - final GeneralPloidyExactAFCalc calc = new GeneralPloidyExactAFCalc(cfg.GLs.size(), 1 + cfg.numAltAlleles, cfg.ploidy); - calc.combineSinglePools(cfg.GLs, 1 + cfg.numAltAlleles, cfg.ploidy, priors); + final GeneralPloidyExactAFCalc calc = new GeneralPloidyExactAFCalc(); + calc.combineSinglePools(cfg.GLs, cfg.ploidy,cfg.numAltAlleles + 1, priors); int nameIndex = 1; + for ( int allele = 0; allele < cfg.numAltAlleles; allele++, nameIndex+=2 ) { - int expectedAlleleCount = Integer.valueOf(cfg.name.substring(nameIndex, nameIndex+1)); - int calculatedAlleleCount = calc.getStateTracker().getAlleleCountsOfMAP()[allele]; + int expectedAlleleCount = Integer.valueOf(cfg.name.substring(nameIndex, nameIndex + 1)); + int calculatedAlleleCount = calc.getAltAlleleCountOfMAP(allele); Assert.assertEquals(calculatedAlleleCount, expectedAlleleCount); } } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyFailOverAFCalculatorProviderUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyFailOverAFCalculatorProviderUnitTest.java new file mode 100644 index 000000000..b55312def --- /dev/null +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyFailOverAFCalculatorProviderUnitTest.java @@ -0,0 +1,162 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ +package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc; + +import org.broadinstitute.gatk.engine.GenomeAnalysisEngine; +import org.broadinstitute.gatk.engine.arguments.GATKArgumentCollection; +import org.broadinstitute.gatk.engine.arguments.GenotypeCalculationArgumentCollection; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.*; + +/** + * Tests {@link GeneralPloidyFailOverAFCalculatorProvider} + * + * @author Valentin Ruano-Rubio <valentin@broadinstitute.org> + */ +public class GeneralPloidyFailOverAFCalculatorProviderUnitTest { + + @Test(dataProvider="nonThreadSafeConstructorsData") + public void testNonThreadSafeConstructors(final int ploidy, final int maxAltAlleles) { + final GenotypeCalculationArgumentCollection args = new GenotypeCalculationArgumentCollection(); + args.MAX_ALTERNATE_ALLELES = maxAltAlleles; + args.samplePloidy = ploidy; + + final GeneralPloidyFailOverAFCalculatorProvider provider = new GeneralPloidyFailOverAFCalculatorProvider(args,null); + + final AFCalc calculator = provider.getInstance(ploidy,maxAltAlleles); + Assert.assertNotNull(calculator); + final AFCalculatorImplementation implementation = AFCalculatorImplementation.fromCalculatorClass(calculator.getClass()); + Assert.assertTrue(implementation.usableForParams(ploidy,maxAltAlleles)); + for (int i = 0; i < PLOIDIES.length; i++) { + for (int j = 0; j < MAX_ALT_ALLELES.length; j++) { + if (implementation.usableForParams(PLOIDIES[i],MAX_ALT_ALLELES[j])) + Assert.assertSame(provider.getInstance(PLOIDIES[i],MAX_ALT_ALLELES[j]),calculator); + else { + final AFCalc failOver = provider.getInstance(PLOIDIES[i],MAX_ALT_ALLELES[j]); + Assert.assertNotNull(failOver); + final AFCalculatorImplementation failOverImplementation = AFCalculatorImplementation.fromCalculatorClass(failOver.getClass()); + Assert.assertTrue(failOverImplementation.usableForParams(PLOIDIES[i],MAX_ALT_ALLELES[j])); + Assert.assertEquals(failOverImplementation, AFCalculatorImplementation.EXACT_GENERAL_PLOIDY); + } + } + } + } + + @Test(dataProvider="threadSafeFactoryData") + public void testThreadSafeConstructors(final int ploidy, final int maxAltAlleles, final int cpuThreadCount, final int dataThreadCount) { + final GenomeAnalysisEngine toolkit = new GenomeAnalysisEngine(); + final GATKArgumentCollection gatkArguments = new GATKArgumentCollection(); + gatkArguments.numberOfCPUThreadsPerDataThread =cpuThreadCount; + gatkArguments.numberOfDataThreads = dataThreadCount; + toolkit.setArguments(gatkArguments); + final GenotypeCalculationArgumentCollection genotypeArgs = new GenotypeCalculationArgumentCollection(); + genotypeArgs.samplePloidy = ploidy; + genotypeArgs.MAX_ALTERNATE_ALLELES = maxAltAlleles; + final AFCalculatorProvider provider = GeneralPloidyFailOverAFCalculatorProvider.createThreadSafeProvider(toolkit,genotypeArgs,null); + final Hashtable perThreadProvider = new Hashtable(cpuThreadCount * dataThreadCount); + final List threads = new ArrayList<>(); + // execute different threads. + for (int i = 0; i < cpuThreadCount; i++) + for (int j = 0; j < cpuThreadCount; j++) { + final Thread thread = new Thread(new Runnable() { + @Override + public void run() { + synchronized (perThreadProvider) { + perThreadProvider.put(Thread.currentThread(), provider.getInstance(ploidy, maxAltAlleles)); + } + } + }); + thread.start(); + threads.add(thread); + } + // wait all threads to have finished. + for (final Thread thread : threads) + try { + thread.join(); + } catch (InterruptedException e) { + Assert.fail(); + } + // check that each thread gave a different calculator. + final Set calculators = new HashSet<>(perThreadProvider.values()); + Assert.assertEquals(calculators.size(),threads.size()); + } + + private final static int[] PLOIDIES = new int[] { AFCalculatorImplementation.UNBOUND_PLOIDY,1,2,3,4,10 }; + private final static int[] MAX_ALT_ALLELES = new int[] { AFCalculatorImplementation.UNBOUND_ALTERNATIVE_ALLELE_COUNT,1,2,3,4,10}; + private final static int[] CPU_THREAD_COUNT = new int[] { 1, 2, 3, 4, 10}; + private final static int[] DATA_THREAD_COUNT = new int[] { 1, 2, 3, 4, 10}; + + @DataProvider(name="nonThreadSafeConstructorsData") + public Object[][] nonThreadSafeConstructorsData() { + final Object[][] result = new Object[PLOIDIES.length * MAX_ALT_ALLELES.length][]; + int idx = 0; + for (int i = 0; i < PLOIDIES.length; i++) { + for (int j = 0; j < MAX_ALT_ALLELES.length; j++) { + result[idx++] = new Object[] { PLOIDIES[i], MAX_ALT_ALLELES[j]}; + } + } + return result; + } + + @DataProvider(name="threadSafeFactoryData") + public Object[][] threadSafeFactoryData() { + final Object[][] result = new Object[DATA_THREAD_COUNT.length * CPU_THREAD_COUNT.length * PLOIDIES.length * MAX_ALT_ALLELES.length][]; + int idx = 0; + for (int i = 0; i < PLOIDIES.length; i++) { + for (int j = 0; j < MAX_ALT_ALLELES.length; j++) { + for (int k = 0; k < CPU_THREAD_COUNT.length; k++) { + for (int l = 0; l < DATA_THREAD_COUNT.length; l++) { + result[idx++] = new Object[]{PLOIDIES[i], MAX_ALT_ALLELES[j], CPU_THREAD_COUNT[k], DATA_THREAD_COUNT[l]}; + } + } + } + } + return result; + } +} diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/IndependentAllelesDiploidExactAFCalcUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/IndependentAllelesDiploidExactAFCalcUnitTest.java index 756b6dce3..8e2709abd 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/IndependentAllelesDiploidExactAFCalcUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/IndependentAllelesDiploidExactAFCalcUnitTest.java @@ -107,7 +107,7 @@ public class IndependentAllelesDiploidExactAFCalcUnitTest extends BaseTest { @Test(enabled = true, dataProvider = "TestCombineGLs") public void testCombineGLsPrecise(final int altIndex, final int nAlts, final Genotype testg, final Genotype expected) { - final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc)AFCalcFactory.createAFCalc(AFCalcFactory.Calculation.EXACT_INDEPENDENT, 1, 4); + final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc) AFCalculatorImplementation.EXACT_INDEPENDENT.newInstance(); final Genotype combined = calc.combineGLsPrecise(testg, altIndex, nAlts); Assert.assertEquals(combined.getPL(), expected.getPL(), @@ -116,7 +116,7 @@ public class IndependentAllelesDiploidExactAFCalcUnitTest extends BaseTest { @Test(enabled = true, dataProvider = "TestCombineGLs") public void testCombinePrecise(final int altIndex, final int nAlts, final Genotype testg, final Genotype expected) { - final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc)AFCalcFactory.createAFCalc(AFCalcFactory.Calculation.EXACT_INDEPENDENT, 1, 4); + final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc) AFCalculatorImplementation.EXACT_INDEPENDENT.newInstance(); final Genotype combined = calc.combineGLsPrecise(testg, altIndex, nAlts); Assert.assertEquals(combined.getPL(), expected.getPL(), @@ -156,7 +156,7 @@ public class IndependentAllelesDiploidExactAFCalcUnitTest extends BaseTest { @Test(enabled = true, dataProvider = "TestMakeAlleleConditionalContexts") private void testMakeAlleleConditionalContexts(final VariantContext vc, final List expectedVCs) { - final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc)AFCalcFactory.createAFCalc(AFCalcFactory.Calculation.EXACT_INDEPENDENT, 1, 4); + final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc) AFCalculatorImplementation.EXACT_INDEPENDENT.newInstance(); final List biAllelicVCs = calc.makeAlleleConditionalContexts(vc); Assert.assertEquals(biAllelicVCs.size(), expectedVCs.size()); @@ -207,7 +207,7 @@ public class IndependentAllelesDiploidExactAFCalcUnitTest extends BaseTest { pNonRefN.add(log10pNonRef*(i+1)); } - final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc)AFCalcFactory.createAFCalc(AFCalcFactory.Calculation.EXACT_INDEPENDENT, 1, 2); + final IndependentAllelesDiploidExactAFCalc calc = (IndependentAllelesDiploidExactAFCalc) AFCalculatorImplementation.EXACT_INDEPENDENT.newInstance(); final List thetaNPriors = calc.applyMultiAllelicPriors(originalPriors); double prevPosterior = 0.0; diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/AFPriorProviderUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/AFPriorProviderUnitTest.java new file mode 100644 index 000000000..97854e9e2 --- /dev/null +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/AFPriorProviderUnitTest.java @@ -0,0 +1,143 @@ +/* +* By downloading the PROGRAM you agree to the following terms of use: +* +* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY +* +* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE). +* +* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and +* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions. +* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows: +* +* 1. DEFINITIONS +* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE. +* +* 2. LICENSE +* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM. +* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement. +* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement. +* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM. +* +* 3. OWNERSHIP OF INTELLECTUAL PROPERTY +* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication. +* Copyright 2012 Broad Institute, Inc. +* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc. +* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes. +* +* 4. INDEMNIFICATION +* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement. +* +* 5. NO REPRESENTATIONS OR WARRANTIES +* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME. +* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING. +* +* 6. ASSIGNMENT +* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void. +* +* 7. MISCELLANEOUS +* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries. +* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes. +* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4. +* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt. +* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter. +* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement. +* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles. +*/ +package org.broadinstitute.gatk.tools.walkers.haplotypecaller; + +import org.broadinstitute.gatk.engine.GenomeAnalysisEngine; +import org.broadinstitute.gatk.tools.walkers.genotyper.AFPriorProvider; +import org.broadinstitute.gatk.tools.walkers.genotyper.CustomAFPriorProvider; +import org.broadinstitute.gatk.tools.walkers.genotyper.HeterozygosityAFPriorProvider; +import org.broadinstitute.gatk.utils.BaseTest; +import org.broadinstitute.gatk.utils.MathUtils; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * TODO document this. + * + * @author Valentin Ruano-Rubio <valentin@broadinstitute.org> + */ +public class AFPriorProviderUnitTest extends BaseTest { + + private static final double TOLERANCE = 0.0001; + + @Test(dataProvider="HeterozygosityProviderData") + public void testHeterozygosityProvider(final double h, final int useCount, final int minPloidy, final int maxPloidy) { + final double het = h / maxPloidy; + final Random rdn = GenomeAnalysisEngine.getRandomGenerator(); + final int[] plodies = new int[useCount]; + for (int i = 0; i < useCount; i++) + plodies[i] = rdn.nextInt(maxPloidy - minPloidy + 1) + minPloidy; + + final AFPriorProvider provider = new HeterozygosityAFPriorProvider(het); + for (int i = 0; i < useCount; i++) { + final int ploidy = plodies[i]; + double[] priors = provider.forTotalPloidy(ploidy); + Assert.assertNotNull(priors); + Assert.assertEquals(priors.length, ploidy + 1); + Assert.assertEquals(MathUtils.approximateLog10SumLog10(priors),0,TOLERANCE); + for (int j = 0; j < priors.length; j++) { + Assert.assertTrue(!Double.isNaN(priors[j])); + Assert.assertTrue(priors[j] < 0); + if (j > 0) Assert.assertEquals(priors[j], Math.log10(het) - Math.log10(j)); + } + } + } + + @Test(dataProvider="CustomProviderData") + public void testCustomProvider(final int ploidy) { + final double[] priors = new double[ploidy]; + final Random rdn = GenomeAnalysisEngine.getRandomGenerator(); + double remaining = 1; + final List priorsList = new ArrayList(); + for (int i = 0; i < priors.length; i++) { + priors[i] = remaining * rdn.nextDouble() * (.1 / ploidy ); + remaining -= priors[i]; + priorsList.add(priors[i]); + } + + final AFPriorProvider provider = new CustomAFPriorProvider(priorsList); + + final double[] providedPriors = provider.forTotalPloidy(ploidy); + Assert.assertNotNull(providedPriors); + Assert.assertEquals(providedPriors.length, priors.length + 1); + for (int i = 0; i < priors.length; i++) + Assert.assertEquals(providedPriors[i+1],Math.log10(priors[i]),TOLERANCE); + Assert.assertEquals(MathUtils.approximateLog10SumLog10(providedPriors),0,TOLERANCE); + } + + + private double[] hets = new double[] { 0.00001, 0.001, 0.1, 0.5, 0.99, 0.999 }; + private int[] useCounts = new int[] { 10, 100, 1000 }; + + private int[] ploidy = new int[] { 1 , 2, 3, 10, 100, 200, 500}; + + @DataProvider(name="CustomProviderData") + public Object[][] customProviderData() { + final Object[][] result = new Object[ploidy.length][]; + for (int i = 0; i < result.length; i++) + result[i] = new Object[] { ploidy[i] }; + return result; + } + + @DataProvider(name="HeterozygosityProviderData") + public Object[][] heterozygosityProviderData() { + final Object[][] result = new Object[hets.length * useCounts.length * ((ploidy.length + 1) * (ploidy.length) / 2)][]; + int idx = 0; + for (double h : hets) + for (int sc : useCounts) + for (int i = 0; i < ploidy.length; i++) + for (int j = i; j < ploidy.length; j++) + result[idx++] = new Object[] { h, sc, ploidy[i], ploidy[j]}; + return result; + } + + +} diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java index e4e189611..456dddb7d 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java @@ -91,107 +91,6 @@ public class HaplotypeCallerGenotypingEngineUnitTest extends BaseTest { genomeLocParser = new GenomeLocParser(seq); } - @Test - public void testFindHomVarEventAllelesInSample() { - final List eventAlleles = new ArrayList(); - eventAlleles.add( Allele.create("A", true) ); - eventAlleles.add( Allele.create("C", false) ); - final List haplotypeAlleles = new ArrayList(); - haplotypeAlleles.add( Allele.create("AATA", true) ); - haplotypeAlleles.add( Allele.create("AACA", false) ); - haplotypeAlleles.add( Allele.create("CATA", false) ); - haplotypeAlleles.add( Allele.create("CACA", false) ); - final List haplotypes = new ArrayList(); - haplotypes.add(new Haplotype("AATA".getBytes())); - haplotypes.add(new Haplotype("AACA".getBytes())); - haplotypes.add(new Haplotype("CATA".getBytes())); - haplotypes.add(new Haplotype("CACA".getBytes())); - final List haplotypeAllelesForSample = new ArrayList(); - haplotypeAllelesForSample.add( Allele.create("CATA", false) ); - haplotypeAllelesForSample.add( Allele.create("CACA", false) ); - final List> alleleMapper = new ArrayList>(); - List Aallele = new ArrayList(); - Aallele.add(haplotypes.get(0)); - Aallele.add(haplotypes.get(1)); - List Callele = new ArrayList(); - Callele.add(haplotypes.get(2)); - Callele.add(haplotypes.get(3)); - alleleMapper.add(Aallele); - alleleMapper.add(Callele); - final List eventAllelesForSample = new ArrayList(); - eventAllelesForSample.add( Allele.create("C", false) ); - eventAllelesForSample.add( Allele.create("C", false) ); - - if(!compareAlleleLists(eventAllelesForSample, HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes))) { - logger.warn("calc alleles = " + HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes)); - logger.warn("expected alleles = " + eventAllelesForSample); - } - Assert.assertTrue(compareAlleleLists(eventAllelesForSample, HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes))); - } - - @Test - public void testFindHetEventAllelesInSample() { - final List eventAlleles = new ArrayList(); - eventAlleles.add( Allele.create("A", true) ); - eventAlleles.add( Allele.create("C", false) ); - eventAlleles.add( Allele.create("T", false) ); - final List haplotypeAlleles = new ArrayList(); - haplotypeAlleles.add( Allele.create("AATA", true) ); - haplotypeAlleles.add( Allele.create("AACA", false) ); - haplotypeAlleles.add( Allele.create("CATA", false) ); - haplotypeAlleles.add( Allele.create("CACA", false) ); - haplotypeAlleles.add( Allele.create("TACA", false) ); - haplotypeAlleles.add( Allele.create("TTCA", false) ); - haplotypeAlleles.add( Allele.create("TTTA", false) ); - final List haplotypes = new ArrayList(); - haplotypes.add(new Haplotype("AATA".getBytes())); - haplotypes.add(new Haplotype("AACA".getBytes())); - haplotypes.add(new Haplotype("CATA".getBytes())); - haplotypes.add(new Haplotype("CACA".getBytes())); - haplotypes.add(new Haplotype("TACA".getBytes())); - haplotypes.add(new Haplotype("TTCA".getBytes())); - haplotypes.add(new Haplotype("TTTA".getBytes())); - final List haplotypeAllelesForSample = new ArrayList(); - haplotypeAllelesForSample.add( Allele.create("TTTA", false) ); - haplotypeAllelesForSample.add( Allele.create("AATA", true) ); - final List> alleleMapper = new ArrayList>(); - List Aallele = new ArrayList(); - Aallele.add(haplotypes.get(0)); - Aallele.add(haplotypes.get(1)); - List Callele = new ArrayList(); - Callele.add(haplotypes.get(2)); - Callele.add(haplotypes.get(3)); - List Tallele = new ArrayList(); - Tallele.add(haplotypes.get(4)); - Tallele.add(haplotypes.get(5)); - Tallele.add(haplotypes.get(6)); - alleleMapper.add(Aallele); - alleleMapper.add(Callele); - alleleMapper.add(Tallele); - final List eventAllelesForSample = new ArrayList(); - eventAllelesForSample.add( Allele.create("A", true) ); - eventAllelesForSample.add( Allele.create("T", false) ); - - if(!compareAlleleLists(eventAllelesForSample, HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes))) { - logger.warn("calc alleles = " + HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes)); - logger.warn("expected alleles = " + eventAllelesForSample); - } - Assert.assertTrue(compareAlleleLists(eventAllelesForSample, HaplotypeCallerGenotypingEngine.findEventAllelesInSample(eventAlleles, haplotypeAlleles, haplotypeAllelesForSample, alleleMapper, haplotypes))); - } - - private boolean compareAlleleLists(List l1, List l2) { - if( l1.size() != l2.size() ) { - return false; // sanity check - } - - for( int i=0; i < l1.size(); i++ ){ - if ( !l2.contains(l1.get(i)) ) - return false; - } - return true; - } - - private class BasicGenotypingTestProvider extends TestDataProvider { byte[] ref; byte[] hap; diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFsIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFsIntegrationTest.java index e540185ee..16b15544c 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFsIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/CombineGVCFsIntegrationTest.java @@ -90,12 +90,24 @@ public class CombineGVCFsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testTetraploidRun() { WalkerTestSpec spec = new WalkerTestSpec( - baseTestString(" -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" + + "-T CombineGVCFs -R " + b37KGReference + " -o %s --no_cmdline_in_header -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" + " -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" + " -V:sample3 " + privateTestDir + "tetraploid-gvcf-3.vcf" + - " -L " + privateTestDir + "tetraploid-gvcfs.intervals"), + " -L " + privateTestDir + "tetraploid-gvcfs.intervals", 1, - Arrays.asList("41de0808e029ebefd8b28d31ce10109c")); + Arrays.asList("20f55be01d01bed48bf66f354fa72e5b")); + executeTest("combineSingleSamplePipelineGVCF", spec); + } + + @Test(enabled= true) + public void testMixedPloidyRun() { + WalkerTestSpec spec = new WalkerTestSpec( + "-T CombineGVCFs -R " + b37KGReference + " -o %s --no_cmdline_in_header -V:sample1 " + privateTestDir + "haploid-gvcf-1.vcf" + + " -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" + + " -V:sample3 " + privateTestDir + "diploid-gvcf-3.vcf" + + " -L " + privateTestDir + "tetraploid-gvcfs.intervals", + 1, + Arrays.asList("c8bf3da5eb641d0082bdd5f12ea58e1e")); executeTest("combineSingleSamplePipelineGVCF", spec); } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java index 6424b9ae1..f0a0f669e 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFsIntegrationTest.java @@ -85,7 +85,7 @@ public class GenotypeGVCFsIntegrationTest extends WalkerTest { @Test(enabled = true) public void testTetraploidRun() { WalkerTestSpec spec = new WalkerTestSpec( - baseTestString(" -ploidy 4 -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" + + baseTestString(" -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" + " -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" + " -V:sample3 " + privateTestDir + "tetraploid-gvcf-3.vcf" + " -L " + privateTestDir + "tetraploid-gvcfs.intervals", b37KGReference), @@ -94,6 +94,18 @@ public class GenotypeGVCFsIntegrationTest extends WalkerTest { executeTest("combineSingleSamplePipelineGVCF", spec); } + @Test(enabled= true) + public void testMixedPloidyRun() { + WalkerTestSpec spec = new WalkerTestSpec( + baseTestString(" -V:sample1 " + privateTestDir + "haploid-gvcf-1.vcf" + + " -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" + + " -V:sample3 " + privateTestDir + "diploid-gvcf-3.vcf" + + " -L " + privateTestDir + "tetraploid-gvcfs.intervals", b37KGReference), + 1, + Arrays.asList("0ad7d784a15ad7f8b386ec7ca34032af")); + executeTest("combineSingleSamplePipelineGVCF", spec); + } + @Test(enabled = true) public void combineSingleSamplePipelineGVCF_includeNonVariants() { WalkerTestSpec spec = new WalkerTestSpec( @@ -148,7 +160,7 @@ public class GenotypeGVCFsIntegrationTest extends WalkerTest { " -V " + privateTestDir + "gvcfExample1.vcf" + " -V " + privateTestDir + "gvcfExample2.vcf", 1, - Arrays.asList("81c4cc8a6b72c24598ee899df838f1e8")); + Arrays.asList("ec63a629cc707554d3dd2ba7254b3b8d")); executeTest("testSamplesWithDifferentLs", spec); } diff --git a/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtils.java b/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtils.java index 3a9f1ac8a..f818d8d33 100644 --- a/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtils.java +++ b/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtils.java @@ -164,7 +164,7 @@ public class GATKVariantContextUtils { int result = 0; for (final Genotype genotype : vc.getGenotypes()) { final int declaredPloidy = genotype.getPloidy(); - result += declaredPloidy <= 0 ? declaredPloidy : declaredPloidy; + result += declaredPloidy <= 0 ? defaultPloidy : declaredPloidy; } return result; diff --git a/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtilsUnitTest.java b/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtilsUnitTest.java index 13de6b4ed..feb10a7d4 100644 --- a/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtilsUnitTest.java +++ b/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/variant/GATKVariantContextUtilsUnitTest.java @@ -1573,6 +1573,35 @@ public class GATKVariantContextUtilsUnitTest extends BaseTest { locs[nextIndex++] = GenomeLoc.UNMAPPED; } + @Test(dataProvider = "totalPloidyData") + public void testTotalPloidy(final int[] ploidies, final int defaultPloidy, final int expected) { + final Genotype[] genotypes = new Genotype[ploidies.length]; + final List vcAlleles = Arrays.asList(Aref,C); + for (int i = 0; i < genotypes.length; i++) + genotypes[i] = new GenotypeBuilder().alleles(GATKVariantContextUtils.noCallAlleles(ploidies[i])).make(); + final VariantContext vc = new VariantContextBuilder().chr("seq1").genotypes(genotypes).alleles(vcAlleles).make(); + Assert.assertEquals(GATKVariantContextUtils.totalPloidy(vc,defaultPloidy),expected," " + defaultPloidy + " " + Arrays.toString(ploidies)); + } + + @DataProvider(name="totalPloidyData") + public Object[][] totalPloidyData() { + final Random rdn = GenomeAnalysisEngine.getRandomGenerator(); + final List resultList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + final int sampleCount = rdn.nextInt(10); + + int expected = 0; + final int defaultPloidy = rdn.nextInt(10) + 1; + final int[] plodies = new int[sampleCount]; + for (int j = 0; j < sampleCount; j++) { + plodies[j] = rdn.nextInt(10); + expected += plodies[j] == 0 ? defaultPloidy : plodies[j]; + } + resultList.add(new Object[] { plodies, defaultPloidy, expected }); + } + return resultList.toArray(new Object[100][]); + } + private byte[] randomBases(final int length, final boolean reference) { final byte[] bases = new byte[length]; bases[0] = (byte) (reference ? 'A' : 'C');