Search in sources :

Example 1 with VariantContext

use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.

the class FilterByOrientationBias method apply.

/**
     *  Just adds the Pre Adapter Q annotation to the variant and creates a new variant.
     *
     *  Note: the writing of the VCF is not done here, since we need to aggregate once we have OxoQ scores.
     *  Note:  No variant is dropped, if no additional annotation was needed, then the original format field is
     *   preserved
     * @param variant See {@link VariantWalker}
     * @param readsContext See {@link VariantWalker}
     * @param referenceContext See {@link VariantWalker}
     * @param featureContext See {@link VariantWalker}
     */
@Override
public void apply(VariantContext variant, ReadsContext readsContext, ReferenceContext referenceContext, FeatureContext featureContext) {
    final VariantContext updatedVariant = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(variant, relevantTransitions, transitionToPreAdapterScoreMap);
    firstPassVariants.add(updatedVariant);
// See onTraversalSuccess for the actual filtering.
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext)

Example 2 with VariantContext

use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.

the class FilterByOrientationBias method onTraversalSuccess.

@Override
public Object onTraversalSuccess() {
    logger.info("Tagging whether genotypes are in one of the artifact modes.");
    // Calculate how many artifacts need to be cut
    double fdrThreshold = 0.01;
    final List<VariantContext> finalVariants = OrientationBiasFilterer.annotateVariantContextsWithFilterResults(fdrThreshold, relevantTransitions, firstPassVariants, transitionToPreAdapterScoreMap);
    logger.info("Writing variants to VCF...");
    finalVariants.forEach(vcfWriter::add);
    logger.info("Writing a simple summary table...");
    List<String> sampleNames = new ArrayList<>();
    if (finalVariants.size() != 0) {
        sampleNames = finalVariants.get(0).getSampleNamesOrderedByName();
    }
    final List<Pair<String, Transition>> sampleTransitionCombinations = new ArrayList<>();
    for (Transition relevantTransition : relevantTransitions) {
        for (String sampleName : sampleNames) {
            sampleTransitionCombinations.add(Pair.of(sampleName, relevantTransition));
        }
    }
    OrientationBiasUtils.writeOrientationBiasSummaryTable(sampleTransitionCombinations, finalVariants, transitionToPreAdapterScoreMap, new File(outputFile.getAbsolutePath() + SUMMARY_FILE_SUFFIX));
    return null;
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with VariantContext

use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.

the class SVVCFWriter method writeVCF.

/**
     * FASTA and Broadcast references are both required because 2bit Broadcast references currently order their
     * sequence dictionaries in a scrambled order, see https://github.com/broadinstitute/gatk/issues/2037.
     */
public static void writeVCF(final PipelineOptions pipelineOptions, final String vcfFileName, final String fastaReference, final JavaRDD<VariantContext> variantContexts, final Logger logger) {
    final SAMSequenceDictionary referenceSequenceDictionary = new ReferenceMultiSource(pipelineOptions, fastaReference, ReferenceWindowFunctions.IDENTITY_FUNCTION).getReferenceSequenceDictionary(null);
    final List<VariantContext> sortedVariantsList = sortVariantsByCoordinate(variantContexts.collect(), referenceSequenceDictionary);
    logNumOfVarByTypes(sortedVariantsList, logger);
    writeVariants(pipelineOptions, vcfFileName, sortedVariantsList, referenceSequenceDictionary);
}
Also used : ReferenceMultiSource(org.broadinstitute.hellbender.engine.datasources.ReferenceMultiSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary)

Example 4 with VariantContext

use of htsjdk.variant.variantcontext.VariantContext 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);
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContext(htsjdk.variant.variantcontext.VariantContext) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with VariantContext

use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.

the class ApplyVQSRIntegrationTest method testApplyRecalibrationSnpAndIndelTogetherExcludeFiltered.

@Test
public void testApplyRecalibrationSnpAndIndelTogetherExcludeFiltered() throws Exception {
    ArgumentsBuilder args = new ArgumentsBuilder();
    File tempOut = createTempFile("testApplyRecalibrationSnpAndIndelTogetherExcludeFiltered", ".vcf");
    args.add("--variant");
    args.add(new File(getToolTestDataDir() + "VQSR.mixedTest.input.vcf"));
    args.add("-L");
    args.add("20:1000100-1000500");
    args.add("-mode");
    args.add("BOTH");
    args.add("--excludeFiltered");
    args.add("-ts_filter_level");
    args.add("90.0");
    args.add("-tranchesFile ");
    args.add(getToolTestDataDir() + "VQSR.mixedTest.tranches");
    args.add("-recalFile");
    args.add(getToolTestDataDir() + "VQSR.mixedTest.recal.vcf");
    args.addOutput(tempOut);
    runCommandLine(args);
    try (FeatureDataSource<VariantContext> featureSource = new FeatureDataSource<>(tempOut)) {
        for (VariantContext feature : featureSource) {
            // there should only be unfiltered records in the output VCF file
            Assert.assertTrue(feature.isNotFiltered());
        }
    }
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) ArgumentsBuilder(org.broadinstitute.hellbender.utils.test.ArgumentsBuilder) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Aggregations

VariantContext (htsjdk.variant.variantcontext.VariantContext)237 Test (org.testng.annotations.Test)119 File (java.io.File)98 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)68 Allele (htsjdk.variant.variantcontext.Allele)55 Genotype (htsjdk.variant.variantcontext.Genotype)49 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)43 Collectors (java.util.stream.Collectors)43 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)43 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)41 FeatureDataSource (org.broadinstitute.hellbender.engine.FeatureDataSource)36 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)35 java.util (java.util)33 IOException (java.io.IOException)25 Assert (org.testng.Assert)25 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)24 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)22 UserException (org.broadinstitute.hellbender.exceptions.UserException)22 Target (org.broadinstitute.hellbender.tools.exome.Target)22 DataProvider (org.testng.annotations.DataProvider)22