Search in sources :

Example 26 with FeatureDataSource

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

the class FilterByOrientationBiasIntegrationTest method testMultiallelic.

@Test
public void testMultiallelic() throws IOException {
    final File outputFile = File.createTempFile("ob_ma", ".vcf");
    final List<String> arguments = new ArrayList<>();
    arguments.add("-" + FilterByOrientationBias.PRE_ADAPTER_METRICS_DETAIL_FILE_SHORT_NAME);
    arguments.add(preAdapterQFile);
    arguments.add("-" + FilterByOrientationBias.ARTIFACT_MODES_SHORT_NAME);
    arguments.add("C/T");
    arguments.add("-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME);
    arguments.add(smallMA);
    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);
    }
    // It is important to remember that the filter only looks at the first alternate allele.
    Assert.assertEquals(variantContexts.size(), 5);
    // The first variant should have a null in the been OB filter annotation.
    Assert.assertTrue(variantContexts.get(0).getGenotype(0).getExtendedAttribute("OBAMRC").toString().equals("false"));
    Assert.assertTrue(variantContexts.get(0).getGenotype(0).getExtendedAttribute("OBQRC").toString().equals("100.00"));
    // The second variant should not be filtered
    Assert.assertTrue(variantContexts.get(1).getGenotype(0).getExtendedAttribute("OBAMRC").toString().equals("true"));
    Assert.assertTrue(variantContexts.get(2).getGenotype(0).getExtendedAttribute("GT") == null);
    Assert.assertTrue(Double.parseDouble(variantContexts.get(1).getGenotype(0).getExtendedAttribute("OBQRC").toString()) < 100.0);
    // The third variant should be filtered
    Assert.assertTrue(variantContexts.get(2).getGenotype(0).getExtendedAttribute("OBAMRC").toString().equals("true"));
    Assert.assertTrue(Double.parseDouble(variantContexts.get(2).getGenotype(0).getExtendedAttribute("OBQRC").toString()) < 100.0);
    // fourth is in artifact mode
    Assert.assertTrue(variantContexts.get(3).getGenotype(0).getExtendedAttribute("OBAMRC").toString().equals("false"));
    Assert.assertTrue(variantContexts.get(3).getGenotype(0).getExtendedAttribute("OBAM").toString().equals("true"));
    Assert.assertTrue(Double.parseDouble(variantContexts.get(3).getGenotype(0).getExtendedAttribute("OBQ").toString()) < 100.0);
    Assert.assertTrue(variantContexts.get(4).getGenotype(0).getExtendedAttribute("OBAM").toString().equals("false"));
    Assert.assertTrue(variantContexts.get(4).getGenotype(0).getExtendedAttribute("OBQ").toString().equals("100.00"));
}
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 27 with FeatureDataSource

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

the class FilterByOrientationBiasIntegrationTest method testRun.

@Test
public void testRun() throws IOException {
    final File outputFile = File.createTempFile("ob_", ".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(smallM2VcfMore);
    arguments.add("-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME);
    arguments.add(outputFile.getAbsolutePath());
    runCommandLine(arguments);
    Assert.assertTrue(outputFile.exists());
    final File summaryFile = new File(outputFile.getAbsolutePath() + FilterByOrientationBias.SUMMARY_FILE_SUFFIX);
    Assert.assertTrue(summaryFile.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(), 11);
    Assert.assertTrue(FileUtils.sizeOf(outputFile) > 0);
    Assert.assertTrue(FileUtils.sizeOf(summaryFile) > 0);
    boolean is_variant_context_tested = false;
    //  Also, make sure that the variant context has the filter as well.  Not just the genotypes.
    for (final VariantContext vc : variantContexts) {
        final Genotype tumorGenotype = vc.getGenotype("TUMOR");
        Assert.assertTrue((tumorGenotype.getFilters() == null) || (tumorGenotype.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT)) || !OrientationBiasUtils.isGenotypeInTransitionWithComplement(tumorGenotype, Transition.transitionOf('G', 'T')));
        // If we see a filtered genotype, make sure the variant context was filtered as well.
        if ((tumorGenotype.getFilters() != null) && (tumorGenotype.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT))) {
            Assert.assertTrue(vc.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT));
            is_variant_context_tested = true;
        }
        final Genotype normalGenotype = vc.getGenotype("NORMAL");
        Assert.assertTrue((normalGenotype.getFilters() == null) || normalGenotype.getFilters().equals(VCFConstants.UNFILTERED) || normalGenotype.getFilters().equals(VCFConstants.PASSES_FILTERS_v4));
    }
    Assert.assertTrue(is_variant_context_tested, "Unit test may be broken.  Should have tested that variant context contained filter as well as genotype fields.");
    final List<OrientationSampleTransitionSummary> summaries = OrientationBiasUtils.readOrientationBiasSummaryTable(summaryFile);
    Assert.assertEquals(summaries.size(), 2);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).map(s -> s.getArtifactMode()).filter(am -> am.equals(Transition.GtoT)).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactMode()).filter(am -> am.equals(Transition.GtoT)).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
    Assert.assertEquals(summaries.stream().filter(s -> s.getArtifactModeComplement().equals(s.getArtifactMode().complement())).count(), summaries.size());
    Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) FileUtils(org.apache.commons.io.FileUtils) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) IOException(java.io.IOException) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) OrientationBiasFilterConstants(org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationBiasFilterConstants) File(java.io.File) OrientationSampleTransitionSummary(org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationSampleTransitionSummary) ArrayList(java.util.ArrayList) List(java.util.List) Assert(org.testng.Assert) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) OrientationBiasUtils(org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationBiasUtils) VCFConstants(htsjdk.variant.vcf.VCFConstants) ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) Genotype(htsjdk.variant.variantcontext.Genotype) OrientationSampleTransitionSummary(org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationSampleTransitionSummary) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 28 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 29 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)

Example 30 with FeatureDataSource

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

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