Search in sources :

Example 11 with GenotypesContext

use of htsjdk.variant.variantcontext.GenotypesContext 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

GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)11 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)6 Allele (htsjdk.variant.variantcontext.Allele)4 Genotype (htsjdk.variant.variantcontext.Genotype)3 VariantContext (htsjdk.variant.variantcontext.VariantContext)3 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 GenotypeBuilder (htsjdk.variant.variantcontext.GenotypeBuilder)1 GenotypeLikelihoods (htsjdk.variant.variantcontext.GenotypeLikelihoods)1 VariantContextUtils (htsjdk.variant.variantcontext.VariantContextUtils)1 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)1 VCFConstants (htsjdk.variant.vcf.VCFConstants)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)1 VCFStandardHeaderLines (htsjdk.variant.vcf.VCFStandardHeaderLines)1 VCFUtils (htsjdk.variant.vcf.VCFUtils)1 File (java.io.File)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1