use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.
the class Mutect2IntegrationTest method testTumorOnly.
// run tumor-only using our mini gnomAD on NA12878, which is not a tumor
// we're just making sure nothing blows up
@Test
public void testTumorOnly() throws Exception {
Utils.resetRandomGenerator();
final File unfilteredVcf = createTempFile("unfiltered", ".vcf");
final File filteredVcf = createTempFile("filtered", ".vcf");
final String[] args = { "-I", NA12878_20_21_WGS_bam, "-tumor", "NA12878", "-R", b37_reference_20_21, "-L", "20:10000000-10010000", "-germline_resource", GNOMAD.getAbsolutePath(), "-O", unfilteredVcf.getAbsolutePath() };
runCommandLine(args);
// run FilterMutectCalls
new Main().instanceMain(makeCommandLineArgs(Arrays.asList("-V", unfilteredVcf.getAbsolutePath(), "-O", filteredVcf.getAbsolutePath()), "FilterMutectCalls"));
final long numVariantsBeforeFiltering = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).count();
final long numVariantsPassingFilters = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).filter(vc -> vc.getFilters().isEmpty()).count();
// just a sanity check that this bam has some germline variants on this interval so that our test doesn't pass trivially!
Assert.assertTrue(numVariantsBeforeFiltering > 50);
// every variant on this interval in this sample is in gnomAD
Assert.assertTrue(numVariantsPassingFilters < 2);
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected by broadinstitute.
the class Mutect2IntegrationTest method testPon.
// make a pon with a tumor and then use this pon to call somatic variants on the same tumor
// if the pon is doing its job all calls should be filtered by this pon
@Test(dataProvider = "dreamSyntheticDataSample1")
public void testPon(final File tumorBam, final String tumorSample, final File normalBam, final String normalSample) throws Exception {
Utils.resetRandomGenerator();
final File ponVcf = createTempFile("pon", ".vcf");
final String[] createPonArgs = { "-I", tumorBam.getAbsolutePath(), "-tumor", tumorSample, "-I", normalBam.getAbsolutePath(), "-normal", normalSample, "-R", b37_reference_20_21, "-L", "20", "-O", ponVcf.getAbsolutePath() };
runCommandLine(createPonArgs);
final File unfilteredVcf = createTempFile("unfiltered", ".vcf");
final File filteredVcf = createTempFile("filtered", ".vcf");
final String[] callWithPonArgs = { "-I", tumorBam.getAbsolutePath(), "-tumor", tumorSample, "-I", normalBam.getAbsolutePath(), "-normal", normalSample, "-normal_panel", ponVcf.getAbsolutePath(), "-R", b37_reference_20_21, "-L", "20", "-O", unfilteredVcf.getAbsolutePath() };
runCommandLine(callWithPonArgs);
// run FilterMutectCalls
new Main().instanceMain(makeCommandLineArgs(Arrays.asList("-V", unfilteredVcf.getAbsolutePath(), "-O", filteredVcf.getAbsolutePath()), "FilterMutectCalls"));
final long numVariants = StreamSupport.stream(new FeatureDataSource<VariantContext>(filteredVcf).spliterator(), false).filter(vc -> vc.getFilters().isEmpty()).count();
Assert.assertEquals(numVariants, 0);
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk by broadinstitute.
the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnDBSNPAndOverlapSite.
@Test
public void testCoverageAnnotationOnDBSNPAndOverlapSite() throws Exception {
final List<String> annotationGroupsToUse = Collections.emptyList();
//good one
final List<String> annotationsToUse = Arrays.asList(Coverage.class.getSimpleName());
final List<String> annotationsToExclude = Collections.emptyList();
final String dbSNPPath = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
final FeatureInput<VariantContext> dbSNPBinding = new FeatureInput<>(dbSNPPath, "dbsnp", Collections.emptyMap());
final File fredFile = getTestFile("one_entry_source.vcf");
final String featureSourceName = "fred";
final FeatureInput<VariantContext> fredInput = new FeatureInput<>(fredFile.getAbsolutePath(), featureSourceName, Collections.emptyMap());
final List<FeatureInput<VariantContext>> features = Arrays.asList(fredInput);
final VariantAnnotatorEngine vae = VariantAnnotatorEngine.ofSelectedMinusExcluded(annotationGroupsToUse, annotationsToUse, annotationsToExclude, dbSNPBinding, features);
final Set<VCFHeaderLine> vcfAnnotationDescriptions = vae.getVCFAnnotationDescriptions();
Assert.assertTrue(vcfAnnotationDescriptions.contains(VCFStandardHeaderLines.getInfoLine(VCFConstants.DBSNP_KEY)));
final VCFInfoHeaderLine fredHeaderLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
Assert.assertTrue(vcfAnnotationDescriptions.contains(fredHeaderLine));
final VCFInfoHeaderLine headerLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
Assert.assertTrue(vcfAnnotationDescriptions.contains(headerLine));
final int alt = 5;
final int ref = 3;
final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
final VariantContext vcDbSNP = new FeatureDataSource<VariantContext>(dbSNPPath, null, 0, VariantContext.class).query(loc).next();
final VariantContext vcFred = new FeatureDataSource<VariantContext>(fredFile.getAbsolutePath(), null, 0, VariantContext.class).query(loc).next();
final Allele refAllele = vcDbSNP.getReference();
final Allele altAllele = vcDbSNP.getAlternateAllele(0);
final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
//both features
final FeatureContext featureContext0 = when(mock(FeatureContext.class).getValues(dbSNPBinding, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcDbSNP)).getMock();
final FeatureContext featureContext = when(featureContext0.getValues(fredInput, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcFred)).getMock();
final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
//Check that if has both the DBSNP and Fred annotations
Assert.assertEquals(resultVC.getID(), vcDbSNP.getID());
Assert.assertTrue((boolean) resultVC.getCommonInfo().getAttribute(featureSourceName));
Assert.assertNull(resultVC.getCommonInfo().getAttribute("does not exist"));
}
use of org.broadinstitute.hellbender.engine.FeatureDataSource in project gatk-protected 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);
}
Aggregations