Search in sources :

Example 21 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 22 with ReferenceContext

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

the class LikelihoodRankSumTestUnitTest method testReadPos.

@Test
public void testReadPos() {
    final double[] altBestAlleleLL = { -1.0, -2.0 };
    final double[] refBestAlleleLL = { -5.0, -7.0 };
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final List<GATKRead> refReads = Arrays.asList(makeRead(), makeRead());
    final List<GATKRead> altReads = Arrays.asList(makeRead(), makeRead());
    // first two reads are ref, last two are alt, "wrong" likelihoods are -100
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    // modify "good" likelihoods manually
    final LikelihoodMatrix<Allele> matrix = likelihoods.sampleMatrix(0);
    matrix.set(0, 0, refBestAlleleLL[0]);
    matrix.set(0, 1, refBestAlleleLL[1]);
    matrix.set(1, 2, altBestAlleleLL[0]);
    matrix.set(1, 3, altBestAlleleLL[1]);
    final InfoFieldAnnotation ann = new LikelihoodRankSumTest();
    Assert.assertEquals(ann.getDescriptions().size(), 1);
    Assert.assertEquals(ann.getDescriptions().get(0).getID(), GATKVCFConstants.LIKELIHOOD_RANK_SUM_KEY);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), GATKVCFConstants.LIKELIHOOD_RANK_SUM_KEY);
    final ReferenceContext ref = null;
    //middle of the read
    final long position = 5L;
    final VariantContext vc = makeVC(CONTIG, position, REF, ALT);
    final Map<String, Object> annotate = ann.annotate(ref, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { altBestAlleleLL[0], altBestAlleleLL[1] }, new double[] { refBestAlleleLL[0], refBestAlleleLL[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(GATKVCFConstants.LIKELIHOOD_RANK_SUM_KEY), zScoreStr);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 23 with ReferenceContext

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

the class ReadPosRankSumTestUnitTest method testReadPos.

@Test
public void testReadPos() {
    final InfoFieldAnnotation ann = new ReadPosRankSumTest();
    final String key = GATKVCFConstants.READ_POS_RANK_SUM_KEY;
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final int[] startAlts = { 3, 4 };
    final int[] startRefs = { 1, 2 };
    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(), key);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), key);
    final ReferenceContext ref = null;
    //middle of the read
    final long position = 5L;
    final VariantContext vc = makeVC(position);
    final Map<String, Object> annotate = ann.annotate(ref, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { position - startAlts[0], position - startAlts[1] }, new double[] { position - startRefs[0], position - startRefs[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(key), zScoreStr);
    //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> annotateEnd = ann.annotate(ref, vcEnd, likelihoods);
    final double zScoreEnd = mannWhitneyU.test(new double[] { startAlts[0], startAlts[1] }, new double[] { startRefs[0], startRefs[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreEndStr = String.format("%.3f", zScoreEnd);
    Assert.assertEquals(annotateEnd.get(key), zScoreEndStr);
    //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> annotatePastEnd = ann.annotate(ref, vcPastEnd, likelihoods);
    Assert.assertTrue(annotatePastEnd.isEmpty());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) AS_ReadPosRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_ReadPosRankSumTest) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) 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 24 with ReferenceContext

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

the class CoverageUnitTest method testLikelihoods.

@Test
public void testLikelihoods() {
    final Allele REF = Allele.create("T", true);
    final Allele ALT = Allele.create("A");
    final int refDepth = 5;
    final int altDepth = 3;
    final List<GATKRead> refReads = IntStream.range(0, refDepth).mapToObj(n -> makeRead()).collect(Collectors.toList());
    final List<GATKRead> altReads = IntStream.range(0, altDepth).mapToObj(n -> makeRead()).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods("sample1", refReads, altReads, -100.0, -100.0, REF, ALT);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate = new Coverage().annotate(referenceContext, vc, likelihoods);
    Assert.assertEquals(annotate.size(), 1, "size");
    Assert.assertEquals(annotate.keySet(), Collections.singleton(VCFConstants.DEPTH_KEY), "annots");
    final int m = altDepth + refDepth;
    Assert.assertEquals(annotate.get(VCFConstants.DEPTH_KEY), String.valueOf(m));
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) IntStream(java.util.stream.IntStream) Allele(htsjdk.variant.variantcontext.Allele) java.util(java.util) ImmutableMap(com.google.common.collect.ImmutableMap) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) VariantContext(htsjdk.variant.variantcontext.VariantContext) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VCFConstants(htsjdk.variant.vcf.VCFConstants) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Allele(htsjdk.variant.variantcontext.Allele) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) VariantContext(htsjdk.variant.variantcontext.VariantContext) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 25 with ReferenceContext

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

the class ChromosomeCountsUnitTest method testEmptyVC.

@Test
public void testEmptyVC() throws Exception {
    final VariantContext vc = makeEmptyVC();
    final ReferenceContext referenceContext = null;
    final InfoFieldAnnotation cov = new ChromosomeCounts();
    final Map<String, Object> annotate = cov.annotate(referenceContext, vc, null);
    //no genotypes
    Assert.assertTrue(annotate.isEmpty());
}
Also used : ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) 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