@Override public void decode(final List<Allele> siteAlleles, final String field, final BCF2Decoder decoder, final byte typeDescriptor, final int numElements, final GenotypeBuilder[] gbs) throws IOException { for ( final GenotypeBuilder gb : gbs ) { // the -1 is for missing gb.DP(decoder.decodeInt(typeDescriptor, -1)); } } }
@Override public void decode(final List<Allele> siteAlleles, final String field, final BCF2Decoder decoder, final byte typeDescriptor, final int numElements, final GenotypeBuilder[] gbs) throws IOException { for ( final GenotypeBuilder gb : gbs ) { // the -1 is for missing gb.DP(decoder.decodeInt(typeDescriptor, -1)); } } }
@Override public void decode(final List<Allele> siteAlleles, final String field, final BCF2Decoder decoder, final byte typeDescriptor, final int numElements, final GenotypeBuilder[] gbs) throws IOException { for ( final GenotypeBuilder gb : gbs ) { // the -1 is for missing gb.DP(decoder.decodeInt(typeDescriptor, -1)); } } }
@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))); } } } }
private VariantContext makeHomRefAlt(final String contig, final int start, final int GQ) { final VariantContextBuilder vcb = new VariantContextBuilder("test", contig, start, start, Arrays.asList(REF, ALT)); final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME, Arrays.asList(REF, REF)); gb.GQ(GQ); gb.DP(10); gb.AD(new int[]{1, 2}); gb.PL(new int[]{0, 10, 100}); return vcb.genotypes(gb.make()).make(); }
final List<Allele> refAlleles = Collections.nCopies(gPloidy, vc.getReference()); final GenotypeBuilder gb = new GenotypeBuilder(g.getSampleName(), refAlleles); if ( g.hasDP() ) gb.DP(g.getDP()); if ( g.hasGQ() ) gb.GQ(g.getGQ()); newGTs.add(gb.make());
private VariantContext makeNonRef(final String contig, final int start, final int GQ) { final VariantContextBuilder vcb = new VariantContextBuilder("test", contig, start, start, Arrays.asList(REF, ALT)); final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME, Arrays.asList(REF, ALT)); gb.GQ(GQ); gb.DP(10); gb.AD(new int[]{1, 2}); gb.PL(new int[]{0, 10, 100}); return vcb.genotypes(gb.make()).make(); }
@DataProvider(name = "UsingAD") public Object[][] makeUsingADData() { List<Object[]> tests = new ArrayList<>(); final Allele A = Allele.create("A", true); final Allele C = Allele.create("C"); final Allele G = Allele.create("G"); final List<Allele> AA = Arrays.asList(A,A); final List<Allele> AC = Arrays.asList(A,C); final List<Allele> GG = Arrays.asList(G,G); final List<Allele> ACG = Arrays.asList(A,C,G); final Genotype gAC = new GenotypeBuilder("1", AC).DP(10).AD(new int[]{5,5}).make(); final Genotype gAA = new GenotypeBuilder("2", AA).DP(10).AD(new int[]{10,0}).make(); final Genotype gACerror = new GenotypeBuilder("3", AC).DP(10).AD(new int[]{9,1}).make(); final Genotype gGG = new GenotypeBuilder("4", GG).DP(10).AD(new int[]{1,9}).make(); tests.add(new Object[]{new VariantContextBuilder("test", "20", 10, 10, AC).log10PError(-5).genotypes(Arrays.asList(gAC)).make(), 5.0}); tests.add(new Object[]{new VariantContextBuilder("test", "20", 10, 10, AC).log10PError(-5).genotypes(Arrays.asList(gACerror)).make(), 5.0}); tests.add(new Object[]{new VariantContextBuilder("test", "20", 10, 10, AC).log10PError(-5).genotypes(Arrays.asList(gAA, gAC)).make(), 5.0}); tests.add(new Object[]{new VariantContextBuilder("test", "20", 10, 10, AC).log10PError(-5).genotypes(Arrays.asList(gAC, gACerror)).make(), 5.0}); tests.add(new Object[]{new VariantContextBuilder("test", "20", 10, 10, ACG).log10PError(-5).genotypes(Arrays.asList(gAA, gAC, gACerror, gGG)).make(), 2.5}); return tests.toArray(new Object[][]{}); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testBadAdd() { final HomRefBlock band = new HomRefBlock(vc, 10, 20, HomoSapiensConstants.DEFAULT_PLOIDY); final GenotypeBuilder gb = new GenotypeBuilder("NA12878"); band.add(vc.getStart() + 10, gb.DP(10).GQ(11).PL(new int[]{0,10,100}).make()); }
private VariantContext makeDeletion(final String contig, final int start, final int size) { final String del = Utils.dupString("A", size); final String alt = del.substring(0, 1); final VariantContext vc = GATKVariantContextUtils.makeFromAlleles("test", contig, start, Arrays.asList(del, alt)); final VariantContextBuilder vcb = new VariantContextBuilder(vc); final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME, Arrays.asList(vc.getReference(), vc.getAlternateAllele(0))); gb.GQ(50); gb.DP(10); gb.AD(new int[]{1, 2}); gb.PL(new int[]{0, 10, 100}); return vcb.genotypes(gb.make()).make(); }
private VariantContext makeHomRef(final String contig, final int start, final int GQ) { final VariantContextBuilder vcb = new VariantContextBuilder("test", contig, start, start, ALLELES); final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME, Arrays.asList(REF, REF)); gb.GQ(GQ); gb.DP(10); gb.AD(new int[]{1, 2}); gb.PL(new int[]{0, 10, 100}); return vcb.genotypes(gb.make()).make(); }
@Test public void testMinMedian() { //TODO - might be better to make this test use a data provider? final HomRefBlock band = new HomRefBlock(vc, 10, 20, HomoSapiensConstants.DEFAULT_PLOIDY); final GenotypeBuilder gb = new GenotypeBuilder("NA12878"); gb.alleles(vc.getAlleles()); int pos = vc.getStart(); band.add(pos++, gb.DP(10).GQ(11).PL(new int[]{0,11,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); assertValues(band, 10, 10, 11, 11); band.add(pos++, gb.DP(11).GQ(10).PL(new int[]{0,10,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); assertValues(band, 10, 11, 10, 11); band.add(pos++, gb.DP(12).GQ(12).PL(new int[]{0,12,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); assertValues(band, 10, 11, 10, 11); band.add(pos++, gb.DP(13).GQ(15).PL(new int[]{0,15,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); band.add(pos++, gb.DP(14).GQ(16).PL(new int[]{0,16,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); band.add(pos++, gb.DP(15).GQ(17).PL(new int[]{0,17,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); band.add(pos++, gb.DP(16).GQ(18).PL(new int[]{0,18,100}).make()); Assert.assertEquals(band.getStop(), pos - 1); assertValues(band, 10, 13, 10, 15); Assert.assertEquals(band.getSize(), pos - vc.getStart()); Assert.assertTrue(Arrays.equals(band.getMinPLs(), new int[]{0,10,100})); }
@Test public void testBigGQIsCapped() { final HomRefBlock band = new HomRefBlock(vc, 10, 20, HomoSapiensConstants.DEFAULT_PLOIDY); final GenotypeBuilder gb = new GenotypeBuilder("NA12878"); gb.alleles(vc.getAlleles()); band.add(vc.getStart(), gb.DP(1000).GQ(1000).PL(new int[]{0,10,100}).make()); assertValues(band, 1000, 1000, 99, 99); }
@Test public void testGenotypeConcordanceDetermineStateDp() throws Exception { final List<Allele> allelesNormal = makeUniqueListOfAlleles(Aref, C); final Genotype gtNormal = GenotypeBuilder.create(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C)); final VariantContext vcNormal = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesNormal).genotypes(gtNormal).make(); final List<Allele> allelesLowDp = makeUniqueListOfAlleles(Aref, C); final Genotype gtLowDp = new GenotypeBuilder(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C)).DP(4).make(); final VariantContext vcLowDp = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesLowDp).genotypes(gtLowDp).make(); testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcNormal, CallState.HET_REF_VAR1, 0, 20); testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2); testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.LOW_DP, 0, 20); testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2); testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcLowDp, CallState.LOW_DP, 0, 20); testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2); }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
.DP(haplotypeProbabilities.getTotalObs()) .noAttributes() .PL(haplotypeProbabilities.getLogLikelihoods())
@DataProvider(name="swapAlleleData") Iterator<Object[]> swapAlleleData(){ List<Object[]> tests = new ArrayList<>(); final VariantContext vcBase = new VariantContextBuilder("test", "20", 10, 10, AC).make(); final Genotype base = new GenotypeBuilder("NA12878").DP(10).GQ(100).make(); tests.add(new Object[]{vcBase, C, G, new VariantContextBuilder(vcBase).alleles(AG).make(), true}); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(new GenotypeBuilder(base).alleles(AC).make()).make(), C, G, new VariantContextBuilder(vcBase).alleles(AG).genotypes(new GenotypeBuilder(base).alleles(AG).make()).make(), true}); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(new GenotypeBuilder(base).alleles(AA).make()).make(), C, G, new VariantContextBuilder(vcBase).alleles(AG).genotypes(new GenotypeBuilder(base).alleles(AA).make()).make(), true}); tests.add(new Object[]{new VariantContextBuilder(vcBase).genotypes(new GenotypeBuilder(base).alleles(CC).make()).make(), C, G, new VariantContextBuilder(vcBase).alleles(AG).genotypes(new GenotypeBuilder(base).alleles(GG).make()).make(), true}); tests.add(new Object[]{vcBase, AlleleSubsettingUtils.NON_REF_ALLELE, G, null, false}); return tests.iterator(); }
/** * 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(); }