Search in sources :

Example 11 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk-protected 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 12 with Transition

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

the class OrientationBiasFiltererUnitTest method assertArtifact.

private boolean assertArtifact(double amPreAdapterQ, final Genotype genotypeTumor, final Transition transition) {
    final Transition transitionComplement = transition.complement();
    boolean result = false;
    // Check whether this genotype is reverse complement or actual artifact mode
    if (genotypeTumor.getAllele(0).basesMatch(String.valueOf(transition.ref())) && genotypeTumor.getAllele(1).basesMatch(String.valueOf(transition.call()))) {
        // not complement (i.e. artifact mode)
        Assert.assertTrue(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_RC_FIELD_NAME).equals(OrientationBiasFilterer.PRE_ADAPTER_METRIC_NOT_ARTIFACT_SCORE));
        Assert.assertTrue(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_FIELD_NAME).equals(amPreAdapterQ));
        Assert.assertEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_ARTIFACT_MODE), String.valueOf(true));
        Assert.assertEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_RC_ARTIFACT_MODE), String.valueOf(false));
        result = true;
    } else if (genotypeTumor.getAllele(0).basesMatch(String.valueOf(transitionComplement.ref())) && genotypeTumor.getAllele(1).basesMatch(String.valueOf(transitionComplement.call()))) {
        //complement
        Assert.assertTrue(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_RC_FIELD_NAME).equals(amPreAdapterQ));
        Assert.assertTrue(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.PRE_ADAPTER_METRIC_FIELD_NAME).equals(OrientationBiasFilterer.PRE_ADAPTER_METRIC_NOT_ARTIFACT_SCORE));
        Assert.assertEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_ARTIFACT_MODE), String.valueOf(false));
        Assert.assertEquals(genotypeTumor.getExtendedAttribute(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_RC_ARTIFACT_MODE), String.valueOf(true));
        result = true;
    }
    return result;
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition)

Example 13 with Transition

use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk-protected 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 14 with Transition

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

the class PreAdapterOrientationScorerUnitTest method testBasicScoring.

/**
     * Note that (due to raw data), this test includes collapsing over libraries (not just the contexts).
     * @throws IOException
     */
@Test
public void testBasicScoring() throws IOException {
    final MetricsFile<SequencingArtifactMetrics.PreAdapterDetailMetrics, Comparable<?>> mf = new MetricsFile<>();
    mf.read(new FileReader(testPreAdapterDetailsMetrics));
    final Map<Transition, Double> scoreMap = PreAdapterOrientationScorer.scoreOrientationBiasMetricsOverContext(mf.getMetrics());
    Assert.assertNotNull(scoreMap);
    Assert.assertEquals(scoreMap.keySet().size(), 12);
    // Ground truth values painstakingly derived manually
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('A', 'C')), 100.0, 1e-6);
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('A', 'G')), 50.5788416297570, 1e-6);
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('A', 'T')), 100.0, 1e-6);
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('C', 'A')), 100.0, 1e-6);
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('C', 'G')), 100.0, 1e-6);
    Assert.assertEquals(scoreMap.get(Transition.transitionOf('C', 'T')), 58.0641821538479, 1e-6);
}
Also used : MetricsFile(htsjdk.samtools.metrics.MetricsFile) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) FileReader(java.io.FileReader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 15 with Transition

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

the class PreAdapterOrientationScorerUnitTest method testBasicCounting.

/**
     * Note that (due to raw data), this test includes collapsing over libraries (not just the contexts).
     * @throws IOException
     */
@Test
public void testBasicCounting() throws IOException {
    final MetricsFile<SequencingArtifactMetrics.PreAdapterDetailMetrics, Comparable<?>> mf = new MetricsFile<>();
    mf.read(new FileReader(testPreAdapterDetailsMetrics));
    final Map<Transition, RealMatrix> countMap = PreAdapterOrientationScorer.countOrientationBiasMetricsOverContext(mf.getMetrics());
    Assert.assertNotNull(countMap);
    Assert.assertEquals(countMap.keySet().size(), 12);
    // Ground truth values painstakingly derived manually from both libraries (hence four values in the expression instead of two)
    // L1 norm can be used since all values are always positive.
    Assert.assertEquals(countMap.get(Transition.transitionOf('A', 'C')).getRowVector(0).getL1Norm(), 2836660 + 2631203 + 240 + 246, 1e-1);
    Assert.assertEquals(countMap.get(Transition.transitionOf('A', 'C')).getRowVector(1).getL1Norm(), 2852491 + 333 + 2646654 + 297, 1e-1);
    Assert.assertEquals(countMap.get(Transition.transitionOf('A', 'G')).getRowVector(0).getL1Norm(), 2631203 + 416 + 2836660 + 481, 1e-1);
    Assert.assertEquals(countMap.get(Transition.transitionOf('A', 'G')).getRowVector(1).getL1Norm(), 2852491 + 404 + 2646654 + 397, 1e-1);
}
Also used : MetricsFile(htsjdk.samtools.metrics.MetricsFile) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) FileReader(java.io.FileReader) 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