use of org.broadinstitute.hellbender.engine.FeatureDataSource 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);
}
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource 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);
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk by broadinstitute.
the class HaplotypeCallerIntegrationTest method calculateConcordance.
/*
* Calculate rough concordance between two vcfs, comparing only the positions, alleles, and the first genotype.
*/
public static double calculateConcordance(final File actual, final File expected) {
final Set<String> actualVCFKeys = new HashSet<>();
final Set<String> expectedVCFKeys = new HashSet<>();
int concordant = 0;
int discordant = 0;
try (final FeatureDataSource<VariantContext> actualSource = new FeatureDataSource<>(actual);
final FeatureDataSource<VariantContext> expectedSource = new FeatureDataSource<>(expected)) {
for (final VariantContext vc : actualSource) {
actualVCFKeys.add(keyForVariant(vc));
}
for (final VariantContext vc : expectedSource) {
expectedVCFKeys.add(keyForVariant(vc));
}
for (final String vcKey : actualVCFKeys) {
if (!expectedVCFKeys.contains(vcKey)) {
++discordant;
} else {
++concordant;
}
}
for (final String vcKey : expectedVCFKeys) {
if (!actualVCFKeys.contains(vcKey)) {
++discordant;
}
}
}
return (double) concordant / (double) (concordant + discordant);
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.
the class FilterByOrientationBiasIntegrationTest method testRun.
@Test
public void testRun() throws IOException {
final File outputFile = File.createTempFile("ob_", ".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(smallM2VcfMore);
arguments.add("-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME);
arguments.add(outputFile.getAbsolutePath());
runCommandLine(arguments);
Assert.assertTrue(outputFile.exists());
final File summaryFile = new File(outputFile.getAbsolutePath() + FilterByOrientationBias.SUMMARY_FILE_SUFFIX);
Assert.assertTrue(summaryFile.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(), 11);
Assert.assertTrue(FileUtils.sizeOf(outputFile) > 0);
Assert.assertTrue(FileUtils.sizeOf(summaryFile) > 0);
boolean is_variant_context_tested = false;
// Also, make sure that the variant context has the filter as well. Not just the genotypes.
for (final VariantContext vc : variantContexts) {
final Genotype tumorGenotype = vc.getGenotype("TUMOR");
Assert.assertTrue((tumorGenotype.getFilters() == null) || (tumorGenotype.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT)) || !OrientationBiasUtils.isGenotypeInTransitionWithComplement(tumorGenotype, Transition.transitionOf('G', 'T')));
// If we see a filtered genotype, make sure the variant context was filtered as well.
if ((tumorGenotype.getFilters() != null) && (tumorGenotype.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT))) {
Assert.assertTrue(vc.getFilters().contains(OrientationBiasFilterConstants.IS_ORIENTATION_BIAS_CUT));
is_variant_context_tested = true;
}
final Genotype normalGenotype = vc.getGenotype("NORMAL");
Assert.assertTrue((normalGenotype.getFilters() == null) || normalGenotype.getFilters().equals(VCFConstants.UNFILTERED) || normalGenotype.getFilters().equals(VCFConstants.PASSES_FILTERS_v4));
}
Assert.assertTrue(is_variant_context_tested, "Unit test may be broken. Should have tested that variant context contained filter as well as genotype fields.");
final List<OrientationSampleTransitionSummary> summaries = OrientationBiasUtils.readOrientationBiasSummaryTable(summaryFile);
Assert.assertEquals(summaries.size(), 2);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).map(s -> s.getArtifactMode()).filter(am -> am.equals(Transition.GtoT)).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("NORMAL")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactMode()).filter(am -> am.equals(Transition.GtoT)).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
Assert.assertEquals(summaries.stream().filter(s -> s.getArtifactModeComplement().equals(s.getArtifactMode().complement())).count(), summaries.size());
Assert.assertEquals(summaries.stream().filter(s -> s.getSample().equals("TUMOR")).map(s -> s.getArtifactModeComplement()).filter(am -> am.equals(Transition.CtoA)).count(), 1);
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.
the class FilterByOrientationBiasIntegrationTest method testNoVariantsRun.
@Test
public void testNoVariantsRun() throws IOException {
final File outputFile = File.createTempFile("ob_no_variants", ".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(emptyVcf);
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);
final File summaryFile = new File(outputFile.getAbsolutePath() + FilterByOrientationBias.SUMMARY_FILE_SUFFIX);
Assert.assertTrue(summaryFile.exists());
Assert.assertTrue(FileUtils.sizeOf(outputFile) > 0);
Assert.assertTrue(FileUtils.sizeOf(summaryFile) > 0);
final List<OrientationSampleTransitionSummary> summaries = OrientationBiasUtils.readOrientationBiasSummaryTable(summaryFile);
Assert.assertEquals(summaries.size(), 0);
}
Aggregations