Search in sources :

Example 96 with VariantContext

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

the class OrientationBiasFiltererUnitTest method testAnnotateVariantContextWithPreprocessingValues.

@Test
public void testAnnotateVariantContextWithPreprocessingValues() {
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2Vcf));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('G', 'T'));
    final Map<Transition, Double> preAdapterQFakeScoreMap = new HashMap<>();
    final double amGTPreAdapterQ = 20.0;
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(Transition.transitionOf('G', 'T'), amGTPreAdapterQ);
    for (final VariantContext vc : featureDataSource) {
        final VariantContext updatedVariantContext = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(vc, relevantTransitions, preAdapterQFakeScoreMap);
        final Genotype genotypeTumor = updatedVariantContext.getGenotype("TUMOR");
        final Genotype genotypeNormal = updatedVariantContext.getGenotype("NORMAL");
        Assert.assertNotEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.FOB, VCFConstants.EMPTY_ALLELE), VCFConstants.EMPTY_ALLELE);
        Assert.assertNotEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.P_ARTIFACT_FIELD_NAME, VCFConstants.EMPTY_ALLELE), VCFConstants.EMPTY_ALLELE);
        assertArtifact(amGTPreAdapterQ, genotypeTumor, Transition.transitionOf('G', 'T'));
        // The NORMAL is always ref/ref in the example file.
        assertNormal(genotypeNormal);
    }
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) Genotype(htsjdk.variant.variantcontext.Genotype) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 97 with VariantContext

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

the class OrientationBiasUtilsUnitTest method testCountNumTransition.

@Test
public void testCountNumTransition() {
    // Setup the test
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2VcfMore));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('T', 'A'));
    final List<VariantContext> variantContexts = getVariantContexts(featureDataSource);
    // Should be one, since one of the variants was filtered.
    Assert.assertEquals(OrientationBiasUtils.calculateNumTransition("TUMOR", variantContexts, relevantTransitions.first()), 1);
    Assert.assertEquals(OrientationBiasUtils.calculateNumTransition("NORMAL", variantContexts, relevantTransitions.first()), 0);
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 98 with VariantContext

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

the class SVVariantConsensusDiscoveryUnitTest method seeIfItWorks_integrative.

// -----------------------------------------------------------------------------------------------
// Integrative test
// -----------------------------------------------------------------------------------------------
private static void seeIfItWorks_integrative(final Tuple4<AlignedAssembly.AlignmentInterval, AlignedAssembly.AlignmentInterval, NovelAdjacencyReferenceLocations, String> testData, final List<String> expectedAttributeKeys) throws IOException {
    final AlignedAssembly.AlignmentInterval region1 = testData._1();
    final AlignedAssembly.AlignmentInterval region2 = testData._2();
    // hack, as the contig sequence is really not necessary for this test purpose
    final byte[] contigSeq = null;
    final Iterable<ChimericAlignment> evidence = Collections.singletonList(new ChimericAlignment(region1, region2, Collections.emptyList(), testData._4()));
    final NovelAdjacencyReferenceLocations breakpoints = testData._3();
    final VariantContext variantContext = SVVariantConsensusDiscovery.discoverVariantsFromConsensus(new Tuple2<>(breakpoints, evidence), SparkContextFactory.getTestSparkContext().broadcast(SVDiscoveryTestDataProvider.reference));
    final List<String> attributeKeys = variantContext.getAttributes().keySet().stream().sorted().collect(Collectors.toList());
    Assert.assertEquals(attributeKeys, expectedAttributeKeys);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext)

Example 99 with VariantContext

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

the class StructuralVariationDiscoveryPipelineSparkIntegrationTest method svDiscoveryVCFEquivalenceTest.

public static void svDiscoveryVCFEquivalenceTest(final String generatedVCFPath, final String expectedVCFPath, final List<String> attributesToIgnore, final boolean onHDFS) throws Exception {
    VCFFileReader fileReader;
    CloseableIterator<VariantContext> iterator;
    final List<VariantContext> actualVcs;
    if (onHDFS) {
        final File tempLocalVCF = BaseTest.createTempFile("variants", "vcf");
        tempLocalVCF.deleteOnExit();
        BucketUtils.copyFile(generatedVCFPath, tempLocalVCF.getAbsolutePath());
        fileReader = new VCFFileReader(tempLocalVCF, false);
    } else {
        fileReader = new VCFFileReader(new File(generatedVCFPath), false);
    }
    iterator = fileReader.iterator();
    actualVcs = Utils.stream(iterator).collect(Collectors.toList());
    CloserUtil.close(iterator);
    CloserUtil.close(fileReader);
    fileReader = new VCFFileReader(new File(expectedVCFPath), false);
    iterator = fileReader.iterator();
    final List<VariantContext> expectedVcs = Utils.stream(iterator).collect(Collectors.toList());
    CloserUtil.close(iterator);
    CloserUtil.close(fileReader);
    BaseTest.assertCondition(actualVcs, expectedVcs, (a, e) -> VariantContextTestUtils.assertVariantContextsAreEqual(a, e, attributesToIgnore));
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File)

Example 100 with VariantContext

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

the class GenotypeGVCFsIntegrationTest method runGenotypeGVCFSAndAssertSomething.

private void runGenotypeGVCFSAndAssertSomething(String input, File expected, List<String> additionalArguments, BiConsumer<VariantContext, VariantContext> assertion, String reference) throws IOException {
    final File output = createTempFile("genotypegvcf", ".vcf");
    final ArgumentsBuilder args = new ArgumentsBuilder();
    args.addReference(new File(reference)).addArgument("V", input).addOutput(output);
    additionalArguments.forEach(args::add);
    Utils.resetRandomGenerator();
    runCommandLine(args);
    final List<VariantContext> expectedVC = getVariantContexts(expected);
    final List<VariantContext> actualVC = getVariantContexts(output);
    assertForEachElementInLists(actualVC, expectedVC, assertion);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) ArgumentsBuilder(org.broadinstitute.hellbender.utils.test.ArgumentsBuilder) File(java.io.File)

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