protected static Genotype create(final String sampleName, final List<Allele> alleles, final double[] gls) { return new GenotypeBuilder(sampleName, alleles).PL(gls).make(); }
/** * 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; }
/** * 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(); }
public Genotype makePL(final List<Allele> expectedGT, int ... pls) { GenotypeBuilder gb = new GenotypeBuilder("sample" + sampleNameCounter++); gb.alleles(expectedGT); gb.PL(pls); return gb.make(); }
final GenotypeBuilder gb = new GenotypeBuilder(sampleName); gb.maxAttributes(genotypeKeys.size() - 1); gb.attribute(gtKey, genotypeValues.get(i)); } else if (missing) { gb.attribute(gtKey, null); } else if (gtKey.equals(VCFConstants.GENOTYPE_FILTER_KEY)) { final List<String> filters = parseFilters(getCachedString(genotypeValues.get(i))); if (filters != null) { gb.filters(filters); gb.attribute(gtKey, filters); } else if (genotypeValues.get(i).equals(VCFConstants.MISSING_VALUE_v4)) { gb.attribute(gtKey, null); } else { if (gtKey.equals(VCFConstants.GENOTYPE_QUALITY_KEY)) { if (genotypeValues.get(i).equals(VCFConstants.MISSING_GENOTYPE_QUALITY_v3)) { gb.noGQ(); } else { gb.GQ((int)Math.round(Double.valueOf(genotypeValues.get(i)))); gb.AD(decodeInts(genotypeValues.get(i))); } else if (gtKey.equals(VCFConstants.GENOTYPE_PL_KEY)) { gb.PL(decodeInts(genotypeValues.get(i))); } else if (gtKey.equals(VCFConstants.GENOTYPE_LIKELIHOODS_KEY)) { gb.PL(GenotypeLikelihoods.fromGLField(genotypeValues.get(i)).getAsPLs());
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(); }
@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); }
@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))); } } } }
final List<Allele> alleles = Arrays.asList(allele1, allele2); final Genotype gt = new GenotypeBuilder() .DP(haplotypeProbabilities.getTotalObs()) .noAttributes() .PL(haplotypeProbabilities.getLogLikelihoods()) .AD(new int[]{haplotypeProbabilities.getObsAllele1(), haplotypeProbabilities.getObsAllele2()}) .name(sample) .make(); try { return new VariantContextBuilder(
/** * 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(); }
@Requires("originalGenotypes != null && alleleMapper != null") protected static GenotypesContext updateGenotypesWithMappedAlleles(final GenotypesContext originalGenotypes, final AlleleMapper alleleMapper) { final GenotypesContext updatedGenotypes = GenotypesContext.create(originalGenotypes.size()); for ( final Genotype genotype : originalGenotypes ) { final List<Allele> updatedAlleles = alleleMapper.remap(genotype.getAlleles()); updatedGenotypes.add(new GenotypeBuilder(genotype).alleles(updatedAlleles).make()); } return updatedGenotypes; }
final GenotypeBuilder gb = new GenotypeBuilder(sample); gb.attribute(GATKVCFConstants.AVG_INTERVAL_DP_BY_SAMPLE_KEY, sampleStat.averageCoverage(interval.size())); gb.attribute(GATKVCFConstants.LOW_COVERAGE_LOCI, sampleStat.getNLowCoveredLoci()); gb.attribute(GATKVCFConstants.ZERO_COVERAGE_LOCI, sampleStat.getNUncoveredLoci()); gb.filters(statusToStrings(stats.getSampleStatistics(sample).callableStatuses(), false)); genotypes.add(gb.make());
@DataProvider(name = "badSamplesProvider") public Iterator<Object[]> badSamplesProvider() { final VariantContextBuilder vc_builder = new VariantContextBuilder("testCode", "chr1", 1, 1, Arrays.asList(refA, G)); final GenotypeBuilder gt_builder = new GenotypeBuilder(); final List<Object[]> hets = new ArrayList<Object[]>(10); hets.add(new Object[]{vc_builder.make(), null}); hets.add(new Object[]{vc_builder.genotypes(Arrays.asList(gt_builder.name("test1").make(), gt_builder.name("test2").make())).make(), "notNull"}); hets.add(new Object[]{vc_builder.genotypes(Collections.singleton(gt_builder.name("This").make())).make(), "That"}); return hets.iterator(); }
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(); }
final List<Genotype> newGenotypes = new ArrayList<Genotype>(ctx.getNSamples()); for (final Genotype gt : ctx.getGenotypes()) { final GenotypeBuilder gtBuilder = new GenotypeBuilder(gt); final List<String> filters = gtFilterStrings.get(gt.getSampleName()); gtBuilder.filter(PASS_FILTER); gtBuilder.filters(filters); newGenotypes.add(gtBuilder.make());
genotypes.add(new GenotypeBuilder(g).filters(filters).alleles(DIPLOID_NO_CALL_ALLELES).make()); genotypes.add(new GenotypeBuilder(g).filters(filters).make()); calledAlleles = GATKVariantContextUtils.incrementChromosomeCountsInfo(calledAltAlleles, calledAlleles, g);
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(); } }
public static Genotype create(final String sampleName, final List<Allele> alleles, final Map<String, Object> attributes) { return new GenotypeBuilder(sampleName, alleles).attributes(attributes).make(); }
/** Augment genotype with the given filters and return modified GenotypeBuilder */ public Genotype gtWithAppliedFilters(Genotype gt) { GenotypeBuilder gtBuilder = new GenotypeBuilder(gt); ArrayList<String> filters = new ArrayList<>(); if (gt.isFiltered()) filters.add(gt.getFilters()); filters.addAll(getFiltersFor(gt)); gtBuilder.filters(filters); return gtBuilder.make(); }