Search in sources :

Example 11 with FeatureDataSource

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

the class AnnotateVcfWithExpectedAlleleFractionIntegrationTest method test.

// run with made-up mixing fractions and the doctored 2-sample version of DREAM challenge sample 4
// described in {@link CalculateMixingFractionsIntegrationTest}
@Test
public void test() {
    final File table = createTempFile("mixing", ".table");
    final File outputVcf = createTempFile("output", ".vcf");
    //as in the input vcf
    final String sample1 = "SAMPLE1";
    //as in the input vcf
    final String sample2 = "SAMPLE2";
    final double fraction1 = 0.4;
    final double fraction2 = 0.6;
    MixingFraction.writeMixingFractions(Arrays.asList(new MixingFraction(sample1, fraction1), new MixingFraction(sample2, fraction2)), table);
    final String[] arguments = { "-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME, INPUT_VCF.getAbsolutePath(), "-" + AnnotateVcfWithExpectedAlleleFraction.MIXING_FRACTIONS_TABLE_NAME, table.getAbsolutePath(), "-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME, outputVcf.getAbsolutePath() };
    runCommandLine(arguments);
    final List<VariantContext> input = StreamSupport.stream(new FeatureDataSource<VariantContext>(INPUT_VCF).spliterator(), false).collect(Collectors.toList());
    final List<VariantContext> output = StreamSupport.stream(new FeatureDataSource<VariantContext>(outputVcf).spliterator(), false).collect(Collectors.toList());
    Assert.assertEquals(input.size(), output.size());
    final List<String> inputKeys = input.stream().map(vc -> keyForVariant(vc)).collect(Collectors.toList());
    final List<String> outputKeys = output.stream().map(vc -> keyForVariant(vc)).collect(Collectors.toList());
    Assert.assertEquals(inputKeys, outputKeys);
    final List<Double> alleleFractions = output.stream().map(vc -> vc.getAttributeAsDouble(AnnotateVcfWithExpectedAlleleFraction.EXPECTED_ALLELE_FRACTION_NAME, -1)).collect(Collectors.toList());
    // the first few -- 0.2 is sample1 is het, 0.3 is sample 2 is het, 0.5 if both are het
    final List<Double> firstSeveralAlleleFractionsByHand = Arrays.asList(0.2, 0.2, 0.3, 0.2, 0.3, 0.5, 0.3, 0.2, 0.3, 0.3);
    Assert.assertEquals(alleleFractions.subList(0, firstSeveralAlleleFractionsByHand.size()), firstSeveralAlleleFractionsByHand);
    // hom var + het
    Assert.assertEquals(alleleFractions.get(16), 0.7);
    // het + hom var
    Assert.assertEquals(alleleFractions.get(18), 0.8);
    //both hom ref
    Assert.assertEquals(alleleFractions.get(26), 0.0);
}
Also used : Arrays(java.util.Arrays) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) File(java.io.File) AnnotateVcfWithExpectedAlleleFraction(org.broadinstitute.hellbender.tools.walkers.validation.AnnotateVcfWithExpectedAlleleFraction) List(java.util.List) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Assert(org.testng.Assert) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) StreamSupport(java.util.stream.StreamSupport) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 12 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 13 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 14 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 15 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)

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