use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.
the class PileupSpark method pileupFunction.
private static Function<LocusWalkerContext, String> pileupFunction(List<FeatureInput<Feature>> metadata, boolean outputInsertLength, boolean showVerbose) {
return (Function<LocusWalkerContext, String>) context -> {
AlignmentContext alignmentContext = context.getAlignmentContext();
ReferenceContext referenceContext = context.getReferenceContext();
FeatureContext featureContext = context.getFeatureContext();
final String features = getFeaturesString(featureContext, metadata);
final ReadPileup basePileup = alignmentContext.getBasePileup();
final StringBuilder s = new StringBuilder();
s.append(String.format("%s %s", basePileup.getPileupString((referenceContext.hasBackingDataSource()) ? (char) referenceContext.getBase() : 'N'), features));
if (outputInsertLength) {
s.append(" ").append(insertLengthOutput(basePileup));
}
if (showVerbose) {
s.append(" ").append(createVerboseOutput(basePileup));
}
s.append("\n");
return s.toString();
};
}
use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.
the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnDbSnpSite.
@Test
public void testCoverageAnnotationOnDbSnpSite() 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 path = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
final FeatureInput<VariantContext> dbSNPBinding = new FeatureInput<>(path, "dbsnp", Collections.emptyMap());
final List<FeatureInput<VariantContext>> features = Collections.emptyList();
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 int alt = 5;
final int ref = 3;
final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
final VariantContext vcRS = new FeatureDataSource<VariantContext>(path, null, 0, VariantContext.class).query(loc).next();
final Allele refAllele = vcRS.getReference();
final Allele altAllele = vcRS.getAlternateAllele(0);
final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
final FeatureContext featureContext = when(mock(FeatureContext.class).getValues(dbSNPBinding, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcRS)).getMock();
final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
Assert.assertEquals(resultVC.getID(), vcRS.getID());
}
use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.
the class VariantAnnotatorEngineUnitTest method testCoverageAnnotationOnOverlapSite.
@Test
public void testCoverageAnnotationOnOverlapSite() 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 path = publicTestDir + "Homo_sapiens_assembly19.dbsnp135.chr1_1M.exome_intervals.vcf";
final FeatureInput<VariantContext> dbSNPBinding = null;
final String featureSourceName = "fred";
//we'll just reuse the DBSnp file under a different name
final FeatureInput<VariantContext> fredInput = new FeatureInput<>(path, 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.assertFalse(vcfAnnotationDescriptions.contains(VCFStandardHeaderLines.getInfoLine(VCFConstants.DBSNP_KEY)));
final VCFInfoHeaderLine fredHeaderLine = new VCFInfoHeaderLine(featureSourceName, 0, VCFHeaderLineType.Flag, featureSourceName + " Membership");
Assert.assertTrue(vcfAnnotationDescriptions.contains(fredHeaderLine));
final int alt = 5;
final int ref = 3;
final SimpleInterval loc = new SimpleInterval("1", 69428, 69428);
final VariantContext vcRS = new FeatureDataSource<VariantContext>(path, null, 0, VariantContext.class).query(loc).next();
final Allele refAllele = vcRS.getReference();
final Allele altAllele = vcRS.getAlternateAllele(0);
final VariantContext vcToAnnotate = makeVC(refAllele, altAllele, loc);
final ReadLikelihoods<Allele> likelihoods = makeReadLikelihoods(ref, alt, refAllele, altAllele, loc.getContig(), loc.getStart() - 5);
final FeatureContext featureContext = when(mock(FeatureContext.class).getValues(fredInput, loc.getStart())).thenReturn(Arrays.<VariantContext>asList(vcRS)).getMock();
final VariantContext resultVC = vae.annotateContext(vcToAnnotate, featureContext, null, likelihoods, a -> true);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.DEPTH_KEY), String.valueOf(ref + alt));
Assert.assertEquals(resultVC.getID(), VCFConstants.EMPTY_ID_FIELD);
Assert.assertTrue((boolean) resultVC.getCommonInfo().getAttribute(featureSourceName));
Assert.assertNull(resultVC.getCommonInfo().getAttribute("does not exist"));
}
use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.
the class VariantAnnotatorEngineUnitTest method testAllAnnotations.
@Test
public void testAllAnnotations() throws Exception {
/**
* exclude {@link StrandArtifact} until https://github.com/broadinstitute/gatk/issues/2797 is fixed
* exclude {@link ReferenceBases} until https://github.com/broadinstitute/gatk/issues/2799 is fixed
* */
final List<String> annotationsToExclude = Arrays.asList("StrandArtifact", "ReferenceBases");
final FeatureInput<VariantContext> dbSNPBinding = null;
final List<FeatureInput<VariantContext>> features = Collections.emptyList();
final VariantAnnotatorEngine vae = VariantAnnotatorEngine.ofAllMinusExcluded(annotationsToExclude, dbSNPBinding, features);
Assert.assertFalse(vae.getVCFAnnotationDescriptions().contains(null));
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(VCFConstants.ALLELE_COUNT_KEY), 1);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.ALLELE_FREQUENCY_KEY), 1.0 / 2);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.ALLELE_NUMBER_KEY), 2);
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.FISHER_STRAND_KEY), FisherStrand.makeValueObjectForAnnotation(new int[][] { { ref, 0 }, { alt, 0 } }));
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.NOCALL_CHROM_KEY), 0);
Assert.assertNull(resultVC.getCommonInfo().getAttribute(VCFConstants.RMS_MAPPING_QUALITY_KEY));
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.RAW_RMS_MAPPING_QUALITY_KEY), RMSMappingQuality.formattedValue(0.0));
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(VCFConstants.MAPPING_QUALITY_ZERO_KEY), MappingQualityZero.formattedValue(8));
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.SAMPLE_LIST_KEY), "sample1");
Assert.assertEquals(resultVC.getCommonInfo().getAttribute(GATKVCFConstants.STRAND_ODDS_RATIO_KEY), StrandOddsRatio.formattedValue(StrandOddsRatio.calculateSOR(new int[][] { { ref, 0 }, { alt, 0 } })));
}
use of org.broadinstitute.hellbender.engine.FeatureContext in project gatk by broadinstitute.
the class VariantOverlapAnnotatorUnitTest method testRsIDFeatureContextWithNoDBSnP.
@Test(dataProvider = "AnnotateRsIDData")
public void testRsIDFeatureContextWithNoDBSnP(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, null, "binding");
final VariantContext annotated = annotator.annotateRsID(ctx, toAnnotate);
Assert.assertNotNull(annotated);
//nothing at given position
Assert.assertEquals(annotated, toAnnotate);
}
Aggregations