@Test public void TestMergeIntoMNPvalidationCheckLocBefore() { final VariantContext vc1before = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make(); final VariantContext vc2after = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make(); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1before, vc2after)); }
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(); }
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) .stop(end) .log10PError(qual) .filters(filters); variantContextBuilder.alleles(refAllele); } else { variantContextBuilder.alleles(alleleList.stream().filter(a -> !a.equals(NO_CALL_ALLELE)).collect(Collectors.toList())); variantContextBuilder.noGenotypes(); } else { variantContextBuilder.genotypes(genotypes); variantContextBuilder.attributes(attributes); variantContextBuilder.id(idForVcf); return variantContextBuilder.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(); }
public VariantContextBuilder(VariantContextBuilder parent) { if ( parent == null ) throw new IllegalArgumentException("BUG: VariantContext parent argument cannot be null in VariantContextBuilder"); this.alleles = parent.alleles; this.attributesCanBeModified = false; this.contig = parent.contig; this.genotypes = parent.genotypes; this.ID = parent.ID; this.log10PError = parent.log10PError; this.source = parent.source; this.start = parent.start; this.stop = parent.stop; this.fullyDecoded = parent.fullyDecoded; this.attributes(parent.attributes); this.filters(parent.filters); }
protected static VariantContextBuilder liftSimpleVariantContext(VariantContext source, Interval target) { if (target == null || source.getReference().length() != target.length()) { return null; } // Build the new variant context. Note: this will copy genotypes, annotations and filters final VariantContextBuilder builder = new VariantContextBuilder(source); builder.chr(target.getContig()); builder.start(target.getStart()); builder.stop(target.getEnd()); return builder; }
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(); }
public VariantContext annotateContext(final RefMetaDataTracker tracker, final ReferenceContext ref, final Map<String, AlignmentContext> stratifiedContexts, final VariantContext vc, final Map<String,PerReadAlleleLikelihoodMap> perReadAlleleLikelihoodMap) { // annotate genotypes final VariantContextBuilder builder = new VariantContextBuilder(vc).genotypes(annotateGenotypes(tracker, ref, stratifiedContexts, vc, perReadAlleleLikelihoodMap)); VariantContext newGenotypeAnnotatedVC = builder.make(); // annotate expressions where available final Map<String, Object> infoAnnotations = new LinkedHashMap<>(newGenotypeAnnotatedVC.getAttributes()); annotateExpressions(tracker, ref.getLocus(), newGenotypeAnnotatedVC, infoAnnotations); // go through all the requested info annotationTypes for ( final InfoFieldAnnotation annotationType : requestedInfoAnnotations ) { final Map<String, Object> annotationsFromCurrentType = annotationType.annotate(tracker, walker, ref, stratifiedContexts, newGenotypeAnnotatedVC, perReadAlleleLikelihoodMap); if ( annotationsFromCurrentType != null ) infoAnnotations.putAll(annotationsFromCurrentType); } // create a new VC in the with info and genotype annotations final VariantContext annotated = builder.attributes(infoAnnotations).make(); // annotate db occurrences return annotateDBs(tracker, annotated); }
@Test(dataProvider = "genotypeConcordanceDetermineStateDataProvider") public void testGenotypeConcordanceDetermineState(final Allele truthAllele1, final Allele truthAllele2, final TruthState expectedTruthState, final Allele callAllele1, final Allele callAllele2, final CallState expectedCallState) throws Exception { final List<Allele> truthAlleles = makeUniqueListOfAlleles(truthAllele1, truthAllele2); final Genotype truthGt = GenotypeBuilder.create(TRUTH_SAMPLE_NAME, Arrays.asList(truthAllele1, truthAllele2)); final VariantContext truthVariantContext = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, truthAlleles).genotypes(truthGt).make(); final List<Allele> callAlleles = makeUniqueListOfAlleles(callAllele1, callAllele2); final Genotype callGt = GenotypeBuilder.create(CALL_SAMPLE_NAME, Arrays.asList(callAllele1, callAllele2)); final VariantContext callVariantContext = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, callAlleles).genotypes(callGt).make(); testGenotypeConcordanceDetermineState(truthVariantContext, expectedTruthState, callVariantContext, expectedCallState, 0, 0); }
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; }
@DataProvider() public Iterator<Object[]> variantProvider() { final VariantContextBuilder vc_builder = new VariantContextBuilder("test", "chr1", 1, 1, Arrays.asList(refA, G)); final List<Object[]> variants = new ArrayList<Object[]>(10); // unfiltered variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).make(), true}); // passing variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).passFilters().make(), true}); // failing variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).filters(Collections.singleton("FILTER")).make(), false}); return variants.iterator(); }
@Test (expectedExceptions = Exception.class) public void testBadID2() { new VariantContextBuilder("test", delLoc, delLocStart, delLocStop, Arrays.asList(Aref, T)).id("").make(); }
private void writeVariant(VariantContextWriter writer, GenomeVariant genomeVar) { String nameInFasta = mapContigToFasta(genomeVar.getChrName()); List<Allele> alleles = new ArrayList<Allele>(); int shift = 0; if (genomeVar.getRef().isEmpty() || genomeVar.getAlt().isEmpty()) { shift = -1; String left = fasta.getSubsequenceAt(nameInFasta, genomeVar.getPos(), genomeVar.getPos()) .getBaseString(); alleles.add(Allele.create(left + genomeVar.getRef(), true)); alleles.add(Allele.create(left + genomeVar.getAlt(), false)); } else { alleles.add(Allele.create(genomeVar.getRef(), true)); alleles.add(Allele.create(genomeVar.getAlt(), false)); } VariantContextBuilder builder = new VariantContextBuilder(); builder.chr(genomeVar.getChrName()).start(genomeVar.getPos() + shift + 1) .computeEndFromAlleles(alleles, genomeVar.getPos() + shift + 1).alleles(alleles); writer.add(builder.make()); }
@DataProvider() public Iterator<Object[]> variantProvider() { final VariantContextBuilder vc_builder = new VariantContextBuilder("testCode", "chr1", 1, 1, Collections.<Allele>emptyList()); final List<Object[]> variants = new ArrayList<Object[]>(10); variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)) .make(), true}); // SNP variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G, T)) .make(), true}); // SNP variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, AG)) .make(), false}); // INDEL variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G, AG)) .make(), false}); // MIXED variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, star)) .make(), false}); // SYMBOLIC variants.add(new Object[]{vc_builder.stop(2).alleles(Arrays.asList(refAG, T)) .make(), false}); // INDEL variants.add(new Object[]{vc_builder.stop(2).alleles(Arrays.asList(refAG, AT)).make(), false}); // MNP return variants.iterator(); }
/** * Update the attributes of the attributes map in the VariantContextBuilder to reflect the proper * chromosome-based VCF tags based on the current VC produced by builder.make() * * @param builder the VariantContextBuilder we are updating * @param removeStaleValues should we remove stale values from the mapping? */ public static void calculateChromosomeCounts(VariantContextBuilder builder, boolean removeStaleValues) { VariantContext vc = builder.make(); builder.attributes(calculateChromosomeCounts(vc, new HashMap<String, Object>(vc.getAttributes()), removeStaleValues, new HashSet<String>(0))); }
private void writeOne(final VariantContext vc, final String set, final String status) { final Map<String, Object> attrs = new HashMap<>(); if ( SET_KEY != null && set != null ) attrs.put(SET_KEY, set); if ( STATUS_KEY != null && status != null ) attrs.put(STATUS_KEY, status); writer.add(new VariantContextBuilder(vc).attributes(attrs).make()); }
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(); }
/** * Decode the sites level data from this classes decoder * * @param builder * @return */ private final void decodeSiteLoc(final VariantContextBuilder builder) throws IOException { final int contigOffset = decoder.decodeInt(BCF2Type.INT32); final String contig = lookupContigName(contigOffset); builder.chr(contig); this.pos = decoder.decodeInt(BCF2Type.INT32) + 1; // GATK is one based, BCF2 is zero-based final int refLength = decoder.decodeInt(BCF2Type.INT32); builder.start((long)pos); builder.stop((long)(pos + refLength - 1)); // minus one because GATK has closed intervals but BCF2 is open }
/** * Add mask to variant context filters if it covers its location. * @param vc VariantContext * @param genomeLoc genome location * @param maskName name of the mask * @param maskExtension bases beyond the mask * @param locStart if true, start at genome location and end at VariantContext. If false, do the opposite. * @return VariantContext with the mask added if the VariantContext is within the extended mask area */ private VariantContext addMaskIfCoversVariant(VariantContext vc, final GenomeLoc genomeLoc, final String maskName, final int maskExtension, final boolean locStart) { if (doesMaskCoverVariant(vc, genomeLoc, maskName, maskExtension, locStart) ) { final Set<String> filters = new LinkedHashSet<>(vc.getFilters()); filters.add(maskName); vc = new VariantContextBuilder(vc).filters(filters).make(); } return vc; }