Search in sources :

Example 1 with FeatureDataSource

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

the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnDbSnpSite.

@Test
public void testCoverageAnnotationOnDbSnpSite() 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 path = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
    final FeatureInput<VariantContext> dbSNPBinding = new FeatureInput<>(path, "dbsnp", Collections.emptyMap());
    final List<FeatureInput<VariantContext>> features = Collections.emptyList();
    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 int alt = 5;
    final int ref = 3;
    final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
    final VariantContext vcRS = new FeatureDataSource<VariantContext>(path, null, 0, VariantContext.class).query(loc).next();
    final Allele refAllele = vcRS.getReference();
    final Allele altAllele = vcRS.getAlternateAllele(0);
    final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
    final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
    final FeatureContext featureContext = when(mock(FeatureContext.class).getValues(dbSNPBinding, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcRS)).getMock();
    final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
    Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
    Assert.assertEquals(resultVC.getID(), vcRS.getID());
}
Also used : FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureInput(org.broadinstitute.hellbender.engine.FeatureInput) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 2 with FeatureDataSource

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

the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnOverlapSite.

@Test
public void testCoverageAnnotationOnOverlapSite() 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 path = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
    final FeatureInput<VariantContext> dbSNPBinding = null;
    final String featureSourceName = "fred";
    //we'll just reuse the DBSnp file under a different name
    final FeatureInput<VariantContext> fredInput = new FeatureInput<>(path, 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.assertFalse(vcfAnnotationDescriptions.contains(VCFStandardHeaderLines.getInfoLine(VCFConstants.DBSNP_KEY)));
    final VCFInfoHeaderLine fredHeaderLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
    Assert.assertTrue(vcfAnnotationDescriptions.contains(fredHeaderLine));
    final int alt = 5;
    final int ref = 3;
    final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
    final VariantContext vcRS = new FeatureDataSource<VariantContext>(path, null, 0, VariantContext.class).query(loc).next();
    final Allele refAllele = vcRS.getReference();
    final Allele altAllele = vcRS.getAlternateAllele(0);
    final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
    final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
    final FeatureContext featureContext = when(mock(FeatureContext.class).getValues(fredInput, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcRS)).getMock();
    final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
    Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
    Assert.assertEquals(resultVC.getID(), VCFConstants.EMPTY_ID_FIELD);
    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) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with FeatureDataSource

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

the class VariantContextVariantAdapterTest method testVariantAdapter.

@Test(dataProvider = "VariantDataProvider")
public void testVariantAdapter(final List<GATKVariant> expectedVariantList) {
    // The test suite for reading in VCF files is FeatureDataSourceUnitTest.
    try (FeatureDataSource<VariantContext> featureSource = new FeatureDataSource<>(QUERY_TEST_VCF)) {
        List<GATKVariant> variantList = new ArrayList<>();
        for (VariantContext feature : featureSource) {
            VariantContextVariantAdapter va = new VariantContextVariantAdapter(feature);
            variantList.add(va);
        }
        // Now, test to see that every variant is in in the expected set.
        Assert.assertEquals(variantList.size(), expectedVariantList.size());
        for (GATKVariant v : variantList) {
            boolean matchFound = false;
            for (GATKVariant vv : expectedVariantList) {
                if (VariantUtils.variantsAreEqual(v, vv)) {
                    matchFound = true;
                }
            }
            Assert.assertTrue(matchFound, v.toString());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with FeatureDataSource

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

the class FilterByOrientationBiasIntegrationTest method testHighPloidyRun.

@Test
public void testHighPloidyRun() throws IOException {
    final File outputFile = File.createTempFile("ob_high_ploidy", ".vcf");
    final List<String> arguments = new ArrayList<>();
    arguments.add("-" + FilterByOrientationBias.PRE_ADAPTER_METRICS_DETAIL_FILE_SHORT_NAME);
    arguments.add(preAdapterQFile);
    arguments.add("-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME);
    arguments.add(smallHighDiploid);
    arguments.add("-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME);
    arguments.add(outputFile.getAbsolutePath());
    runCommandLine(arguments);
    Assert.assertTrue(outputFile.exists());
    final List<VariantContext> variantContexts = new ArrayList<>();
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(outputFile);
    for (final VariantContext vc : featureDataSource) {
        variantContexts.add(vc);
    }
    Assert.assertEquals(variantContexts.size(), 1);
}
Also used : ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 5 with FeatureDataSource

use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk 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(org.testng.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)

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