use of org.broadinstitute.hellbender.engine.FeatureInput 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.FeatureInput 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));
}
use of org.broadinstitute.hellbender.engine.FeatureInput in project gatk by broadinstitute.
the class VariantOverlapAnnotator method annotateOverlaps.
/**
* Add overlap attributes to vcToAnnotate against all overlaps in featureContext
*
* @see #annotateOverlap(java.util.List, String, htsjdk.variant.variantcontext.VariantContext)
* for more information
*
* @param featureContext non-null featureContext, which we will use to update the rsID of vcToAnnotate
* @param vcToAnnotate a variant context to annotate
* @return a VariantContext (may be == to vcToAnnotate) with updated overlaps update fields value
*/
public VariantContext annotateOverlaps(final FeatureContext featureContext, final VariantContext vcToAnnotate) {
if (overlaps.isEmpty()) {
return vcToAnnotate;
}
VariantContext annotated = vcToAnnotate;
final SimpleInterval loc = new SimpleInterval(vcToAnnotate);
for (final Map.Entry<FeatureInput<VariantContext>, String> overlap : overlaps.entrySet()) {
final FeatureInput<VariantContext> fi = overlap.getKey();
final List<VariantContext> vcs = featureContext.getValues(fi, loc.getStart());
annotated = annotateOverlap(vcs, overlap.getValue(), annotated);
}
return annotated;
}
Aggregations