Search in sources :

Example 36 with FeatureDataSource

use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.

the class Mutect2IntegrationTest method testTumorOnly.

// run tumor-only using our mini gnomAD on NA12878, which is not a tumor
// we're just making sure nothing blows up
@Test
public void testTumorOnly() throws Exception {
    Utils.resetRandomGenerator();
    final File unfilteredVcf = createTempFile("unfiltered", ".vcf");
    final File filteredVcf = createTempFile("filtered", ".vcf");
    final String[] args = { "-I", NA12878_20_21_WGS_bam, "-tumor", "NA12878", "-R", b37_reference_20_21, "-L", "20:10000000-10010000", "-germline_resource", GNOMAD.getAbsolutePath(), "-O", unfilteredVcf.getAbsolutePath() };
    runCommandLine(args);
    // run FilterMutectCalls
    new Main().instanceMain(makeCommandLineArgs(Arrays.asList("-V", unfilteredVcf.getAbsolutePath(), "-O", filteredVcf.getAbsolutePath()), "FilterMutectCalls"));
    final long numVariantsBeforeFiltering = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).count();
    final long numVariantsPassingFilters = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).filter(vc -> vc.getFilters().isEmpty()).count();
    // just a sanity check that this bam has some germline variants on this interval so that our test doesn't pass trivially!
    Assert.assertTrue(numVariantsBeforeFiltering > 50);
    // every variant on this interval in this sample is in gnomAD
    Assert.assertTrue(numVariantsPassingFilters < 2);
}
Also used : Arrays(java.util.Arrays) ConcordanceSummaryRecord(org.broadinstitute.hellbender.tools.walkers.validation.ConcordanceSummaryRecord) DataProvider(org.testng.annotations.DataProvider) Set(java.util.Set) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) File(java.io.File) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(junit.framework.Assert) Main(org.broadinstitute.hellbender.Main) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) Utils(org.broadinstitute.hellbender.utils.Utils) StreamSupport(java.util.stream.StreamSupport) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) Main(org.broadinstitute.hellbender.Main) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 37 with FeatureDataSource

use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.

the class Mutect2IntegrationTest method testPon.

// make a pon with a tumor and then use this pon to call somatic variants on the same tumor
// if the pon is doing its job all calls should be filtered by this pon
@Test(dataProvider = "dreamSyntheticDataSample1")
public void testPon(final File tumorBam, final String tumorSample, final File normalBam, final String normalSample) throws Exception {
    Utils.resetRandomGenerator();
    final File ponVcf = createTempFile("pon", ".vcf");
    final String[] createPonArgs = { "-I", tumorBam.getAbsolutePath(), "-tumor", tumorSample, "-I", normalBam.getAbsolutePath(), "-normal", normalSample, "-R", b37_reference_20_21, "-L", "20", "-O", ponVcf.getAbsolutePath() };
    runCommandLine(createPonArgs);
    final File unfilteredVcf = createTempFile("unfiltered", ".vcf");
    final File filteredVcf = createTempFile("filtered", ".vcf");
    final String[] callWithPonArgs = { "-I", tumorBam.getAbsolutePath(), "-tumor", tumorSample, "-I", normalBam.getAbsolutePath(), "-normal", normalSample, "-normal_panel", ponVcf.getAbsolutePath(), "-R", b37_reference_20_21, "-L", "20", "-O", unfilteredVcf.getAbsolutePath() };
    runCommandLine(callWithPonArgs);
    // run FilterMutectCalls
    new Main().instanceMain(makeCommandLineArgs(Arrays.asList("-V", unfilteredVcf.getAbsolutePath(), "-O", filteredVcf.getAbsolutePath()), "FilterMutectCalls"));
    final long numVariants = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).filter(vc -> vc.getFilters().isEmpty()).count();
    Assert.assertEquals(numVariants, 0);
}
Also used : Arrays(java.util.Arrays) ConcordanceSummaryRecord(org.broadinstitute.hellbender.tools.walkers.validation.ConcordanceSummaryRecord) DataProvider(org.testng.annotations.DataProvider) Set(java.util.Set) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) File(java.io.File) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(junit.framework.Assert) Main(org.broadinstitute.hellbender.Main) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) Utils(org.broadinstitute.hellbender.utils.Utils) StreamSupport(java.util.stream.StreamSupport) File(java.io.File) Main(org.broadinstitute.hellbender.Main) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 38 with FeatureDataSource

use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk by broadinstitute.

the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnDBSNPAndOverlapSite.

@Test
public void testCoverageAnnotationOnDBSNPAndOverlapSite() throws Exception {
    final List<String> annotationGroupsToUse = Collections.emptyList();
    //good one
    final List<String> annotationsToUse = Arrays.asList(Coverage.class.getSimpleName());
    final List<String> annotationsToExclude = Collections.emptyList();
    final String dbSNPPath = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
    final FeatureInput<VariantContext> dbSNPBinding = new FeatureInput<>(dbSNPPath, "dbsnp", Collections.emptyMap());
    final File fredFile = getTestFile("one_entry_source.vcf");
    final String featureSourceName = "fred";
    final FeatureInput<VariantContext> fredInput = new FeatureInput<>(fredFile.getAbsolutePath(), featureSourceName, Collections.emptyMap());
    final List<FeatureInput<VariantContext>> features = Arrays.asList(fredInput);
    final VariantAnnotatorEngine vae = VariantAnnotatorEngine.ofSelectedMinusExcluded(annotationGroupsToUse, annotationsToUse, annotationsToExclude, dbSNPBinding, features);
    final Set<VCFHeaderLine> vcfAnnotationDescriptions = vae.getVCFAnnotationDescriptions();
    Assert.assertTrue(vcfAnnotationDescriptions.contains(VCFStandardHeaderLines.getInfoLine(VCFConstants.DBSNP_KEY)));
    final VCFInfoHeaderLine fredHeaderLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
    Assert.assertTrue(vcfAnnotationDescriptions.contains(fredHeaderLine));
    final VCFInfoHeaderLine headerLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
    Assert.assertTrue(vcfAnnotationDescriptions.contains(headerLine));
    final int alt = 5;
    final int ref = 3;
    final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
    final VariantContext vcDbSNP = new FeatureDataSource<VariantContext>(dbSNPPath, null, 0, VariantContext.class).query(loc).next();
    final VariantContext vcFred = new FeatureDataSource<VariantContext>(fredFile.getAbsolutePath(), null, 0, VariantContext.class).query(loc).next();
    final Allele refAllele = vcDbSNP.getReference();
    final Allele altAllele = vcDbSNP.getAlternateAllele(0);
    final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
    final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
    //both features
    final FeatureContext featureContext0 = when(mock(FeatureContext.class).getValues(dbSNPBinding, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcDbSNP)).getMock();
    final FeatureContext featureContext = when(featureContext0.getValues(fredInput, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcFred)).getMock();
    final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
    Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
    //Check that if has both the DBSNP and Fred annotations
    Assert.assertEquals(resultVC.getID(), vcDbSNP.getID());
    Assert.assertTrue((boolean) resultVC.getCommonInfo().getAttribute(featureSourceName));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute("does not exist"));
}
Also used : FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureInput(org.broadinstitute.hellbender.engine.FeatureInput) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 39 with FeatureDataSource

use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.

the class HaplotypeCallerIntegrationTest method calculateConcordance.

/*
     * Calculate rough concordance between two vcfs, comparing only the positions, alleles, and the first genotype.
     */
public static double calculateConcordance(final File actual, final File expected) {
    final Set<String> actualVCFKeys = new HashSet<>();
    final Set<String> expectedVCFKeys = new HashSet<>();
    int concordant = 0;
    int discordant = 0;
    try (final FeatureDataSource<VariantContext> actualSource = new FeatureDataSource<>(actual);
        final FeatureDataSource<VariantContext> expectedSource = new FeatureDataSource<>(expected)) {
        for (final VariantContext vc : actualSource) {
            actualVCFKeys.add(keyForVariant(vc));
        }
        for (final VariantContext vc : expectedSource) {
            expectedVCFKeys.add(keyForVariant(vc));
        }
        for (final String vcKey : actualVCFKeys) {
            if (!expectedVCFKeys.contains(vcKey)) {
                ++discordant;
            } else {
                ++concordant;
            }
        }
        for (final String vcKey : expectedVCFKeys) {
            if (!actualVCFKeys.contains(vcKey)) {
                ++discordant;
            }
        }
    }
    return (double) concordant / (double) (concordant + discordant);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) HashSet(java.util.HashSet) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource)

Aggregations

FeatureDataSource (org.broadinstitute.hellbender.engine.FeatureDataSource)39 Test (org.testng.annotations.Test)37 VariantContext (htsjdk.variant.variantcontext.VariantContext)36 File (java.io.File)34 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)19 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)18 Transition (org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition)14 ArrayList (java.util.ArrayList)11 List (java.util.List)10 Genotype (htsjdk.variant.variantcontext.Genotype)8 Arrays (java.util.Arrays)8 Collectors (java.util.stream.Collectors)8 StreamSupport (java.util.stream.StreamSupport)8 Assert (org.testng.Assert)8 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)6 OrientationSampleTransitionSummary (org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationSampleTransitionSummary)6 Set (java.util.Set)4 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)4 Pair (org.apache.commons.lang3.tuple.Pair)4 Main (org.broadinstitute.hellbender.Main)4