Search in sources :

Example 6 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk by broadinstitute.

the class OrientationBiasFiltererUnitTest method testAnnotateVariantContextWithFilterValuesMultiArtifact.

@Test
public void testAnnotateVariantContextWithFilterValuesMultiArtifact() {
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2VcfMore));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('G', 'T'));
    relevantTransitions.add(Transition.transitionOf('C', 'T'));
    final Map<Transition, Double> preAdapterQFakeScoreMap = new HashMap<>();
    final double amGTPreAdapterQ = 20.0;
    final double amCTPreAdapterQ = 25.0;
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.first(), amGTPreAdapterQ);
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.last(), amCTPreAdapterQ);
    final List<VariantContext> updatedVariants = new ArrayList<>();
    for (final VariantContext vc : featureDataSource) {
        final VariantContext updatedVariantContext = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(vc, relevantTransitions, preAdapterQFakeScoreMap);
        updatedVariants.add(updatedVariantContext);
    }
    final List<String> sampleNames = updatedVariants.get(0).getSampleNamesOrderedByName();
    // Create a mapping from sample name to a genotype->variant context map
    final Map<String, SortedMap<Genotype, VariantContext>> sampleNameToVariants = OrientationBiasFilterer.createSampleToGenotypeVariantContextSortedMap(sampleNames, updatedVariants);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk by broadinstitute.

the class OrientationBiasFiltererUnitTest method testAnnotateVariantContextWithPreprocessingValues.

@Test
public void testAnnotateVariantContextWithPreprocessingValues() {
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2Vcf));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('G', 'T'));
    final Map<Transition, Double> preAdapterQFakeScoreMap = new HashMap<>();
    final double amGTPreAdapterQ = 20.0;
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(Transition.transitionOf('G', 'T'), amGTPreAdapterQ);
    for (final VariantContext vc : featureDataSource) {
        final VariantContext updatedVariantContext = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(vc, relevantTransitions, preAdapterQFakeScoreMap);
        final Genotype genotypeTumor = updatedVariantContext.getGenotype("TUMOR");
        final Genotype genotypeNormal = updatedVariantContext.getGenotype("NORMAL");
        Assert.assertNotEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.FOB, VCFConstants.EMPTY_ALLELE), VCFConstants.EMPTY_ALLELE);
        Assert.assertNotEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.P_ARTIFACT_FIELD_NAME, VCFConstants.EMPTY_ALLELE), VCFConstants.EMPTY_ALLELE);
        assertArtifact(amGTPreAdapterQ, genotypeTumor, Transition.transitionOf('G', 'T'));
        // The NORMAL is always ref/ref in the example file.
        assertNormal(genotypeNormal);
    }
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) Genotype(htsjdk.variant.variantcontext.Genotype) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 8 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk by broadinstitute.

the class OrientationBiasUtilsUnitTest method testCountNumTransition.

@Test
public void testCountNumTransition() {
    // Setup the test
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2VcfMore));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('T', 'A'));
    final List<VariantContext> variantContexts = getVariantContexts(featureDataSource);
    // Should be one, since one of the variants was filtered.
    Assert.assertEquals(OrientationBiasUtils.calculateNumTransition("TUMOR", variantContexts, relevantTransitions.first()), 1);
    Assert.assertEquals(OrientationBiasUtils.calculateNumTransition("NORMAL", variantContexts, relevantTransitions.first()), 0);
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 9 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk-protected by broadinstitute.

the class OrientationBiasFiltererUnitTest method testCreateSampleToGenotypeVCMap.

@Test
public void testCreateSampleToGenotypeVCMap() {
    // Setup the test
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2VcfMore));
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('G', 'T'));
    relevantTransitions.add(Transition.transitionOf('C', 'T'));
    final Map<Transition, Double> preAdapterQFakeScoreMap = new HashMap<>();
    final double amGTPreAdapterQ = 20.0;
    final double amCTPreAdapterQ = 25.0;
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.first(), amGTPreAdapterQ);
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.last(), amCTPreAdapterQ);
    final List<VariantContext> updatedVariants = new ArrayList<>();
    for (final VariantContext vc : featureDataSource) {
        final VariantContext updatedVariantContext = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(vc, relevantTransitions, preAdapterQFakeScoreMap);
        updatedVariants.add(updatedVariantContext);
    }
    final List<String> sampleNames = updatedVariants.get(0).getSampleNamesOrderedByName();
    // Do the test
    // Create a mapping from sample name to a genotype->variant context map with the second map sorted by p_artifact (i.e. OrientationBiasFilterConstants.P_ARTIFACT_FIELD_NAME)
    final Map<String, SortedMap<Genotype, VariantContext>> sampleNameToVariants = OrientationBiasFilterer.createSampleToGenotypeVariantContextSortedMap(sampleNames, updatedVariants);
    Assert.assertEquals(sampleNameToVariants.keySet().size(), 2);
    Assert.assertTrue(sampleNameToVariants.keySet().contains("TUMOR"));
    Assert.assertTrue(sampleNameToVariants.keySet().contains("NORMAL"));
    Assert.assertEquals(sampleNameToVariants.get("TUMOR").keySet().size(), 8);
    // None of the normal genotypes should have a pvalue, so cannot/shouldn't be added to the sorted map
    Assert.assertEquals(sampleNameToVariants.get("NORMAL").keySet().size(), 0);
    // Check that the sorted map is getting smaller (or same) values of p_artifact and not staying put.
    double previousPArtifact = Double.POSITIVE_INFINITY;
    for (final Genotype genotypeTumor : sampleNameToVariants.get("TUMOR").keySet()) {
        final Double pArtifact = OrientationBiasUtils.getGenotypeDouble(genotypeTumor, OrientationBiasFilterConstants.P_ARTIFACT_FIELD_NAME, Double.POSITIVE_INFINITY);
        Assert.assertNotNull(pArtifact);
        Assert.assertTrue(pArtifact <= previousPArtifact);
        Assert.assertNotEquals(pArtifact, Double.POSITIVE_INFINITY);
    }
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) Genotype(htsjdk.variant.variantcontext.Genotype) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 10 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk-protected by broadinstitute.

the class OrientationBiasFiltererUnitTest method testHighPloidy.

@Test(description = "This test just confirms that the OB filterer does not throw an exception if confronted with high ploidy call.  Also test that it is a superset of the original variant context.")
public void testHighPloidy() {
    final FeatureDataSource<VariantContext> featureDataSource = new FeatureDataSource<>(new File(smallM2HighPloidy));
    // Dummy values for relevant transitions and preAdapter Map
    SortedSet<Transition> relevantTransitions = new TreeSet<>();
    relevantTransitions.add(Transition.transitionOf('G', 'T'));
    relevantTransitions.add(Transition.transitionOf('C', 'T'));
    final Map<Transition, Double> preAdapterQFakeScoreMap = new HashMap<>();
    final double amGTPreAdapterQ = 20.0;
    final double amCTPreAdapterQ = 25.0;
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.first(), amGTPreAdapterQ);
    // preAdapterQ suppression will do nothing.
    preAdapterQFakeScoreMap.put(relevantTransitions.last(), amCTPreAdapterQ);
    for (final VariantContext vc : featureDataSource) {
        final VariantContext updatedVariantContext = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(vc, relevantTransitions, preAdapterQFakeScoreMap);
        final Set<String> originalGenotypeAttributes = vc.getGenotype("TUMOR1").getExtendedAttributes().keySet();
        final Set<String> newGenotypeAttributes = updatedVariantContext.getGenotype("TUMOR1").getExtendedAttributes().keySet();
        Assert.assertTrue(newGenotypeAttributes.containsAll(originalGenotypeAttributes));
        Assert.assertTrue(newGenotypeAttributes.size() == (originalGenotypeAttributes.size() + 2));
        for (final String ga : originalGenotypeAttributes) {
            Assert.assertEquals(updatedVariantContext.getGenotype("TUMOR1").getExtendedAttributes().get(ga), vc.getGenotype("TUMOR1").getExtendedAttributes().get(ga));
        }
    }
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) File(java.io.File) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Transition (org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition)32 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)16 Test (org.testng.annotations.Test)16 VariantContext (htsjdk.variant.variantcontext.VariantContext)14 File (java.io.File)14 FeatureDataSource (org.broadinstitute.hellbender.engine.FeatureDataSource)12 VisibleForTesting (com.google.cloud.dataflow.sdk.repackaged.com.google.common.annotations.VisibleForTesting)6 MetricsFile (htsjdk.samtools.metrics.MetricsFile)6 Genotype (htsjdk.variant.variantcontext.Genotype)6 RealMatrix (org.apache.commons.math3.linear.RealMatrix)6 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)4 htsjdk.variant.vcf (htsjdk.variant.vcf)4 FileReader (java.io.FileReader)4 java.util (java.util)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4