private static int indexOfSameAllele(final VariantContext vc, final Allele allele, final boolean considerRefAllele) { int i = 0; for (final Allele a : vc.getAlleles()) if (a == allele) return i == 0 ? (considerRefAllele ? 0 : -1) : i; else i++; return -1; }
/** * Lookup the index of allele in this variant context * * @param allele the allele whose index we want to get * @return the index of the allele into getAlleles(), or -1 if it cannot be found */ public int getAlleleIndex(final Allele allele) { return getAlleles().indexOf(allele); }
/** * @return The allele sharing the same bases as this byte[], or null if no such allele is present. */ public Allele getAllele(byte[] allele) { return Allele.getMatchingAllele(getAlleles(), allele); }
/** * Assign genotypes (GTs) to the samples in the Variant Context greedily based on the PLs * * @param vc variant context with genotype likelihoods * @return genotypes context */ public static GenotypesContext assignDiploidGenotypes(final VariantContext vc) { return subsetAlleles(vc, vc.getAlleles(), GenotypeAssignmentMethod.USE_PLS_TO_ASSIGN); }
private VariantContext addNonRefSymbolicAllele(final VariantContext mergedVC) { final VariantContextBuilder vcb = new VariantContextBuilder(mergedVC); final List<Allele> originalList = mergedVC.getAlleles(); final List<Allele> alleleList = new ArrayList<>(originalList.size() + 1); alleleList.addAll(mergedVC.getAlleles()); alleleList.add(GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE); vcb.alleles(alleleList); return vcb.make(); }
@Override public String toString() { final StringBuilder b = new StringBuilder("EventMap{"); for ( final VariantContext vc : getVariantContexts() ) b.append(String.format("%s:%d-%d %s,", vc.getChr(), vc.getStart(), vc.getEnd(), vc.getAlleles())); b.append("}"); return b.toString(); }
private Double annotateWithPileup(final AlignmentContext stratifiedContext, final VariantContext vc) { final HashMap<Byte, MutableInt> alleleCounts = new HashMap<>(); for ( final Allele allele : vc.getAlleles() ) alleleCounts.put(allele.getBases()[0], new MutableInt(0)); for ( final byte base : stratifiedContext.getBasePileup().getBases() ) { if ( alleleCounts.containsKey(base) ) alleleCounts.get(base).increment(); } final int refCount = alleleCounts.get(vc.getReference().getBases()[0]).intValue(); final int altCount = alleleCounts.get(vc.getAlternateAllele(0).getBases()[0]).intValue(); return (refCount + altCount == 0) ? null : ((double) refCount) / (refCount + altCount); }
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 String toStringWithoutGenotypes() { return String.format("[VC %s @ %s Q%s of type=%s alleles=%s attr=%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()), String.join(",", commonInfo.getFilters())); }
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()); }
@Test(enabled = !DEBUG, dataProvider = "mergeFiltered") public void testMergeFiltered(MergeFilteredTest cfg) { final List<String> priority = vcs2priority(cfg.inputs); final VariantContext merged = GATKVariantContextUtils.simpleMerge( cfg.inputs, priority, cfg.type, GATKVariantContextUtils.GenotypeMergeType.PRIORITIZE, true, false, "set", false, false); // test alleles are equal Assert.assertEquals(merged.getAlleles(), cfg.expected.getAlleles()); // test set field Assert.assertEquals(merged.getAttribute("set"), cfg.setExpected); // test filter field Assert.assertEquals(merged.getFilters(), cfg.expected.getFilters()); }
/** * Test code that creates VariantContexts */ @Test() public void testWithVariantContext() throws Exception { final List<Allele> alleles = Arrays.asList(Allele.create("A", true), Allele.create("C")); final VariantContext vc = new VariantContextBuilder("test", "1", 10, 10, alleles).make(); Assert.assertTrue(vc.getAlleles().size() >= 0); // TODO -- add some tests that use VariantContext } }
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(); } }
@Test public void testRemoveExcessiveAltAlleleFromVC(){ final VariantContext originalVC = new VariantContextBuilder("source", "1", 1000000, 1000000, Arrays.asList(Allele.create("A", true), Allele.create("T", false), Allele.create("C", false), Allele.create("G", false))).make(); final VariantContext reducedVC = HaplotypeCallerGenotypingEngine.removeExcessAltAllelesFromVC(originalVC, Arrays.asList(Allele.create("A", true), Allele.create("T", false), Allele.create("C", false))); Assert.assertEquals(reducedVC.getNAlleles(), 3); Assert.assertTrue(reducedVC.getAlleles().containsAll(Arrays.asList(Allele.create("A", true), Allele.create("T", false), Allele.create("C", false)))); } }
/** * 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); }