Search in sources :

Example 21 with VariantContextBuilder

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();
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype)

Example 22 with VariantContextBuilder

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());
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 23 with VariantContextBuilder

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);
    }
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContext(htsjdk.variant.variantcontext.VariantContext)

Example 24 with VariantContextBuilder

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);
    }
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContext(htsjdk.variant.variantcontext.VariantContext)

Example 25 with VariantContextBuilder

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());
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder)

Aggregations

VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)57 VariantContext (htsjdk.variant.variantcontext.VariantContext)40 Test (org.testng.annotations.Test)26 Allele (htsjdk.variant.variantcontext.Allele)25 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)21 Genotype (htsjdk.variant.variantcontext.Genotype)12 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)7 GenotypeBuilder (htsjdk.variant.variantcontext.GenotypeBuilder)6 GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)6 File (java.io.File)6 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)5 VCFHeader (htsjdk.variant.vcf.VCFHeader)5 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)4 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)4 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3