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;
}
use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk 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;
}
use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk 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));
}
}
}
use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk by broadinstitute.
the class OrientationBiasFiltererUnitTest method testAnnotateVariantContextWithPreprocessingValuesMultiArtifact.
@Test
public void testAnnotateVariantContextWithPreprocessingValuesMultiArtifact() {
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);
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");
// This is mostly just to make sure that nobody breaks the test itself. I.e. that this test will test all tumor genotype paths be artifact or non-artifact.
boolean wasGenotypeTumorTested = false;
// Check whether this genotype is reverse complement or actual artifact mode
wasGenotypeTumorTested |= assertArtifact(amGTPreAdapterQ, genotypeTumor, relevantTransitions.first());
wasGenotypeTumorTested |= assertArtifact(amCTPreAdapterQ, genotypeTumor, relevantTransitions.last());
// Check any variants that are not an artifact mode but are SNP
if (!OrientationBiasUtils.isGenotypeInTransitionsWithComplement(genotypeTumor, relevantTransitions)) {
assertNotTransition(genotypeTumor);
wasGenotypeTumorTested = true;
} else {
// Check attributes common to all variants in artifact mode
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);
}
// The NORMAL is always ref/ref in the example file.
assertNormal(genotypeNormal);
Assert.assertTrue(wasGenotypeTumorTested, "The test seems to be broken... A variant context was tested, but it had no tumor genotype.");
}
}
use of org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition in project gatk 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);
}
Aggregations