@BeforeMethod public void initializeAnyploidPLIndexToAlleleIndices() { GenotypeLikelihoods.anyploidPloidyToPLIndexToAlleleIndices.clear(); GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(1, 1); GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(2, 2); GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(2, 3); }
@Test(dataProvider = "testInitializeAnyploidPLIndexToAlleleIndiceseBadData", expectedExceptions = IllegalArgumentException.class) public void testInitializeAnyploidPLIndexToAlleleIndicesBadData(final int altAlleles, final int ploidy) { GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(altAlleles, ploidy); }
@Test(enabled = !DEBUG, dataProvider = "UpdateGenotypeAfterSubsettingData") public void testUpdateGenotypeAfterSubsetting(final int ploidy, final GATKVariantContextUtils.GenotypeAssignmentMethod mode, final double[] likelihoods, final List<Allele> originalGT, final List<Allele> allelesToUse, final List<Allele> expectedAlleles) { final int numAltAlleles = originalGT.size() > 1 ? originalGT.size() - 1 : 1; GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(numAltAlleles, ploidy); final GenotypeBuilder gb = new GenotypeBuilder("test"); final double[] log10Likelhoods = MathUtils.normalizeFromLog10(likelihoods, true, false); GATKVariantContextUtils.updateGenotypeAfterSubsetting(originalGT, ploidy, gb, mode, log10Likelhoods, allelesToUse); final Genotype g = gb.make(); Assert.assertEquals(new HashSet<>(g.getAlleles()), new HashSet<>(expectedAlleles)); }
@Test(dataProvider = "SubsetAllelesData") public void testSubsetAlleles(final VariantContext inputVC, final List<Allele> allelesToUse, final List<Genotype> expectedGenotypes) { // initialize cache of allele anyploid indices for (final Genotype genotype : inputVC.getGenotypes()) { GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(inputVC.getNAlleles() - 1, genotype.getPloidy()); } final GenotypesContext actual = GATKVariantContextUtils.subsetAlleles(inputVC, allelesToUse, GATKVariantContextUtils.GenotypeAssignmentMethod.USE_PLS_TO_ASSIGN); Assert.assertEquals(actual.size(), expectedGenotypes.size()); for ( final Genotype expected : expectedGenotypes ) { final Genotype actualGT = actual.get(expected.getSampleName()); Assert.assertNotNull(actualGT); assertGenotypesAreEqual(actualGT, expected); } }
@Test(dataProvider = "updatePLsSACsAndADData") public void testUpdatePLsAndADData(final VariantContext originalVC, final VariantContext selectedVC, final List<Genotype> expectedGenotypes) { // initialize cache of allele anyploid indices for (final Genotype genotype : originalVC.getGenotypes()) { GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(originalVC.getNAlleles() - 1, genotype.getPloidy()); } final VariantContext selectedVCwithGTs = new VariantContextBuilder(selectedVC).genotypes(originalVC.getGenotypes()).make(); final GenotypesContext actual = GATKVariantContextUtils.updatePLsSACsAD(selectedVCwithGTs, originalVC); Assert.assertEquals(actual.size(), expectedGenotypes.size()); for ( final Genotype expected : expectedGenotypes ) { final Genotype actualGT = actual.get(expected.getSampleName()); Assert.assertNotNull(actualGT); assertGenotypesAreEqual(actualGT, expected); } }
if (g.getPloidy() != 0) { if (!ploidyToNumberOfAlleles.containsKey(g.getPloidy()) || ploidyToNumberOfAlleles.get(g.getPloidy()) < vc.getNAlleles()) { GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(vc.getNAlleles() - 1, g.getPloidy()); ploidyToNumberOfAlleles.put(g.getPloidy(), vc.getNAlleles());
@Test(dataProvider = "updatePLsAndADData") public void testUpdatePLsAndADData(final VariantContext originalVC, final VariantContext selectedVC, final List<Genotype> expectedGenotypes) { // initialize cache of allele anyploid indices for (final Genotype genotype : originalVC.getGenotypes()) { GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(originalVC.getNAlleles() - 1, genotype.getPloidy()); } final VariantContext selectedVCwithGTs = new VariantContextBuilder(selectedVC).genotypes(originalVC.getGenotypes()).make(); final GenotypesContext oldGs = selectedVCwithGTs.getGenotypes(); final GenotypesContext actual = selectedVCwithGTs.getNAlleles() == originalVC.getNAlleles() ? oldGs : AlleleSubsettingUtils.subsetAlleles(oldGs, originalVC.getAlleles(), selectedVCwithGTs.getAlleles()); Assert.assertEquals(actual.size(), expectedGenotypes.size()); for (final Genotype expected : expectedGenotypes) { final Genotype actualGT = actual.get(expected.getSampleName()); Assert.assertNotNull(actualGT); Assert.assertTrue(actualGT.sameGenotype(expected), String.format("expected same genotypes, found: %s and expected: %s", actual.toString(), expected.toString())); } }