/** * Strips PLs from the specified GenotypeBuilder if their number exceeds the maximum allowed. Corresponding counters are updated. * @param gb the GenotypeBuilder to modify * @param vc the VariantContext * @param sampleName the sample name * @param newLikelihoods the PL array */ protected void removePLsIfMaxNumPLValuesExceeded(final GenotypeBuilder gb, final VariantContext vc, final String sampleName, final double[] newLikelihoods) { final int numPLValuesFound = newLikelihoods.length; if (numPLValuesFound > maxNumPLValues) { logMaxNumPLValuesWarning(vc, sampleName, numPLValuesFound); numTimesMaxNumPLValuesExceeded++; gb.noPL(); if (numPLValuesFound > maxNumPLValuesObserved) { maxNumPLValuesObserved = numPLValuesFound; } } }
protected void ensureGenotypeBuilders(ProcessingContext context) { for (int i = 0; i < context.getCategoryCount(); i++) { if (genotypeBuilder.size() <= i) { genotypeBuilder.add(new GenotypeBuilder(context.getCategoryLabel(i)) .alleles(Arrays.asList(Allele.NO_CALL)) .phased(false) .noAD() .noDP() .noGQ() .noPL()); } } assert(genotypeBuilder.size() >= context.getCategoryCount()); } public IdsvVariantContextBuilder referenceReads(int[] count) {
public static Genotype removePLsAndAD(final Genotype g) { return ( g.hasLikelihoods() || g.hasAD() ) ? new GenotypeBuilder(g).noPL().noAD().make() : g; }
builder.noPL(); } else { builder.PL(glsToPls(in.getGenotypeLikelihoodList()));
genotypeBuilder.PL(pl); } else { genotypeBuilder.noPL();
gb.noGQ(); gb.noAD(); gb.noPL(); gb.noAttributes(); break;
@Test(enabled = !DEBUG) public void testSubsetToRef() { final Map<Genotype, Genotype> tests = new LinkedHashMap<>(); for ( final List<Allele> alleles : Arrays.asList(Arrays.asList(Aref), Arrays.asList(C), Arrays.asList(Aref, C), Arrays.asList(Aref, C, C) ) ) { for ( final String name : Arrays.asList("test1", "test2") ) { final GenotypeBuilder builder = new GenotypeBuilder(name, alleles); builder.DP(10); builder.GQ(30); builder.AD(alleles.size() == 1 ? new int[]{1} : (alleles.size() == 2 ? new int[]{1, 2} : new int[]{1, 2, 3})); builder.PL(alleles.size() == 1 ? new int[]{1} : (alleles.size() == 2 ? new int[]{1, 2} : new int[]{1, 2, 3})); builder.attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, alleles.size() == 1 ? new int[]{1, 2} : (alleles.size() == 2 ? new int[]{1, 2, 3, 4} : new int[]{1, 2, 3, 4, 5, 6})); final List<Allele> refs = Collections.nCopies(alleles.size(), Aref); tests.put(builder.make(), builder.alleles(refs).noAD().noPL().attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, null).make()); } } for ( final int n : Arrays.asList(1, 2, 3) ) { for ( final List<Genotype> genotypes : Utils.makePermutations(new ArrayList<>(tests.keySet()), n, false) ) { final VariantContext vc = new VariantContextBuilder("test", "20", 1, 1, Arrays.asList(Aref, C)).genotypes(genotypes).make(); final GenotypesContext gc = GATKVariantContextUtils.subsetToRefOnly(vc, 2); Assert.assertEquals(gc.size(), genotypes.size()); for ( int i = 0; i < genotypes.size(); i++ ) { assertGenotypesAreEqual(gc.get(i), tests.get(genotypes.get(i))); } } } }
gb = new GenotypeBuilder(g).noPL().noGQ().alleles(DIPLOID_NO_CALL); } else { gb = new GenotypeBuilder(g).PL(newPLs).log10PError(newLog10GQ);
gb = new GenotypeBuilder(g).noPL().noGQ().alleles(DIPLOID_NO_CALL); } else { gb = new GenotypeBuilder(g).PL(newPLs).log10PError(newLog10GQ);
builder.PL(pl); } else { builder.noPL();
builder.PL(pl); } else { builder.noPL();
builder.noPL();
public static VariantContextBuilder pruneVariantContext(final VariantContextBuilder builder, Collection<String> keysToPreserve ) { final VariantContext vc = builder.make(); if ( keysToPreserve == null ) keysToPreserve = Collections.emptyList(); // VC info final Map<String, Object> attributes = subsetAttributes(vc.getCommonInfo(), keysToPreserve); // Genotypes final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples()); for ( final Genotype g : vc.getGenotypes() ) { final GenotypeBuilder gb = new GenotypeBuilder(g); // remove AD, DP, PL, and all extended attributes, keeping just GT and GQ gb.noAD().noDP().noPL().noAttributes(); genotypes.add(gb.make()); } return builder.genotypes(genotypes).attributes(attributes); }
final int ploidy = g.getPloidy(); final GenotypeBuilder genotypeBuilder = new GenotypeBuilder(g).alleles(GATKVariantContextUtils.noCallAlleles(g.getPloidy())) .noPL(); genotypeBuilder.name(name);
gb.noPL(); else gb.PL(newLikelihoods);
/** * Convert a HomRefBlock into a VariantContext * * @param block the block to convert * @return a VariantContext representing the gVCF encoding for this block. * It will return {@code null} if input {@code block} is {@code null}, indicating that there * is no variant-context to be output into the VCF. */ private VariantContext blockToVCF(final HomRefBlock block) { if ( block == null ) return null; final VariantContextBuilder vcb = new VariantContextBuilder(block.getStartingVC()); vcb.attributes(new HashMap<String, Object>(2)); // clear the attributes vcb.stop(block.getStop()); vcb.attribute(VCFConstants.END_KEY, block.getStop()); // create the single Genotype with GQ and DP annotations final GenotypeBuilder gb = new GenotypeBuilder(sampleName, GATKVariantContextUtils.homozygousAlleleList(block.getRef(),block.getPloidy())); gb.noAD().noPL().noAttributes(); // clear all attributes final int[] minPLs = block.getMinPLs(); gb.PL(minPLs); final int gq = GATKVariantContextUtils.calculateGQFromPLs(minPLs); gb.GQ(gq); gb.DP(block.getMedianDP()); gb.attribute(GATKVCFConstants.MIN_DP_FORMAT_KEY, block.getMinDP()); // This annotation is no longer standard //gb.attribute(MIN_GQ_FORMAT_FIELD, block.getMinGQ()); return vcb.genotypes(gb.make()).make(); }
final Genotype emptyGT = new GenotypeBuilder(base).alleles(GATKVariantContextUtils.noCallAlleles(2)).noPL().noGQ().make(); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(uninformativeGT).make(), AC, Arrays.asList(emptyGT)}); final Genotype haplpoidEmptyGT = new GenotypeBuilder(base).alleles(GATKVariantContextUtils.noCallAlleles(1)).noPL().noGQ().make(); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(haploidUninformativeGT).make(), AC, Arrays.asList(haplpoidEmptyGT)});
final Genotype emptyGT = new GenotypeBuilder(base).alleles(Collections.nCopies(2, Allele.NO_CALL)).noAD().noPL().noGQ().make(); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(emptyGT).make(), new VariantContextBuilder(vcBase).alleles(AC).make(), Collections.singletonList(emptyGT)}); new VariantContextBuilder(vcBase).source("test-" + i++).alleles(ACG).genotypes(new GenotypeBuilder(base).alleles(AA).AD(homG3AllelesAD).noPL().make()).make(), new VariantContextBuilder(vcBase).source("test-" + i).alleles(AG).make(), Collections.singletonList(new GenotypeBuilder(base).alleles(AlleleSubsettingUtils.DIPLOID_NO_CALL).noPL().AD(new int[]{0, 21}).noGQ().make())});
final Genotype emptyGT = new GenotypeBuilder(base).alleles(GATKVariantContextUtils.noCallAlleles(2)).noAD().noPL().noGQ().make(); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(emptyGT).make(), new VariantContextBuilder(vcBase).alleles(AC).make(), Arrays.asList(emptyGT)});