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);
}
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);
}
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());
}
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));
}
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());
}
Aggregations