/** * Annotate VariantContext with the pedigree-based filters * * @param vc the {@link VariantContext} to annotate * @return copy of <code>vc</code> with applied annotations */ public VariantContext annotateVariantContext(VariantContext vc) { VariantContextBuilder builder = new VariantContextBuilder(vc); List<Genotype> gts = annotateGenotypes(builder, vc); builder.genotypes(gts); return builder.make(); }
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); }
private static void addGenotypeTests( final VariantContext site, Genotype ... genotypes ) { // for each sites VC, we are going to add create two root genotypes. // The first is the primary, and will be added to each new test // The second is variable. In some tests it's absent (testing 1 genotype), in others it is duplicated // 1 once, 10, 100, or 1000 times to test scaling final VariantContextBuilder builder = new VariantContextBuilder(site); // add a single context builder.genotypes(genotypes[0]); add(builder); if ( genotypes.length > 1 ) { // add all add(builder.genotypes(Arrays.asList(genotypes))); // add all with the last replicated 10x and 100x times for ( int nCopiesOfLast : Arrays.asList(10, 100, 1000) ) { final GenotypesContext gc = new GenotypesContext(); final Genotype last = genotypes[genotypes.length-1]; for ( int i = 0; i < genotypes.length - 1; i++ ) gc.add(genotypes[i]); for ( int i = 0; i < nCopiesOfLast; i++ ) gc.add(new GenotypeBuilder(last).name("copy" + i).make()); add(builder.genotypes(gc)); } } }
/** Makes a new VariantContext with only the desired samples. */ private static VariantContext subsetToSamplesWithOriginalAnnotations(final VariantContext ctx, final Set<String> samples) { final VariantContextBuilder builder = new VariantContextBuilder(ctx); final GenotypesContext newGenotypes = ctx.getGenotypes().subsetToSamples(samples); builder.alleles(ctx.getAlleles()); return builder.genotypes(newGenotypes).make(); } }
protected static VariantContextBuilder reverseComplementVariantContext(final VariantContext source, final Interval target, final ReferenceSequence refSeq) { if (target.isPositiveStrand()) { throw new IllegalArgumentException("This should only be called for negative strand liftovers"); } final List<Allele> origAlleles = new ArrayList<>(source.getAlleles()); final VariantContextBuilder vcb = new VariantContextBuilder(source); vcb.chr(target.getContig()); // By convention, indels are left aligned and include the base prior to that indel. // When reverse complementing, will be necessary to include this additional base. // This check prevents the extremely rare situation in which the indel occurs on the // first base of the sequence final boolean addToStart = source.isIndel() && target.getStart() > 1; final int start = target.getStart() - (addToStart ? 1 : 0); vcb.start(start); final int stop = target.getEnd() - (addToStart ? 1 : 0); vcb.stop(stop); vcb.alleles(reverseComplementAlleles(origAlleles, target, refSeq, source.isIndel(), addToStart)); if (!source.isSNP()) { // check that the reverse complemented bases match the new reference if (!referenceAlleleMatchesReferenceForIndel(vcb.getAlleles(), refSeq, start, stop)) { return null; } leftAlignVariant(vcb, start, stop, vcb.getAlleles(), refSeq); } vcb.genotypes(fixGenotypes(source.getGenotypes(), origAlleles, vcb.getAlleles())); return vcb; }
public static VariantContext subsetAlleles(final VariantContext originalVc, final List<Allele> allelesToKeep) { VariantContextBuilder vcBuilder = new VariantContextBuilder(originalVc).alleles(allelesToKeep); GenotypesContext newGenotypes = subsetAlleles(originalVc.getGenotypes(), originalVc.getAlleles(), allelesToKeep); vcBuilder.genotypes(newGenotypes); return vcBuilder.make(); }
public VariantContext createEmptyContext(VariantContext other, List<String> samples) { VariantContextBuilder builder = new VariantContextBuilder(); // set the alleles to be the same builder.alleles(other.getAlleles()); builder.loc(other.getChr(),other.getStart(),other.getEnd()); // set all genotypes to empty List<Genotype> genotypes = new ArrayList<Genotype>(samples.size()); for ( String sample : samples ) genotypes.add(GenotypeBuilder.create(sample, new ArrayList<Allele>(0))); builder.genotypes(genotypes); return builder.make(); }
public static VariantContext purgeUnallowedGenotypeAttributes(VariantContext vc, Set<String> allowedAttributes) { if ( allowedAttributes == null ) return vc; final GenotypesContext newGenotypes = GenotypesContext.create(vc.getNSamples()); for ( final Genotype genotype : vc.getGenotypes() ) { final Map<String, Object> attrs = new HashMap<>(); for ( final Map.Entry<String, Object> attr : genotype.getExtendedAttributes().entrySet() ) { if ( allowedAttributes.contains(attr.getKey()) ) attrs.put(attr.getKey(), attr.getValue()); } newGenotypes.add(new GenotypeBuilder(genotype).attributes(attrs).make()); } return new VariantContextBuilder(vc).genotypes(newGenotypes).make(); }
public VariantContext makeACTest(final int[] nhet, final int[] nhomvar, final int nNonInformative, final int nonTypePL) { List<Genotype> samples = new ArrayList<Genotype>(nSamples); for ( int altI = 0; altI < nhet.length; altI++ ) { for ( int i = 0; i < nhet[altI]; i++ ) samples.add(makePL(GenotypeType.HET, nonTypePL, altI+1)); for ( int i = 0; i < nhomvar[altI]; i++ ) samples.add(makePL(GenotypeType.HOM_VAR, nonTypePL, altI+1)); } final Genotype nonInformative = makeNonInformative(); samples.addAll(Collections.nCopies(nNonInformative, nonInformative)); final int nRef = Math.max((int) (nSamples - nNonInformative - MathUtils.sum(nhet) - MathUtils.sum(nhomvar)), 0); samples.addAll(Collections.nCopies(nRef, makePL(GenotypeType.HOM_REF, nonTypePL, 0))); samples = samples.subList(0, nSamples); if ( samples.size() > nSamples ) throw new IllegalStateException("too many samples"); VariantContextBuilder vcb = new VariantContextBuilder("x", "1", 1, 1, getAlleles()); vcb.genotypes(samples); return vcb.make(); }
public static VariantContext subsetAlleles(final VariantContext originalVc, final List<Allele> allelesToKeep) { VariantContextBuilder vcBuilder = new VariantContextBuilder(originalVc).alleles(allelesToKeep); GenotypesContext newGenotypes = subsetAlleles(originalVc.getGenotypes(), originalVc.getAlleles(), allelesToKeep); vcBuilder.genotypes(newGenotypes); return vcBuilder.make(); }
/** Makes a new VariantContext with only the desired samples. */ private static VariantContext subsetToSamplesWithOriginalAnnotations(final VariantContext ctx, final Set<String> samples) { final VariantContextBuilder builder = new VariantContextBuilder(ctx); final GenotypesContext newGenotypes = ctx.getGenotypes().subsetToSamples(samples); builder.alleles(ctx.getAlleles()); return builder.genotypes(newGenotypes).make(); } }
public VariantContext toVariantContext() { GenotypesContext gc = GenotypesContext.copy(this.genotypes.values()); return new VariantContextBuilder(name, contig, start, stop, alleles).id(id) .genotypes(gc).log10PError(log10PError).filters(filters).attributes(attributes).make(); }
/** * 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 VariantContext getVC() { VariantContextBuilder builder = new VariantContextBuilder("test", "1", 1, 1, getAlleles()); builder.genotypes(GLs); return builder.make(); }
private VariantContext makeVC(String source, List<Allele> alleles, Genotype... genotypes) { int start = 10; int stop = start; // alleles.contains(ATC) ? start + 3 : start; return new VariantContextBuilder(source, "1", start, stop, alleles) .genotypes(Arrays.asList(genotypes)) .filters((String) null) .make(); }
private VariantContext makeVC(String source, List<Allele> alleles, Genotype... genotypes) { int start = 10; int stop = start; // alleles.contains(ATC) ? start + 3 : start; return new VariantContextBuilder(source, "1", start, stop, alleles) .genotypes(Arrays.asList(genotypes)) .filters((String)null) .make(); }
private VariantContext makeVC(String source, List<Allele> alleles, Genotype... genotypes) { int start = 10; int stop = start; // alleles.contains(ATC) ? start + 3 : start; return new VariantContextBuilder(source, "1", start, stop, alleles).genotypes(Arrays.asList(genotypes)).filters((String)null).make(); }
private VariantContext makeVC(String source, List<Allele> alleles, Genotype... genotypes) { int start = 10; int stop = start; // alleles.contains(ATC) ? start + 3 : start; return new VariantContextBuilder(source, "1", start, stop, alleles) .genotypes(Arrays.asList(genotypes)) .filters((String)null) .make(); }
@Override protected VariantContext reduceScope(final VariantContext vc, final int defaultPloidy, final int maximumAlternativeAlleles) { // don't try to genotype too many alternate alleles final List<Allele> inputAltAlleles = vc.getAlternateAlleles(); final List<Allele> outputAltAlleles = reduceScopeAlleles(vc, defaultPloidy, maximumAlternativeAlleles); // only if output allele has reduced from the input alt allele set size we should care. final int altAlleleReduction = inputAltAlleles.size() - outputAltAlleles.size(); if (altAlleleReduction == 0) return vc; final String message = String.format("This tool is currently set to genotype at most %d " + "alternate alleles in a given context, but the context at %s: %d has %d " + "alternate alleles so only the top alleles will be used; see the --max_alternate_alleles argument", maximumAlternativeAlleles, vc.getContig(), vc.getStart(), vc.getAlternateAlleles().size()); if ( !printedMaxAltAllelesWarning ) { printedMaxAltAllelesWarning = true; logger.warn(message + ". Unless the DEBUG logging level is used, this warning message is output just once per run and further warnings are suppressed."); } else { logger.debug(message); } final List<Allele> alleles = new ArrayList<>(maximumAlternativeAlleles + 1); alleles.add(vc.getReference()); alleles.addAll(reduceScopeAlleles(vc, defaultPloidy, maximumAlternativeAlleles)); final VariantContextBuilder builder = new VariantContextBuilder(vc); builder.alleles(alleles); builder.genotypes(reduceScopeGenotypes(vc, defaultPloidy, alleles)); if (altAlleleReduction < 0) throw new IllegalStateException("unexpected: reduction increased the number of alt. alleles!: " + - altAlleleReduction + " " + vc + " " + builder.make()); return builder.make(); }
protected VariantContext makeVariantContext(String chromosome, int start, int end, String idForVcf, List<String> alleleList, boolean isNoVariation, Set<String> filters, double qual, ObjectMap attributes, List<Genotype> genotypes) { String refAllele = alleleList.get(0); VariantContextBuilder variantContextBuilder = new VariantContextBuilder() .chr(chromosome) .start(start) variantContextBuilder.noGenotypes(); } else { variantContextBuilder.genotypes(genotypes); return variantContextBuilder.make();