/** * Returns a map from sampleName -> Genotype for the genotype associated with sampleName. Returns a map * for consistency with the multi-get function. * * @param sampleName the sample name * @return mapping from sample name to genotype * @throws IllegalArgumentException if sampleName isn't bound to a genotype */ public GenotypesContext getGenotypes(String sampleName) { return getGenotypes(Collections.singleton(sampleName)); }
private final int computeMaxSizeOfGenotypeFieldFromValues(final VariantContext vc) { int size = -1; for ( final Genotype g : vc.getGenotypes() ) { size = Math.max(size, numElements(vc, g)); } return size; } }
private final int computeMaxSizeOfGenotypeFieldFromValues(final VariantContext vc) { int size = -1; for ( final Genotype g : vc.getGenotypes() ) { size = Math.max(size, numElements(vc, g)); } return size; } }
/** Returns true if the variant is --NOT-- interesting enough to be included in metrics calculations. */ static private boolean isVariantExcluded(final VariantContext vc) { // If the entire record is not a variant, exclude it return !vc.isVariant() || vc.getGenotypes().stream().allMatch(Genotype::isHomRef); }
@Ensures({"result >= 0"}) private final int computeMaxSizeOfGenotypeFieldFromValues(final VariantContext vc) { int size = -1; for ( final Genotype g : vc.getGenotypes() ) { size = Math.max(size, numElements(vc, g)); } return size; } }
/** Returns true if the variant is --NOT-- interesting enough to be included in metrics calculations. */ static private boolean isVariantExcluded(final VariantContext vc) { // If the entire record is not a variant, exclude it return !vc.isVariant() || vc.getGenotypes().stream().allMatch(Genotype::isHomRef); }
protected void writeRecord(VariantContext vc) { final GenotypesContext gc = vc.getGenotypes(); if (gc instanceof LazyParsingGenotypesContext) ((LazyParsingGenotypesContext)gc).getParser().setHeaderDataCache( gc instanceof LazyVCFGenotypesContext ? vcfHeaderDataCache : bcfHeaderDataCache); writer.add(vc); } }
private void calculateGenotypeCounts() { if ( genotypeCounts == null ) { genotypeCounts = new int[GenotypeType.values().length]; for ( final Genotype g : getGenotypes() ) { genotypeCounts[g.getType().ordinal()]++; } } }
private BCF2Codec.LazyData getLazyData(final VariantContext vc) { if ( vc.getGenotypes().isLazyWithData() ) { final LazyGenotypesContext lgc = (LazyGenotypesContext)vc.getGenotypes(); if ( lgc.getUnparsedGenotypeData() instanceof BCF2Codec.LazyData && canSafelyWriteRawGenotypesBytes((BCF2Codec.LazyData) lgc.getUnparsedGenotypeData())) { return (BCF2Codec.LazyData)lgc.getUnparsedGenotypeData(); } else { lgc.decode(); // WARNING -- required to avoid keeping around bad lazy data for too long } } return null; }
private void calculateGenotypeCounts() { if ( genotypeCounts == null ) { genotypeCounts = new int[GenotypeType.values().length]; for ( final Genotype g : getGenotypes() ) { genotypeCounts[g.getType().ordinal()]++; } } }
protected void writeRecord(VariantContext vc) { final GenotypesContext gc = vc.getGenotypes(); if (gc instanceof LazyParsingGenotypesContext) ((LazyParsingGenotypesContext)gc).getParser().setHeaderDataCache( gc instanceof LazyVCFGenotypesContext ? vcfHeaderDataCache : bcfHeaderDataCache); writer.add(vc); } }
private void calculateGenotypeCounts() { if ( genotypeCounts == null ) { genotypeCounts = new int[GenotypeType.values().length]; for ( final Genotype g : getGenotypes() ) { genotypeCounts[g.getType().ordinal()]++; } } }
public String toStringDecodeGenotypes() { return String.format("[VC %s @ %s Q%s of type=%s alleles=%s attr=%s GT=%s filters=%s", getSource(), contig + ":" + (start - stop == 0 ? start : start + "-" + stop), hasLog10PError() ? String.format("%.2f", getPhredScaledQual()) : ".", this.getType(), ParsingUtils.sortList(this.getAlleles()), ParsingUtils.sortedString(this.getAttributes()), this.getGenotypes(), String.join(",", commonInfo.getFilters())); }
@Test(enabled = !DEBUG, dataProvider = "mergeGenotypes") public void testMergeGenotypes(MergeGenotypesTest cfg) { final VariantContext merged = GATKVariantContextUtils.simpleMerge( cfg.inputs, cfg.priority, GATKVariantContextUtils.FilteredRecordMergeType.KEEP_IF_ANY_UNFILTERED, GATKVariantContextUtils.GenotypeMergeType.PRIORITIZE, true, false, "set", false, false); // test alleles are equal Assert.assertEquals(merged.getAlleles(), cfg.expected.getAlleles()); // test genotypes assertGenotypesAreMostlyEqual(merged.getGenotypes(), cfg.expected.getGenotypes()); }
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 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(); } }
/** * Copy constructor * * @param other the VariantContext to copy */ protected VariantContext(VariantContext other) { this(other.getSource(), other.getID(), other.getContig(), other.getStart(), other.getEnd(), other.getAlleles(), other.getGenotypes(), other.getLog10PError(), other.getFiltersMaybeNull(), other.getAttributes(), other.fullyDecoded, NO_VALIDATION); }
@Test(dataProvider = "leftAlignAllelesData") public void testLeftAlignVariants(final VariantContext source, final ReferenceSequence reference, final VariantContext result) { VariantContextBuilder vcb = new VariantContextBuilder(source); LiftoverUtils.leftAlignVariant(vcb, source.getStart(), source.getEnd(), source.getAlleles(), reference); vcb.genotypes(LiftoverUtils.fixGenotypes(source.getGenotypes(), source.getAlleles(), vcb.getAlleles())); VcfTestUtils.assertEquals(vcb.make(), result); }