Search in sources :

Example 11 with ReadLikelihoods

use of org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods in project gatk by broadinstitute.

the class MappingQualityZeroUnitTest method testEmptyLikelihoods.

@Test
public void testEmptyLikelihoods() throws Exception {
    final List<GATKRead> reads = Collections.emptyList();
    final Map<String, List<GATKRead>> readsBySample = ImmutableMap.of("sample1", reads);
    final org.broadinstitute.hellbender.utils.genotyper.SampleList sampleList = new IndexedSampleList(Arrays.asList("sample1"));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(Arrays.asList(Allele.create("A")));
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readsBySample);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate = new MappingQualityZero().annotate(referenceContext, vc, likelihoods);
    //strangely,  MappingQualityZero returns 0 if likelihoods is empty
    final int n = 0;
    Assert.assertEquals(annotate.get(VCFConstants.MAPPING_QUALITY_ZERO_KEY), String.valueOf(n));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) VariantContext(htsjdk.variant.variantcontext.VariantContext) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) Allele(htsjdk.variant.variantcontext.Allele) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) List(java.util.List) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Test(org.testng.annotations.Test)

Example 12 with ReadLikelihoods

use of org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods in project gatk by broadinstitute.

the class ClippingRankSumTestUnitTest method testClipping.

@Test
public void testClipping() {
    final int[] refHardClips = { 10, 0 };
    final int[] altHardClips = { 1, 2 };
    final List<GATKRead> refReads = Arrays.stream(refHardClips).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final List<GATKRead> altReads = Arrays.stream(altHardClips).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(SAMPLE_1, refReads, altReads, -100.0, -100.0, REF, ALT);
    final ReferenceContext ref = null;
    final VariantContext vc = makeVC(REF, ALT);
    final InfoFieldAnnotation ann = new ClippingRankSumTest();
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final Map<String, Object> annotate = ann.annotate(ref, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { altHardClips[0], altHardClips[1] }, new double[] { refHardClips[0], refHardClips[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(GATKVCFConstants.CLIPPING_RANK_SUM_KEY), zScoreStr);
    Assert.assertEquals(ann.getDescriptions().size(), 1);
    Assert.assertEquals(ann.getDescriptions().get(0).getID(), GATKVCFConstants.CLIPPING_RANK_SUM_KEY);
    Assert.assertEquals(ann.getKeyNames().size(), 1);
    Assert.assertEquals(ann.getKeyNames().get(0), GATKVCFConstants.CLIPPING_RANK_SUM_KEY);
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) Cigar(htsjdk.samtools.Cigar) Arrays(java.util.Arrays) GATKVCFConstants(org.broadinstitute.hellbender.utils.variant.GATKVCFConstants) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) List(java.util.List) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) Map(java.util.Map) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) Test(org.testng.annotations.Test)

Example 13 with ReadLikelihoods

use of org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods in project gatk by broadinstitute.

the class CoverageUnitTest method testLikelihoodsEmpty.

@Test
public void testLikelihoodsEmpty() throws Exception {
    final List<GATKRead> reads = new ArrayList<>();
    final Map<String, List<GATKRead>> readsBySample = ImmutableMap.of("sample1", reads);
    final org.broadinstitute.hellbender.utils.genotyper.SampleList sampleList = new IndexedSampleList(Arrays.asList("sample1"));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(Arrays.asList(Allele.NO_CALL));
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readsBySample);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate = new Coverage().annotate(referenceContext, vc, likelihoods);
    Assert.assertTrue(annotate.isEmpty());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) VariantContext(htsjdk.variant.variantcontext.VariantContext) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) Allele(htsjdk.variant.variantcontext.Allele) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AlleleList(org.broadinstitute.hellbender.utils.genotyper.AlleleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 14 with ReadLikelihoods

use of org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods in project gatk-protected by broadinstitute.

the class AssemblyBasedCallerUtils method realignReadsToTheirBestHaplotype.

/**
     * Returns a map with the original read as a key and the realigned read as the value.
     * <p>
     *     Missing keys or equivalent key and value pairs mean that the read was not realigned.
     * </p>
     * @return never {@code null}
     */
public static Map<GATKRead, GATKRead> realignReadsToTheirBestHaplotype(final ReadLikelihoods<Haplotype> originalReadLikelihoods, final Haplotype refHaplotype, final Locatable paddedReferenceLoc) {
    final Collection<ReadLikelihoods<Haplotype>.BestAllele<Haplotype>> bestAlleles = originalReadLikelihoods.bestAlleles();
    final Map<GATKRead, GATKRead> result = new HashMap<>(bestAlleles.size());
    for (final ReadLikelihoods<Haplotype>.BestAllele<Haplotype> bestAllele : bestAlleles) {
        final GATKRead originalRead = bestAllele.read;
        final Haplotype bestHaplotype = bestAllele.allele;
        final boolean isInformative = bestAllele.isInformative();
        final GATKRead realignedRead = AlignmentUtils.createReadAlignedToRef(originalRead, bestHaplotype, refHaplotype, paddedReferenceLoc.getStart(), isInformative);
        result.put(originalRead, realignedRead);
    }
    return result;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods)

Example 15 with ReadLikelihoods

use of org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods 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)

Aggregations

ReadLikelihoods (org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods)22 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)17 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)17 Allele (htsjdk.variant.variantcontext.Allele)11 Test (org.testng.annotations.Test)11 GATKVCFConstants (org.broadinstitute.hellbender.utils.variant.GATKVCFConstants)10 VariantContext (htsjdk.variant.variantcontext.VariantContext)9 java.util (java.util)9 Collectors (java.util.stream.Collectors)9 AlleleList (org.broadinstitute.hellbender.utils.genotyper.AlleleList)9 IndexedAlleleList (org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList)9 IndexedSampleList (org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList)9 Assert (org.testng.Assert)7 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)6 VCFConstants (htsjdk.variant.vcf.VCFConstants)6 List (java.util.List)6 GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 TextCigarCodec (htsjdk.samtools.TextCigarCodec)4 Genotype (htsjdk.variant.variantcontext.Genotype)4