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