Search in sources :

Example 11 with FeatureContext

use of org.broadinstitute.hellbender.engine.FeatureContext 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"));
}
Also used : FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureInput(org.broadinstitute.hellbender.engine.FeatureInput) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) 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 FeatureContext

use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.

the class VariantOverlapAnnotatorUnitTest method testRsIDFeatureContext.

@Test(dataProvider = "AnnotateRsIDData")
public void testRsIDFeatureContext(final VariantContext toAnnotate, final List<VariantContext> dbSNPRecords, final String expectedID, final boolean expectOverlap) throws Exception {
    final File file = new File(publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf");
    final FeatureContext ctx = new FeatureContext(new FeatureManager(new ArtificialFeatureContainingCommandLineProgram_ForVariantOverlap(file)), new SimpleInterval(toAnnotate));
    final VariantOverlapAnnotator annotator = makeAnnotator(file, "dbsnp");
    final VariantContext annotated = annotator.annotateRsID(ctx, toAnnotate);
    Assert.assertNotNull(annotated);
    //nothing at given position
    Assert.assertEquals(annotated, toAnnotate);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureManager(org.broadinstitute.hellbender.engine.FeatureManager) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 13 with FeatureContext

use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.

the class VariantOverlapAnnotatorUnitTest method testAnnotateOverlapsFeatureContext.

@Test(dataProvider = "AnnotateRsIDData")
public void testAnnotateOverlapsFeatureContext(final VariantContext toAnnotate, final List<VariantContext> records, final String expectedID, final boolean expectOverlap) throws Exception {
    final File file = new File(publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf");
    final FeatureContext ctx = new FeatureContext(new FeatureManager(new ArtificialFeatureContainingCommandLineProgram_ForVariantOverlap(file)), new SimpleInterval(toAnnotate));
    final VariantOverlapAnnotator annotator = makeAnnotator(file, "dbsnp");
    final VariantContext annotated = annotator.annotateOverlaps(ctx, toAnnotate);
    //nothing at given position
    Assert.assertEquals(annotated, toAnnotate);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureManager(org.broadinstitute.hellbender.engine.FeatureManager) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 14 with FeatureContext

use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.

the class VariantAnnotatorEngineUnitTest method testMultipleAnnotations.

@Test
public void testMultipleAnnotations() throws Exception {
    final List<String> annotationsToExclude = Collections.emptyList();
    final FeatureInput<VariantContext> dbSNPBinding = null;
    final List<String> annotationGroupsToUse = Collections.emptyList();
    final List<String> annotationsToUse = Arrays.asList(Coverage.class.getSimpleName(), FisherStrand.class.getSimpleName());
    final List<FeatureInput<VariantContext>> features = Collections.emptyList();
    final VariantAnnotatorEngine vae = VariantAnnotatorEngine.ofSelectedMinusExcluded(annotationGroupsToUse, annotationsToUse, annotationsToExclude, dbSNPBinding, features);
    final int alt = 5;
    final int ref = 3;
    final Allele refAllele = Allele.create("A", true);
    final Allele altAllele = Allele.create("T");
    final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele);
    final VariantContext resultVC = vae.annotateContext(makeVC(refAllele, altAllele), new FeatureContext(), null, likelihoods, a -> true);
    Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
    Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.FISHER_STRAND_KEY), FisherStrand.makeValueObjectForAnnotation(new int[][] { { ref, 0 }, { alt, 0 } }));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.ALLELE_COUNT_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.ALLELE_FREQUENCY_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.ALLELE_NUMBER_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.NOCALL_CHROM_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.RMS_MAPPING_QUALITY_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.MAPPING_QUALITY_ZERO_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.SAMPLE_LIST_KEY));
    Assert.assertNull(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.STRAND_ODDS_RATIO_KEY));
}
Also used : FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureInput(org.broadinstitute.hellbender.engine.FeatureInput) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 15 with FeatureContext

use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.

the class VariantOverlapAnnotatorUnitTest method testRsIDFeatureContextWith2Sets.

@Test(dataProvider = "AnnotateRsIDData")
public void testRsIDFeatureContextWith2Sets(final VariantContext toAnnotate, final List<VariantContext> dbSNPRecords, final String expectedID, final boolean expectOverlap) throws Exception {
    final File file = new File(publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf");
    final FeatureContext ctx = new FeatureContext(new FeatureManager(new ArtificialFeatureContainingCommandLineProgram_ForVariantOverlap(file)), new SimpleInterval(toAnnotate));
    final VariantOverlapAnnotator annotator = makeAnnotator(file, "dbsnp", "binding");
    final VariantContext annotated = annotator.annotateRsID(ctx, toAnnotate);
    Assert.assertNotNull(annotated);
    //nothing at given position
    Assert.assertEquals(annotated, toAnnotate);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) FeatureManager(org.broadinstitute.hellbender.engine.FeatureManager) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

FeatureContext (org.broadinstitute.hellbender.engine.FeatureContext)16 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)11 Test (org.testng.annotations.Test)11 File (java.io.File)9 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)8 VariantContext (htsjdk.variant.variantcontext.VariantContext)7 FeatureInput (org.broadinstitute.hellbender.engine.FeatureInput)6 FeatureManager (org.broadinstitute.hellbender.engine.FeatureManager)5 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)5 VCFInfoHeaderLine (htsjdk.variant.vcf.VCFInfoHeaderLine)4 Collectors (java.util.stream.Collectors)4 AlignmentContext (org.broadinstitute.hellbender.engine.AlignmentContext)3 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)2 Genotype (htsjdk.variant.variantcontext.Genotype)2 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)2 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)2 VCFConstants (htsjdk.variant.vcf.VCFConstants)2