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();
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class ReadThreadingAssemblerUnitTest method testAssembleRefAndInsertion.
@Test(dataProvider = "AssembleIntervalsWithVariantData")
public void testAssembleRefAndInsertion(final ReadThreadingAssembler assembler, final SimpleInterval loc, final int nReadsToUse, final int variantSite) {
final byte[] refBases = seq.getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getEnd()).getBases();
for (int insertionLength = 1; insertionLength < 10; insertionLength++) {
final Allele refBase = Allele.create(refBases[variantSite], false);
final Allele altBase = Allele.create(new String(refBases).substring(variantSite, variantSite + insertionLength + 1), true);
final VariantContextBuilder vcb = new VariantContextBuilder("x", loc.getContig(), variantSite, variantSite + insertionLength, Arrays.asList(refBase, altBase));
testAssemblyWithVariant(assembler, refBases, loc, nReadsToUse, vcb.make());
}
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk-protected by broadinstitute.
the class CreateSomaticPanelOfNormals method processVariantsAtSamePosition.
//TODO: this is the old Mutect behavior that just looks for multiple hits
//TODO: we should refine this
private static void processVariantsAtSamePosition(final List<VariantContext> variants, final VariantContextWriter writer) {
if (variants.size() > 1) {
final VariantContext mergedVc = AssemblyBasedCallerUtils.makeMergedVariantContext(variants);
final VariantContext outputVc = new VariantContextBuilder().source(mergedVc.getSource()).loc(mergedVc.getContig(), mergedVc.getStart(), mergedVc.getEnd()).alleles(mergedVc.getAlleles()).make();
writer.add(outputVc);
}
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class ApplyVQSR method apply.
//---------------------------------------------------------------------------------------------------------------
//
// apply
//
//---------------------------------------------------------------------------------------------------------------
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext ref, final FeatureContext featureContext) {
final List<VariantContext> recals = featureContext.getValues(recal, vc.getStart());
final boolean evaluateThisVariant = useASannotations || VariantDataManager.checkVariationClass(vc, MODE);
//vc.isNotFiltered is true for PASS; vc.filtersHaveBeenApplied covers PASS and filters
final boolean variantIsNotFiltered = IGNORE_ALL_FILTERS || vc.isNotFiltered() || (!ignoreInputFilterSet.isEmpty() && ignoreInputFilterSet.containsAll(vc.getFilters()));
if (evaluateThisVariant && variantIsNotFiltered) {
String filterString;
final VariantContextBuilder builder = new VariantContextBuilder(vc);
if (!useASannotations) {
filterString = doSiteSpecificFiltering(vc, recals, builder);
} else {
//allele-specific mode
filterString = doAlleleSpecificFiltering(vc, recals, builder);
}
//for both non-AS and AS modes:
if (filterString.equals(VCFConstants.PASSES_FILTERS_v4)) {
builder.passFilters();
} else if (filterString.equals(VCFConstants.UNFILTERED)) {
builder.unfiltered();
} else {
builder.filters(filterString);
}
final VariantContext outputVC = builder.make();
if (!EXCLUDE_FILTERED || outputVC.isNotFiltered()) {
vcfWriter.add(outputVC);
}
} else {
// valid VC but not compatible with this mode, so just emit the variant untouched
vcfWriter.add(vc);
}
}
use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.
the class VariantDataManager method writeOutRecalibrationTable.
public void writeOutRecalibrationTable(final VariantContextWriter recalWriter, final SAMSequenceDictionary seqDictionary) {
// we need to sort in coordinate order in order to produce a valid VCF
Collections.sort(data, VariantDatum.getComparator(seqDictionary));
// create dummy alleles to be used
List<Allele> alleles = Arrays.asList(Allele.create("N", true), Allele.create("<VQSR>", false));
for (final VariantDatum datum : data) {
if (VRAC.useASannotations)
//use the alleles to distinguish between multiallelics in AS mode
alleles = Arrays.asList(datum.referenceAllele, datum.alternateAllele);
VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(), datum.loc.getStart(), datum.loc.getEnd(), alleles);
builder.attribute(VCFConstants.END_KEY, datum.loc.getEnd());
builder.attribute(GATKVCFConstants.VQS_LOD_KEY, String.format("%.4f", datum.lod));
builder.attribute(GATKVCFConstants.CULPRIT_KEY, (datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));
if (datum.atTrainingSite)
builder.attribute(GATKVCFConstants.POSITIVE_LABEL_KEY, true);
if (datum.atAntiTrainingSite)
builder.attribute(GATKVCFConstants.NEGATIVE_LABEL_KEY, true);
recalWriter.add(builder.make());
}
}
Aggregations