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