Search in sources :

Example 26 with SimpleInterval

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

Example 27 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval 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);
}
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 28 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class FragmentCollectionUnitTest method createFromMultiSamplePileup.

@Test
public void createFromMultiSamplePileup() throws Exception {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "10M");
    final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "10M");
    read1.setPosition(new SimpleInterval("22", 200, 210));
    read2.setPosition(new SimpleInterval("22", 208, 218));
    read1.setMatePosition(read2);
    read2.setMatePosition(read1);
    final Locatable loc = new SimpleInterval("22", 208, 208);
    final Map<String, ReadPileup> stratified = new LinkedHashMap<>();
    stratified.put("sample1", new ReadPileup(loc, Arrays.asList(read2), 0));
    stratified.put("sample2", new ReadPileup(loc, Arrays.asList(read1), 9));
    final ReadPileup combined = new ReadPileup(loc, stratified);
    final FragmentCollection<PileupElement> elements = FragmentCollection.create(combined);
    Assert.assertTrue(elements.getSingletonReads().isEmpty());
    Assert.assertEquals(elements.getOverlappingPairs().size(), 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) PileupElement(org.broadinstitute.hellbender.utils.pileup.PileupElement) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Locatable(htsjdk.samtools.util.Locatable) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 29 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class IntervalsSkipListOneContigUnitTest method testEmptyInput.

@Test
public void testEmptyInput() throws Exception {
    List<Locatable> empty = new ArrayList<>();
    final IntervalsSkipListOneContig<Locatable> l = new IntervalsSkipListOneContig<>(empty);
    //try to fool it by using empty contig
    Assert.assertTrue(l.getOverlapping(new SimpleInterval("", 10, 100)).isEmpty());
    Assert.assertTrue(l.getOverlapping(new SimpleInterval("1", 10, 100)).isEmpty());
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 30 with SimpleInterval

use of org.broadinstitute.hellbender.utils.SimpleInterval in project gatk by broadinstitute.

the class IntervalsSkipListOneContigUnitTest method intervals.

@DataProvider(name = "intervals")
public Object[][] intervals() {
    ArrayList<Locatable> input = Lists.newArrayList(new SimpleInterval("1", 10, 100));
    ArrayList<Locatable> empty = new ArrayList<>();
    ArrayList<Locatable> manyOverlapping = Lists.newArrayList(new SimpleInterval("1", 10, 100), // special case: multiple intervals starting at the same place
    new SimpleInterval("1", 20, 50), new SimpleInterval("1", 20, 50), new SimpleInterval("1", 20, 50));
    ArrayList<Locatable> mixInput = Lists.newArrayList(// ends before query interval
    new SimpleInterval("1", 10, 20), // ends in query interval
    new SimpleInterval("1", 10, 60), // equal to query interval
    new SimpleInterval("1", 30, 50), // covered by query interval
    new SimpleInterval("1", 40, 42), // ends after query interval
    new SimpleInterval("1", 45, 60), // starts after query interval
    new SimpleInterval("1", 60, 100));
    ArrayList<Locatable> mixExpected = Lists.newArrayList(// ends in query interval
    new SimpleInterval("1", 10, 60), // equal to query interval
    new SimpleInterval("1", 30, 50), // covered by query interval
    new SimpleInterval("1", 40, 42), // ends after query interval
    new SimpleInterval("1", 45, 60));
    // returns input single SimpleInterval, query range, expected SimpleInterval
    return new Object[][] { // single-point boundary cases
    new Object[] { input, new SimpleInterval("1", 10, 10), input }, new Object[] { input, new SimpleInterval("1", 100, 100), input }, new Object[] { input, new SimpleInterval("1", 9, 9), empty }, new Object[] { input, new SimpleInterval("1", 11, 11), input }, new Object[] { input, new SimpleInterval("1", 99, 99), input }, new Object[] { input, new SimpleInterval("1", 101, 101), empty }, // empty list boundary case
    new Object[] { empty, new SimpleInterval("1", 101, 101), empty }, // different contig
    new Object[] { empty, new SimpleInterval("2", 101, 101), empty }, // input exactly matches the query interval
    new Object[] { input, new SimpleInterval("1", 10, 100), input }, // multiple intervals in the same place (potential edge case for indexing)
    new Object[] { manyOverlapping, new SimpleInterval("1", 20, 20), manyOverlapping }, // input with multiple intervals
    new Object[] { mixInput, new SimpleInterval("1", 30, 50), mixExpected } };
}
Also used : ArrayList(java.util.ArrayList) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Locatable(htsjdk.samtools.util.Locatable) DataProvider(org.testng.annotations.DataProvider)

Aggregations

SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)545 Test (org.testng.annotations.Test)287 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)202 File (java.io.File)102 ArrayList (java.util.ArrayList)66 DataProvider (org.testng.annotations.DataProvider)64 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)60 Collectors (java.util.stream.Collectors)53 java.util (java.util)41 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)40 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)40 UserException (org.broadinstitute.hellbender.exceptions.UserException)39 VariantContext (htsjdk.variant.variantcontext.VariantContext)36 IntStream (java.util.stream.IntStream)34 Target (org.broadinstitute.hellbender.tools.exome.Target)34 IOException (java.io.IOException)32 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)28 Assert (org.testng.Assert)27 Locatable (htsjdk.samtools.util.Locatable)26 List (java.util.List)26