Esempio n. 1
0
  public Map<String, Object> annotate(
      final RefMetaDataTracker tracker,
      final AnnotatorCompatible walker,
      final ReferenceContext ref,
      final Map<String, AlignmentContext> stratifiedContexts,
      final VariantContext vc,
      final Map<String, PerReadAlleleLikelihoodMap> perReadAlleleLikelihoodMap) {

    int depth = 0;
    if (stratifiedContexts != null) {
      if (stratifiedContexts.size() == 0) return null;

      for (Map.Entry<String, AlignmentContext> sample : stratifiedContexts.entrySet())
        depth += sample.getValue().getBasePileup().depthOfCoverage();
    } else if (perReadAlleleLikelihoodMap != null) {
      if (perReadAlleleLikelihoodMap.size() == 0) return null;

      for (PerReadAlleleLikelihoodMap maps : perReadAlleleLikelihoodMap.values()) {
        depth += maps.getLikelihoodReadMap().size();
      }
    } else return null;

    Map<String, Object> map = new HashMap<String, Object>();
    map.put(getKeyNames().get(0), String.format("%d", depth));
    return map;
  }
  /**
   * Loop over all of the reads in this likelihood map and realign them to its most likely haplotype
   *
   * @param haplotypes the collection of haplotypes
   * @param paddedReferenceLoc the active region
   */
  public void realignReadsToMostLikelyHaplotype(
      final Collection<Haplotype> haplotypes, final GenomeLoc paddedReferenceLoc) {

    // we need to remap the Alleles back to the Haplotypes; inefficient but unfortunately this is a
    // requirement currently
    final Map<Allele, Haplotype> alleleToHaplotypeMap = new HashMap<>(haplotypes.size());
    Haplotype refHaplotype = null;
    for (final Haplotype haplotype : haplotypes) {
      alleleToHaplotypeMap.put(Allele.create(haplotype.getBases()), haplotype);
      if (refHaplotype == null && haplotype.isReference()) refHaplotype = haplotype;
    }

    final Map<GATKSAMRecord, Map<Allele, Double>> newLikelihoodReadMap =
        new LinkedHashMap<>(likelihoodReadMap.size());
    for (final Map.Entry<GATKSAMRecord, Map<Allele, Double>> entry : likelihoodReadMap.entrySet()) {
      final MostLikelyAllele bestAllele =
          PerReadAlleleLikelihoodMap.getMostLikelyAllele(entry.getValue());
      final GATKSAMRecord alignedToRef =
          AlignmentUtils.createReadAlignedToRef(
              entry.getKey(),
              alleleToHaplotypeMap.get(bestAllele.getMostLikelyAllele()),
              refHaplotype,
              paddedReferenceLoc.getStart(),
              bestAllele.isInformative());
      newLikelihoodReadMap.put(alignedToRef, entry.getValue());
    }

    likelihoodReadMap.clear();
    likelihoodReadMap.putAll(newLikelihoodReadMap);
  }