Search in sources :

Example 1 with ReferenceContext

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

the class ExampleReadWalkerWithReferenceSpark method readFunction.

private Function<ReadWalkerContext, String> readFunction() {
    return (Function<ReadWalkerContext, String>) context -> {
        GATKRead read = context.getRead();
        ReferenceContext referenceContext = context.getReferenceContext();
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("Read at %s:%d-%d:\n%s\n", read.getContig(), read.getStart(), read.getEnd(), read.getBasesString()));
        if (referenceContext.hasBackingDataSource())
            sb.append("Reference Context:\n" + new String(referenceContext.getBases()) + "\n");
        sb.append("\n");
        return sb.toString();
    };
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Function(org.apache.spark.api.java.function.Function) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext)

Example 2 with ReferenceContext

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

the class HaplotypeCallerGenotypingEngine method makeAnnotatedCall.

protected VariantContext makeAnnotatedCall(byte[] ref, SimpleInterval refLoc, FeatureContext tracker, SAMFileHeader header, VariantContext mergedVC, ReadLikelihoods<Allele> readAlleleLikelihoods, VariantContext call) {
    final SimpleInterval locus = new SimpleInterval(mergedVC.getContig(), mergedVC.getStart(), mergedVC.getEnd());
    final SimpleInterval refLocInterval = new SimpleInterval(refLoc);
    final ReferenceDataSource refData = new ReferenceMemorySource(new ReferenceBases(ref, refLocInterval), header.getSequenceDictionary());
    final ReferenceContext referenceContext = new ReferenceContext(refData, locus, refLocInterval);
    final VariantContext untrimmedResult = annotationEngine.annotateContext(call, tracker, referenceContext, readAlleleLikelihoods, a -> true);
    return call.getAlleles().size() == mergedVC.getAlleles().size() ? untrimmedResult : GATKVariantContextUtils.reverseTrimAlleles(untrimmedResult);
}
Also used : ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceMemorySource(org.broadinstitute.hellbender.engine.ReferenceMemorySource) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 3 with ReferenceContext

use of org.broadinstitute.hellbender.engine.ReferenceContext 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();
    };
}
Also used : Function(org.apache.spark.api.java.function.Function) AlignmentContext(org.broadinstitute.hellbender.engine.AlignmentContext) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext)

Example 4 with ReferenceContext

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

the class ReadPosRankSumTestUnitTest method testReadPos_Raw.

@Test
public void testReadPos_Raw() {
    final AS_RankSumTest ann = new AS_ReadPosRankSumTest();
    final String key1 = GATKVCFConstants.AS_RAW_READ_POS_RANK_SUM_KEY;
    final String key2 = GATKVCFConstants.AS_READ_POS_RANK_SUM_KEY;
    final int[] startAlts = { 3, 4 };
    final int[] startRefs = { 1, 2 };
    final int readLength = 10;
    final List<GATKRead> refReads = Arrays.asList(makeRead(startRefs[0], 30), makeRead(startRefs[1], 30));
    final List<GATKRead> altReads = Arrays.asList(makeRead(startAlts[0], 30), makeRead(startAlts[1], 30));
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    Assert.assertEquals(ann.getDescriptions().size(), 1);
    Assert.assertEquals(ann.getDescriptions().get(0).getID(), key1);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), key2);
    final ReferenceContext ref = null;
    //middle of the read
    final long position = 5L;
    final VariantContext vc = makeVC(position);
    final Map<String, Object> annotateRaw = ann.annotateRawData(ref, vc, likelihoods);
    final Map<String, Object> annotateNonRaw = ann.annotate(ref, vc, likelihoods);
    final String expected = startAlts[0] + ",1," + startAlts[1] + ",1" + AS_RankSumTest.PRINT_DELIM + startRefs[0] + ",1," + startRefs[1] + ",1";
    Assert.assertEquals(annotateRaw.get(key1), expected);
    Assert.assertEquals(annotateNonRaw.get(key1), expected);
    //past middle
    final long positionEnd = 8L;
    final VariantContext vcEnd = makeVC(positionEnd);
    //Note: past the middle of the read we compute the position from the end.
    final Map<String, Object> annotateEndRaw = ann.annotateRawData(ref, vcEnd, likelihoods);
    final Map<String, Object> annotateEndNonRaw = ann.annotate(ref, vcEnd, likelihoods);
    final String refS = (startRefs[0] + readLength - positionEnd - 1) + ",1," + (startRefs[1] + readLength - positionEnd - 1) + ",1";
    final String altS = (positionEnd - startAlts[1]) + ",1," + (positionEnd - startAlts[0]) + ",1";
    Assert.assertEquals(annotateEndRaw.get(key1), refS + AS_RankSumTest.PRINT_DELIM + altS);
    Assert.assertEquals(annotateEndNonRaw.get(key1), refS + AS_RankSumTest.PRINT_DELIM + altS);
    //past middle
    final long positionPastEnd = 20L;
    final VariantContext vcPastEnd = makeVC(positionPastEnd);
    //Note: past the end of the read, there's nothing
    final Map<String, Object> annotatePastEndRaw = ann.annotateRawData(ref, vcPastEnd, likelihoods);
    final Map<String, Object> annotatePastEndNonRaw = ann.annotate(ref, vcPastEnd, likelihoods);
    Assert.assertTrue(annotatePastEndRaw.isEmpty());
    Assert.assertTrue(annotatePastEndNonRaw.isEmpty());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest)

Example 5 with ReferenceContext

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

the class ReferenceBasesUnitTest method test.

@Test
public void test() {
    final File refFasta = new File(b37_reference_20_21);
    final ReferenceDataSource refDataSource = new ReferenceFileSource(refFasta);
    final ReferenceContext ref = new ReferenceContext(refDataSource, new SimpleInterval("20", 10_000_000, 10_000_200));
    final VariantContext vc = new VariantContextBuilder("source", "20", 10_000_100, 10_000_100, Collections.singleton(Allele.create((byte) 'A', true))).make();
    final String refBases = (String) new ReferenceBases().annotate(ref, vc, null).get(ReferenceBases.REFERENCE_BASES_KEY);
    Assert.assertEquals(refBases, "ACTGCATCCCTTGCATTTCC");
}
Also used : VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceDataSource(org.broadinstitute.hellbender.engine.ReferenceDataSource) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) ReferenceFileSource(org.broadinstitute.hellbender.engine.ReferenceFileSource) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)41 Test (org.testng.annotations.Test)30 VariantContext (htsjdk.variant.variantcontext.VariantContext)17 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)17 ReadLikelihoods (org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods)15 Collectors (java.util.stream.Collectors)13 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)12 Allele (htsjdk.variant.variantcontext.Allele)10 GATKVCFConstants (org.broadinstitute.hellbender.utils.variant.GATKVCFConstants)10 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)9 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)8 java.util (java.util)8 List (java.util.List)8 AS_RMSMappingQuality (org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RMSMappingQuality)8 Assert (org.testng.Assert)8 VCFConstants (htsjdk.variant.vcf.VCFConstants)7 Map (java.util.Map)7 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 MannWhitneyU (org.broadinstitute.hellbender.utils.MannWhitneyU)6