/** * This genotype has these attributes. Attributes are added to previous ones. * * Cannot contain inline attributes (DP, AD, GQ, PL). Note: this is not checked * @return */ public GenotypeBuilder attributes(final Map<String, Object> attributes) { for ( Map.Entry<String, Object> pair : attributes.entrySet() ) attribute(pair.getKey(), pair.getValue()); return this; }
/** * This genotype has these attributes. Attributes are added to previous ones. * * Cannot contain inline attributes (DP, AD, GQ, PL). Note: this is not checked * @return */ public GenotypeBuilder attributes(final Map<String, Object> attributes) { for ( Map.Entry<String, Object> pair : attributes.entrySet() ) attribute(pair.getKey(), pair.getValue()); return this; }
@Override public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { if ( alleleLikelihoodMap != null && !alleleLikelihoodMap.isEmpty() ) { gb.attribute(GATKVCFConstants.BASE_COUNTS_BY_SAMPLE_KEY, Arrays.stream(getBaseCounts(alleleLikelihoodMap, vc)).boxed().collect(Collectors.toList())); } }
/** * This genotype has these attributes. * * Cannot contain inline attributes (DP, AD, GQ, PL) * @return */ @Requires("attributes != null") @Ensures("attributes.isEmpty() || extendedAttributes != null") public GenotypeBuilder attributes(final Map<String, Object> attributes) { for ( Map.Entry<String, Object> pair : attributes.entrySet() ) attribute(pair.getKey(), pair.getValue()); return this; }
public IdsvVariantContextBuilder referenceReads(int[] count) { attribute(VcfInfoAttributes.REFERENCE_READ_COUNT.attribute(), Arrays.stream(count).sum()); for (int i = 0; i < count.length; i++) { genotypeBuilder.get(i).attribute(VcfFormatAttributes.REFERENCE_READ_COUNT.attribute(), count[i]); } return this; } public IdsvVariantContextBuilder referenceSpanningPairs(int[] count) {
private <T> void sumIntAttr( VcfInfoAttributes infoAttr, VcfFormatAttributes formatAttr, List<List<T>> support, ToIntFunction<T> f) { assert(support.size() == processContext.getCategoryCount()); int sum = 0; for (int i = 0; i < support.size(); i++) { int value = support.get(i).stream().mapToInt(f).sum(); genotypeBuilder.get(i).attribute(formatAttr.attribute(), value); sum += value; } attribute(infoAttr, sum); } private <T extends DirectedEvidence> double[] sumDoubleAttr(
public IdsvVariantContextBuilder referenceSpanningPairs(int[] count) { attribute(VcfInfoAttributes.REFERENCE_READPAIR_COUNT.attribute(), Arrays.stream(count).sum()); for (int i = 0; i < count.length; i++) { genotypeBuilder.get(i).attribute(VcfFormatAttributes.REFERENCE_READPAIR_COUNT.attribute(), count[i]); } return this; } /**
protected void annotateWithLikelihoods(final PerReadAlleleLikelihoodMap perReadAlleleLikelihoodMap, final VariantContext vc, final GenotypeBuilder gb) { final ArrayList<Double> refQuals = new ArrayList<>(); final ArrayList<Double> altQuals = new ArrayList<>(); // clean up fillQualsFromLikelihoodMap(vc.getAlleles(), vc.getStart(), perReadAlleleLikelihoodMap, refQuals, altQuals); double refQualSum = 0; for(Double d : refQuals) { refQualSum += d; } double altQualSum = 0; for(Double d : altQuals) { altQualSum += d; } gb.attribute(GATKVCFConstants.QUALITY_SCORE_SUM_KEY, new Integer[]{ (int) refQualSum, (int) altQualSum}); }
/** * Add physical phase information to the provided variant context * * @param vc the variant context * @param ID the ID to use * @param phaseGT the phase GT string to use * @return phased non-null variant context */ private static VariantContext phaseVC(final VariantContext vc, final String ID, final String phaseGT) { final List<Genotype> phasedGenotypes = new ArrayList<>(); for ( final Genotype g : vc.getGenotypes() ) phasedGenotypes.add(new GenotypeBuilder(g).attribute(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_ID_KEY, ID).attribute(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY, phaseGT).make()); return new VariantContextBuilder(vc).genotypes(phasedGenotypes).make(); }
@Override public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { if ( !AnnotationUtils.isAppropriateInput(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, walker, alleleLikelihoodMap, g, warningsLogged, logger) ) { return; } gb.attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, getStrandCounts(Collections.singletonMap(g.getSampleName(), alleleLikelihoodMap), vc)); }
@Override public void annotate(final RefMetaDataTracker tracker, final AnnotatorCompatible walker, final ReferenceContext ref, final AlignmentContext stratifiedContext, final VariantContext vc, final Genotype g, final GenotypeBuilder gb, final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { if (!AnnotationUtils.isAppropriateInput(GATKVCFConstants.STRAND_BIAS_BY_SAMPLE_KEY, walker, alleleLikelihoodMap, g, warningsLogged, logger)) { return; } final int[][] table = FisherStrand.getContingencyTable(Collections.singletonMap(g.getSampleName(), alleleLikelihoodMap), vc, 0); gb.attribute(GATKVCFConstants.STRAND_BIAS_BY_SAMPLE_KEY, StrandBiasTableUtils.getContingencyArray(table)); }
private static Genotype attr(final String name, final Allele ref, final String key, final Object ... value) { if ( value.length == 0 ) return GenotypeBuilder.create(name, Arrays.asList(ref, ref)); else { final Object toAdd = value.length == 1 ? value[0] : Arrays.asList(value); return new GenotypeBuilder(name, Arrays.asList(ref, ref)).attribute(key, toAdd).make(); } }
@Test public void testMakeNewSACs(){ int[] expected = {10, 20} ; final Genotype g = new GenotypeBuilder().alleles(Arrays.asList(Allele.create("A", true), Allele.create("G"))). attribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, new int[]{5, 10, 15, 20}).make(); Assert.assertEquals(GATKVariantContextUtils.makeNewSACs(g, Arrays.asList(1, 3)), expected); }
private VariantContext createVCGeneral(final VCFHeader header, final String chrom, final int position) { final List<Allele> alleles = new ArrayList<Allele>(); final Map<String, Object> attributes = new HashMap<String,Object>(); final GenotypesContext genotypes = GenotypesContext.create(header.getGenotypeSamples().size()); alleles.add(Allele.create("A",true)); alleles.add(Allele.create("ACC",false)); attributes.put("DP","50"); for (final String name : header.getGenotypeSamples()) { final Genotype gt = new GenotypeBuilder(name,alleles.subList(1,2)).GQ(0).attribute("BB", "1").phased(true).make(); genotypes.add(gt); } return new VariantContextBuilder("RANDOM", chrom, position, position, alleles) .genotypes(genotypes).attributes(attributes).make(); }
@BeforeSuite public void init() throws FileNotFoundException { referenceFile = new CachingIndexedFastaSequenceFile(new File(b37KGReference)); genomeLocParser = new GenomeLocParser(referenceFile); alleleList1 = Arrays.asList(Allele.create("T", true), Allele.create("C", false)); alleleList2 = Arrays.asList(Allele.create("G", true), Allele.create("A", false)); genotype1 = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).attribute("PQ", 100.0).alleles(alleleList1).make(); genotype2 = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-2", "10-1"}).attribute("PQ", 200.0).alleles(alleleList2).make(); contig = new String("1"); vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make(); vc2 = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make(); }
@Test public void TestMergeIntoMNPvalidationFilterNoCall() { final List<String> filters = Arrays.asList("filter"); final List<Allele> alleleList = Arrays.asList(Allele.create("T", true), Allele.create(".", false)); final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList).filters(filters).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make(); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2)); }
@Test public void TestMergeIntoMNPvalidationFiltered() { final List<String> filters = Arrays.asList("filter"); final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).filters(filters).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make(); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2)); }
@Test public void TestSomeSampleHasDoubleNonReferenceAlleleTrue(){ Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make(); VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make(); Assert.assertTrue(PhasingUtils.someSampleHasDoubleNonReferenceAllele(vc1, vc)); }
@Test public void TestMergeIntoMNPvalidationDiffSampleNames() { final Genotype genotype = new GenotypeBuilder().name("sample1").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make(); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2)); }
@Test public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){ final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make(); Assert.assertTrue(PhasingUtils.doubleAllelesSegregatePerfectlyAmongSamples(vc1, vc)); }