Search in sources :

Example 1 with MannWhitneyU

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

the class MappingQualityRankSumTestUnitTest method testMQ.

@Test
public void testMQ() {
    final InfoFieldAnnotation ann = new MappingQualityRankSumTest();
    final String key = GATKVCFConstants.MAP_QUAL_RANK_SUM_KEY;
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final int[] altMappingQualities = { 10, 20 };
    final int[] refMappingQualities = { 100, 110 };
    final List<GATKRead> refReads = Arrays.stream(refMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final List<GATKRead> altReads = Arrays.stream(altMappingQualities).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final ReadLikelihoods<Allele> likelihoods = AnnotationArtificialData.makeLikelihoods(sample1, refReads, altReads, -100.0, -100.0, REF, ALT);
    final VariantContext vc = makeVC(REF, ALT);
    final Map<String, Object> annotate = ann.annotate(null, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { altMappingQualities[0], altMappingQualities[1] }, new double[] { refMappingQualities[0], refMappingQualities[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(key), zScoreStr);
    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);
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) Cigar(htsjdk.samtools.Cigar) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) 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) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) 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) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) AS_MappingQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_MappingQualityRankSumTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)

Example 2 with MannWhitneyU

use of org.broadinstitute.hellbender.utils.MannWhitneyU 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 3 with MannWhitneyU

use of org.broadinstitute.hellbender.utils.MannWhitneyU 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 4 with MannWhitneyU

use of org.broadinstitute.hellbender.utils.MannWhitneyU 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 5 with MannWhitneyU

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

the class BaseQualityRankSumTestUnitTest method testBaseQual.

@Test
public void testBaseQual() {
    final InfoFieldAnnotation ann = new BaseQualityRankSumTest();
    final String key = GATKVCFConstants.BASE_QUAL_RANK_SUM_KEY;
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    final int[] altBaseQuals = { 10, 20 };
    final int[] refBaseQuals = { 50, 60 };
    final List<GATKRead> refReads = Arrays.stream(refBaseQuals).mapToObj(i -> makeRead(i)).collect(Collectors.toList());
    final List<GATKRead> altReads = Arrays.stream(altBaseQuals).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 Map<String, Object> annotate = ann.annotate(ref, vc, likelihoods);
    final double zScore = mannWhitneyU.test(new double[] { altBaseQuals[0], altBaseQuals[1] }, new double[] { refBaseQuals[0], refBaseQuals[1] }, MannWhitneyU.TestType.FIRST_DOMINATES).getZ();
    final String zScoreStr = String.format("%.3f", zScore);
    Assert.assertEquals(annotate.get(key), zScoreStr);
    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);
}
Also used : AS_BaseQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_BaseQualityRankSumTest) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) GATKVCFConstants(org.broadinstitute.hellbender.utils.variant.GATKVCFConstants) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) Mockito.when(org.mockito.Mockito.when) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Collectors(java.util.stream.Collectors) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest) List(java.util.List) Assert(org.testng.Assert) Map(java.util.Map) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) Collections(java.util.Collections) org.broadinstitute.hellbender.utils.genotyper(org.broadinstitute.hellbender.utils.genotyper) Mockito.mock(org.mockito.Mockito.mock) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) AS_BaseQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_BaseQualityRankSumTest) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU) AS_BaseQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_BaseQualityRankSumTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)

Aggregations

MannWhitneyU (org.broadinstitute.hellbender.utils.MannWhitneyU)6 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)6 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)5 Test (org.testng.annotations.Test)5 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 AS_RankSumTest (org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)3 ReadLikelihoods (org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods)3 GATKVCFConstants (org.broadinstitute.hellbender.utils.variant.GATKVCFConstants)3 Assert (org.testng.Assert)3 Cigar (htsjdk.samtools.Cigar)2 TextCigarCodec (htsjdk.samtools.TextCigarCodec)2 ArtificialReadUtils (org.broadinstitute.hellbender.utils.read.ArtificialReadUtils)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Allele (htsjdk.variant.variantcontext.Allele)1 GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)1