Search in sources :

Example 31 with Transition

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

the class PreAdapterOrientationScorer method countOrientationBiasMetricsOverContext.

/**
     * Gets PreAdapterQ collapsed over contexts.
     *
     * rows {PRO, CON} x cols {ref, alt}
     * @param metrics metrics usually read from a picard preadapter detail file.
     * @return mapping to score all orientation bias artifact modes to a PreAdapterQ score.  This score can be used as a bam-file level score for level of artifacts.
     */
@VisibleForTesting
static Map<Transition, RealMatrix> countOrientationBiasMetricsOverContext(final List<SequencingArtifactMetrics.PreAdapterDetailMetrics> metrics) {
    Utils.nonNull(metrics, "Input metrics cannot be null");
    // Artifact mode to a matrix
    final Map<Transition, RealMatrix> result = new HashMap<>();
    // Collapse over context
    for (SequencingArtifactMetrics.PreAdapterDetailMetrics metric : metrics) {
        final Transition key = Transition.transitionOf(metric.REF_BASE, metric.ALT_BASE);
        result.putIfAbsent(key, new Array2DRowRealMatrix(2, 2));
        final RealMatrix preAdapterCountMatrix = result.get(key);
        preAdapterCountMatrix.addToEntry(PreAdapterOrientationScorer.PRO, PreAdapterOrientationScorer.ALT, metric.PRO_ALT_BASES);
        preAdapterCountMatrix.addToEntry(PreAdapterOrientationScorer.CON, PreAdapterOrientationScorer.ALT, metric.CON_ALT_BASES);
        preAdapterCountMatrix.addToEntry(PreAdapterOrientationScorer.PRO, PreAdapterOrientationScorer.REF, metric.PRO_REF_BASES);
        preAdapterCountMatrix.addToEntry(PreAdapterOrientationScorer.CON, PreAdapterOrientationScorer.REF, metric.CON_REF_BASES);
    }
    return result;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) HashMap(java.util.HashMap) Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) SequencingArtifactMetrics(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.SequencingArtifactMetrics) VisibleForTesting(com.google.cloud.dataflow.sdk.repackaged.com.google.common.annotations.VisibleForTesting)

Example 32 with Transition

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

the class FilterByOrientationBias method onTraversalSuccess.

@Override
public Object onTraversalSuccess() {
    logger.info("Tagging whether genotypes are in one of the artifact modes.");
    // Calculate how many artifacts need to be cut
    double fdrThreshold = 0.01;
    final List<VariantContext> finalVariants = OrientationBiasFilterer.annotateVariantContextsWithFilterResults(fdrThreshold, relevantTransitions, firstPassVariants, transitionToPreAdapterScoreMap);
    logger.info("Writing variants to VCF...");
    finalVariants.forEach(vcfWriter::add);
    logger.info("Writing a simple summary table...");
    List<String> sampleNames = new ArrayList<>();
    if (finalVariants.size() != 0) {
        sampleNames = finalVariants.get(0).getSampleNamesOrderedByName();
    }
    final List<Pair<String, Transition>> sampleTransitionCombinations = new ArrayList<>();
    for (Transition relevantTransition : relevantTransitions) {
        for (String sampleName : sampleNames) {
            sampleTransitionCombinations.add(Pair.of(sampleName, relevantTransition));
        }
    }
    OrientationBiasUtils.writeOrientationBiasSummaryTable(sampleTransitionCombinations, finalVariants, transitionToPreAdapterScoreMap, new File(outputFile.getAbsolutePath() + SUMMARY_FILE_SUFFIX));
    return null;
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) Pair(org.apache.commons.lang3.tuple.Pair)

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