use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class SVVariantConsensusDiscovery method discoverVariantsFromConsensus.
// TODO: 12/12/16 does not handle translocation yet
/**
* Produces a VC from a {@link NovelAdjacencyReferenceLocations} (consensus among different assemblies if they all point to the same breakpoint).
*
* @param breakpointPairAndItsEvidence consensus among different assemblies if they all point to the same breakpoint
* @param broadcastReference broadcasted reference
* @throws IOException due to read operations on the reference
*/
public static VariantContext discoverVariantsFromConsensus(final Tuple2<NovelAdjacencyReferenceLocations, Iterable<ChimericAlignment>> breakpointPairAndItsEvidence, final Broadcast<ReferenceMultiSource> broadcastReference) throws IOException {
final NovelAdjacencyReferenceLocations novelAdjacencyReferenceLocations = breakpointPairAndItsEvidence._1;
final Iterable<ChimericAlignment> evidence = breakpointPairAndItsEvidence._2();
final String contig = novelAdjacencyReferenceLocations.leftJustifiedLeftRefLoc.getContig();
final int start = novelAdjacencyReferenceLocations.leftJustifiedLeftRefLoc.getEnd();
final int end = novelAdjacencyReferenceLocations.leftJustifiedRightRefLoc.getStart();
Utils.validateArg(start <= end, "An identified breakpoint pair has left breakpoint positioned to the right of right breakpoint: " + novelAdjacencyReferenceLocations.toString());
final SvType variant = getType(novelAdjacencyReferenceLocations);
final VariantContextBuilder vcBuilder = new VariantContextBuilder().chr(contig).start(start).stop(end).alleles(produceAlleles(novelAdjacencyReferenceLocations, broadcastReference.getValue(), variant)).id(variant.getVariantId()).attribute(VCFConstants.END_KEY, end).attribute(GATKSVVCFHeaderLines.SVTYPE, variant.toString()).attribute(GATKSVVCFHeaderLines.SVLEN, variant.getSVLength());
variant.getTypeSpecificAttributes().forEach(vcBuilder::attribute);
parseComplicationsAndMakeThemAttributeMap(novelAdjacencyReferenceLocations).forEach(vcBuilder::attribute);
getEvidenceRelatedAnnotations(evidence).forEach(vcBuilder::attribute);
return vcBuilder.make();
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class GenotypingEngineUnitTest method init.
@BeforeTest
public void init() {
genotypingEngine = getGenotypingEngine();
final int deletionSize = refAllele.length() - altT.length();
final int start = 1;
final VariantContext deletionVC = new VariantContextBuilder("testDeletion", "1", start, start + deletionSize, allelesDel).make();
genotypingEngine.recordDeletion(deletionSize, deletionVC);
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class FilterApplyingVariantIterator method next.
/**
* Provides the next record from the underlying iterator after applying filter strings generated
* by the set of filters in use by the iterator.
*/
@Override
public VariantContext next() {
final VariantContext ctx = this.iterator.next();
final Set<String> filterStrings = new HashSet<>();
// Collect variant level filters
for (final VariantFilter filter : this.filters) {
final String val = filter.filter(ctx);
if (val != null)
filterStrings.add(val);
}
// Collect genotype level filters in a Map of Sample -> List<filter string>
final ListMap<String, String> gtFilterStrings = new ListMap<>();
final Set<String> variantSamples = new HashSet<>();
for (final Genotype gt : ctx.getGenotypes()) {
if (gt.isCalled() && !gt.isHomRef())
variantSamples.add(gt.getSampleName());
for (final GenotypeFilter filter : gtFilters) {
final String filterString = filter.filter(ctx, gt);
if (filterString != null)
gtFilterStrings.add(gt.getSampleName(), filterString);
}
}
// If all genotypes are filtered apply a site level filter
if (gtFilterStrings.keySet().containsAll(variantSamples)) {
filterStrings.add(ALL_GTS_FILTERED);
}
// Make a builder and set the site level filter appropriately
final VariantContextBuilder builder = new VariantContextBuilder(ctx);
if (filterStrings.isEmpty()) {
builder.passFilters();
} else {
builder.filters(filterStrings);
}
// Apply filters to the necessary genotypes
builder.noGenotypes();
final List<Genotype> newGenotypes = new ArrayList<>(ctx.getNSamples());
for (final Genotype gt : ctx.getGenotypes()) {
final GenotypeBuilder gtBuilder = new GenotypeBuilder(gt);
final List<String> filters = gtFilterStrings.get(gt.getSampleName());
if (filters == null || filters.isEmpty()) {
gtBuilder.filter(PASS_FILTER);
} else {
gtBuilder.filters(filters);
}
newGenotypes.add(gtBuilder.make());
}
builder.genotypes(newGenotypes);
return builder.make();
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class CalculateGenotypePosteriors method apply.
@Override
public void apply(final VariantContext variant, final ReadsContext readsContext, final ReferenceContext referenceContext, final FeatureContext featureContext) {
final Collection<VariantContext> vcs = featureContext.getValues(getDrivingVariantsFeatureInput());
final Collection<VariantContext> otherVCs = featureContext.getValues(supportVariants);
final int missing = supportVariants.size() - otherVCs.size();
for (final VariantContext vc : vcs) {
final VariantContext vc_familyPriors;
final VariantContext vc_bothPriors;
//do family priors first (if applicable)
final VariantContextBuilder builder = new VariantContextBuilder(vc);
//only compute family priors for biallelelic sites
if (!skipFamilyPriors && vc.isBiallelic()) {
final GenotypesContext gc = famUtils.calculatePosteriorGLs(vc);
builder.genotypes(gc);
}
VariantContextUtils.calculateChromosomeCounts(builder, false);
vc_familyPriors = builder.make();
if (!skipPopulationPriors) {
vc_bothPriors = PosteriorProbabilitiesUtils.calculatePosteriorProbs(vc_familyPriors, otherVCs, missing * numRefIfMissing, globalPrior, !ignoreInputSamples, defaultToAC, useACoff);
} else {
final VariantContextBuilder builder2 = new VariantContextBuilder(vc_familyPriors);
VariantContextUtils.calculateChromosomeCounts(builder, false);
vc_bothPriors = builder2.make();
}
vcfWriter.add(vc_bothPriors);
}
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class HomRefBlock method toVariantContext.
/**
* Convert a HomRefBlock into a VariantContext
*
* @param sampleName sample name to give this variant context
* @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.
*/
public VariantContext toVariantContext(String sampleName) {
final VariantContextBuilder vcb = new VariantContextBuilder(getStartingVC());
// clear the attributes
vcb.attributes(new LinkedHashMap<>(2));
vcb.stop(getEnd());
vcb.attribute(VCFConstants.END_KEY, getEnd());
final Genotype genotype = createHomRefGenotype(sampleName);
return vcb.genotypes(genotype).make();
}
Aggregations