示例#1
0
  public Map<String, Object> annotate(
      RefMetaDataTracker tracker,
      AnnotatorCompatible walker,
      ReferenceContext ref,
      Map<String, AlignmentContext> stratifiedContexts,
      VariantContext vc) {
    if (stratifiedContexts.size()
        == 0) // size 0 means that call was made by someone else and we have no data here
    return null;

    if (!vc.isSNP() && !vc.isIndel() && !vc.isMixed()) return null;

    final AlignmentContext context =
        AlignmentContextUtils.joinContexts(stratifiedContexts.values());

    final int contextWingSize = Math.min((ref.getWindow().size() - 1) / 2, MIN_CONTEXT_WING_SIZE);
    final int contextSize = contextWingSize * 2 + 1;

    final int locus =
        ref.getLocus().getStart() + (ref.getLocus().getStop() - ref.getLocus().getStart()) / 2;

    final ReadBackedPileup pileup = context.getBasePileup();

    // Compute all haplotypes consistent with the current read pileup
    final List<Haplotype> haplotypes = computeHaplotypes(pileup, contextSize, locus, vc);

    final MathUtils.RunningAverage scoreRA = new MathUtils.RunningAverage();
    if (haplotypes != null) {
      for (final Genotype genotype : vc.getGenotypes()) {
        final AlignmentContext thisContext = stratifiedContexts.get(genotype.getSampleName());
        if (thisContext != null) {
          final ReadBackedPileup thisPileup = thisContext.getBasePileup();
          if (vc.isSNP())
            scoreRA.add(
                scoreReadsAgainstHaplotypes(
                    haplotypes,
                    thisPileup,
                    contextSize,
                    locus)); // Taking the simple average of all sample's score since the score can
                             // be negative and the RMS doesn't make sense
          else if (vc.isIndel() || vc.isMixed()) {
            Double d = scoreIndelsAgainstHaplotypes(thisPileup);
            if (d == null) return null;
            scoreRA.add(
                d); // Taking the simple average of all sample's score since the score can be
                    // negative and the RMS doesn't make sense
          }
        }
      }
    }

    // annotate the score in the info field
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(getKeyNames().get(0), String.format("%.4f", scoreRA.mean()));
    return map;
  }