Search in sources :

Example 31 with FeatureDataSource

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

the class AnnotateVcfWithBamDepthIntegrationTest method test.

// test on the DREAM bam 1 and accompanying variants
// depths verified manually in IGV
@Test
public void test() {
    final File bam = new File(DREAM_BAMS_DIR, "tumor_1.bam");
    final File vcf = new File(DREAM_VCFS_DIR, "sample_1.vcf");
    final File outputVcf = createTempFile("annotated", ".vcf");
    final String[] arguments = { "-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME, vcf.getAbsolutePath(), "-" + StandardArgumentDefinitions.INPUT_SHORT_NAME, bam.getAbsolutePath(), "-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME, outputVcf.getAbsolutePath() };
    runCommandLine(arguments);
    final List<VariantContext> input = StreamSupport.stream(new FeatureDataSource<VariantContext>(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<Integer> bamDepths = output.stream().map(vc -> vc.getAttributeAsInt(AnnotateVcfWithBamDepth.POOLED_BAM_DEPTH_ANNOTATION_NAME, -1)).collect(Collectors.toList());
    final List<Integer> firstSeveralDepthsFromIGV = Arrays.asList(33, 39, 19, 35, 25, 27);
    Assert.assertEquals(bamDepths.subList(0, firstSeveralDepthsFromIGV.size()), firstSeveralDepthsFromIGV);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Assert(org.testng.Assert) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) StreamSupport(java.util.stream.StreamSupport) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) File(java.io.File) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 32 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)

Example 33 with FeatureDataSource

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

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

the class FilterByOrientationBiasIntegrationTest method testNoVariantsNoSamplesRun.

@Test
public void testNoVariantsNoSamplesRun() throws IOException {
    final File outputFile = File.createTempFile("ob_no_variants_no_sample", ".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(emptyVcfNoSamples);
    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(), 0);
    Assert.assertTrue(FileUtils.sizeOf(outputFile) > 0);
    final File summaryFile = new File(outputFile.getAbsolutePath() + FilterByOrientationBias.SUMMARY_FILE_SUFFIX);
    Assert.assertTrue(summaryFile.exists());
    Assert.assertTrue(FileUtils.sizeOf(summaryFile) > 0);
    final List<OrientationSampleTransitionSummary> summaries = OrientationBiasUtils.readOrientationBiasSummaryTable(summaryFile);
    Assert.assertEquals(summaries.size(), 0);
}
Also used : ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) OrientationSampleTransitionSummary(org.broadinstitute.hellbender.tools.exome.orientationbiasvariantfilter.OrientationSampleTransitionSummary) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 35 with FeatureDataSource

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

the class AnnotateVcfWithBamDepthIntegrationTest method test.

// test on the DREAM bam 1 and accompanying variants
// depths verified manually in IGV
@Test
public void test() {
    final File bam = new File(DREAM_BAMS_DIR, "tumor_1.bam");
    final File vcf = new File(DREAM_VCFS_DIR, "sample_1.vcf");
    final File outputVcf = createTempFile("annotated", ".vcf");
    final String[] arguments = { "-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME, vcf.getAbsolutePath(), "-" + StandardArgumentDefinitions.INPUT_SHORT_NAME, bam.getAbsolutePath(), "-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME, outputVcf.getAbsolutePath() };
    runCommandLine(arguments);
    final List<VariantContext> input = StreamSupport.stream(new FeatureDataSource<VariantContext>(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<Integer> bamDepths = output.stream().map(vc -> vc.getAttributeAsInt(AnnotateVcfWithBamDepth.POOLED_BAM_DEPTH_ANNOTATION_NAME, -1)).collect(Collectors.toList());
    final List<Integer> firstSeveralDepthsFromIGV = Arrays.asList(33, 39, 19, 35, 25, 27);
    Assert.assertEquals(bamDepths.subList(0, firstSeveralDepthsFromIGV.size()), firstSeveralDepthsFromIGV);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Assert(org.testng.Assert) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) StreamSupport(java.util.stream.StreamSupport) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) File(java.io.File) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) 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