Search in sources :

Example 6 with MannWhitneyU

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

the class RankSumTest method annotate.

@Override
public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final ReadLikelihoods<Allele> likelihoods) {
    Utils.nonNull(vc, "vc is null");
    final GenotypesContext genotypes = vc.getGenotypes();
    if (genotypes == null || genotypes.isEmpty()) {
        return Collections.emptyMap();
    }
    final List<Double> refQuals = new ArrayList<>();
    final List<Double> altQuals = new ArrayList<>();
    final int refLoc = vc.getStart();
    if (likelihoods != null) {
        for (final ReadLikelihoods<Allele>.BestAllele<Allele> bestAllele : likelihoods.bestAlleles()) {
            final GATKRead read = bestAllele.read;
            final Allele allele = bestAllele.allele;
            if (bestAllele.isInformative() && isUsableRead(read, refLoc)) {
                final OptionalDouble value = getElementForRead(read, refLoc, bestAllele);
                // Bypass read if the clipping goal is not reached or the refloc is inside a spanning deletion
                if (value.isPresent() && value.getAsDouble() != INVALID_ELEMENT_FROM_READ) {
                    if (allele.isReference()) {
                        refQuals.add(value.getAsDouble());
                    } else if (vc.hasAllele(allele)) {
                        altQuals.add(value.getAsDouble());
                    }
                }
            }
        }
    }
    if (refQuals.isEmpty() && altQuals.isEmpty()) {
        return Collections.emptyMap();
    }
    final MannWhitneyU mannWhitneyU = new MannWhitneyU();
    // we are testing that set1 (the alt bases) have lower quality scores than set2 (the ref bases)
    final MannWhitneyU.Result result = mannWhitneyU.test(Doubles.toArray(altQuals), Doubles.toArray(refQuals), MannWhitneyU.TestType.FIRST_DOMINATES);
    final double zScore = result.getZ();
    if (Double.isNaN(zScore)) {
        return Collections.emptyMap();
    } else {
        return Collections.singletonMap(getKeyNames().get(0), String.format("%.3f", zScore));
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) ReadLikelihoods(org.broadinstitute.hellbender.utils.genotyper.ReadLikelihoods) Allele(htsjdk.variant.variantcontext.Allele) MannWhitneyU(org.broadinstitute.hellbender.utils.MannWhitneyU)

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