public Genotype getGenotype(int ith) { return genotypes.get(ith); }
public static void assertEquals(final GenotypesContext actual, final GenotypesContext expected) { if (expected == null) { Assert.assertNull(actual); return; } Assert.assertEquals(actual.getSampleNamesOrderedByName(), expected.getSampleNamesOrderedByName(), "Sample names differ"); for (final String name : expected.getSampleNamesOrderedByName()) { Assert.assertEquals(actual.get(name).getAlleles(), expected.get(name).getAlleles(), "Alleles differ for sample " + name); Assert.assertEquals(actual.get(name).getAD(), expected.get(name).getAD()); Assert.assertEquals(actual.get(name).getPL(), expected.get(name).getPL()); } }
@Override public Genotype next() { return get(sampleNamesInOrder.next()); }
@Override public Genotype next() { return get(sampleNamesInOrder.next()); }
@Override public Genotype next() { return get(sampleNamesInOrder.next()); }
/** * @param ith the sample index * * @return the ith genotype in this context or null if there aren't that many genotypes */ public Genotype getGenotype(int ith) { return genotypes.size() > ith ? genotypes.get(ith) : null; }
/** * @param sample the sample name * * @return the Genotype associated with the given sample in this context or null if the sample is not in this context */ public Genotype getGenotype(String sample) { return getGenotypes().get(sample); }
/** * @param sample the sample name * * @return the Genotype associated with the given sample in this context or null if the sample is not in this context */ public Genotype getGenotype(String sample) { return getGenotypes().get(sample); }
/** * @param sample the sample name * * @return the Genotype associated with the given sample in this context or null if the sample is not in this context */ public Genotype getGenotype(String sample) { return getGenotypes().get(sample); }
/** * @param ith the sample index * * @return the ith genotype in this context or null if there aren't that many genotypes */ public Genotype getGenotype(int ith) { return genotypes.size() > ith ? genotypes.get(ith) : null; }
/** * Return a freshly allocated subcontext of this context containing only the samples * listed in samples. Note that samples can contain names not in this context, they * will just be ignored. * * @param samples * @return */ public GenotypesContext subsetToSamples( final Set<String> samples ) { final int nSamples = samples.size(); if ( nSamples == 0 ) return NO_GENOTYPES; else { // nGenotypes < nSamples final GenotypesContext subset = create(samples.size()); for ( final String sample : samples ) { final Genotype g = get(sample); if ( g != null ) subset.add(g); } return subset; } }
private void validateGenotypes() { if ( this.genotypes == null ) throw new IllegalStateException("Genotypes is null"); for ( int i = 0; i < genotypes.size(); i++ ) { Genotype genotype = genotypes.get(i); if ( genotype.isAvailable() ) { final List<Allele> alleles = genotype.getAlleles(); for ( int j = 0, size = alleles.size(); j < size; j++ ) { final Allele gAllele = alleles.get(j); if ( ! hasAllele(gAllele) && gAllele.isCalled() ) throw new IllegalStateException("Allele in genotype " + gAllele + " not in the variant context " + alleles); } } } }
private void validateGenotypes() { if ( this.genotypes == null ) throw new IllegalStateException("Genotypes is null"); for ( int i = 0; i < genotypes.size(); i++ ) { Genotype genotype = genotypes.get(i); if ( genotype.isAvailable() ) { final List<Allele> alleles = genotype.getAlleles(); for ( int j = 0, size = alleles.size(); j < size; j++ ) { final Allele gAllele = alleles.get(j); if ( ! hasAllele(gAllele) && gAllele.isCalled() ) throw new IllegalStateException("Allele in genotype " + gAllele + " not in the variant context " + alleles); } } } }
private static Genotype getGenotypeFromArray(RefMetaDataTracker tracker, RodBinding<VariantContext> genotypes, boolean verifiedSampleName, boolean verifySample, String sampleName) { // get the truthForSample and the hapmap information for this site; if either are null we can't move forward Collection<VariantContext> truths = tracker.getValues(genotypes); if (truths == null || truths.isEmpty()) return null; VariantContext truthForSample = truths.iterator().next(); // verify that the sample name exists in the input genotype file if (!verifiedSampleName && verifySample) { if (!truthForSample.getSampleNames().contains(sampleName)) throw new UserException.BadInput("The sample name was set to " + sampleName + " but this sample isn't in your genotypes file. Please Verify your sample name"); verifiedSampleName = true; } GenotypesContext gt = truthForSample.getGenotypes(); // if we are supposed to verify the sample name, AND the sample doesn't exist in the genotypes -- skip this site if (verifySample && !gt.containsSample(sampleName)) return null; // if the sample doesn't exist in genotypes AND there is more than one sample in the genotypes file -- skip this site if (!gt.containsSample(sampleName) && gt.size() != 1) return null; // if there is more than one sample in the genotypes file, get it by name. Otherwise just get the sole sample genotype return gt.size() != 1 ? gt.get(sampleName) : gt.get(0); }
@Test(enabled = !DEBUG, dataProvider = "AlleleRemappingData") public void testAlleleRemapping(final Map<Allele, Allele> alleleMap, final int numGenotypes) { final GATKVariantContextUtils.AlleleMapper alleleMapper = new GATKVariantContextUtils.AlleleMapper(alleleMap); final GenotypesContext originalGC = createGenotypesContext(numGenotypes, new ArrayList(alleleMap.keySet())); final GenotypesContext remappedGC = GATKVariantContextUtils.updateGenotypesWithMappedAlleles(originalGC, alleleMapper); for ( int i = 0; i < numGenotypes; i++ ) { final Genotype originalG = originalGC.get(String.format("%d", i)); final Genotype remappedG = remappedGC.get(String.format("%d", i)); Assert.assertEquals(originalG.getAlleles().size(), remappedG.getAlleles().size()); for ( int j = 0; j < originalG.getAlleles().size(); j++ ) Assert.assertEquals(remappedG.getAllele(j), alleleMap.get(originalG.getAllele(j))); } }
@Test(enabled = true, dataProvider = "GenotypesContextProvider") public void testReplace(GenotypesContextProvider cfg) { int n = cfg.makeContext().size(); for ( int i = 0; i < n; i++ ) { GenotypesContext gc = cfg.makeContext(); Genotype toReplace = gc.get(i); Genotype replacement = GenotypeBuilder.create(toReplace.getSampleName(), Arrays.asList(Aref, Aref)); gc.replace(replacement); ArrayList<Genotype> l = new ArrayList<Genotype>(cfg.initialSamples); l.set(i, replacement); Assert.assertEquals(replacement, gc.get(i)); testGenotypesContextContainsExpectedSamples(gc, l); } }
@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); } }
private void assertGenotypesAreMostlyEqual(GenotypesContext actual, GenotypesContext expected) { if (actual == expected) { return; } if (actual == null || expected == null) { Assert.fail("Maps not equal: expected: " + expected + " and actual: " + actual); } if (actual.size() != expected.size()) { Assert.fail("Maps do not have the same size:" + actual.size() + " != " + expected.size()); } for (Genotype value : actual) { Genotype expectedValue = expected.get(value.getSampleName()); Assert.assertEquals(value.getAlleles(), expectedValue.getAlleles(), "Alleles in Genotype aren't equal"); Assert.assertEquals(value.getGQ(), expectedValue.getGQ(), "GQ values aren't equal"); Assert.assertEquals(value.hasLikelihoods(), expectedValue.hasLikelihoods(), "Either both have likelihoods or both not"); if ( value.hasLikelihoods() ) Assert.assertEquals(value.getLikelihoods().getAsVector(), expectedValue.getLikelihoods().getAsVector(), "Genotype likelihoods aren't equal"); } }
@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())); } }