/** * 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); }
/** * Convert the @likelihoodReadMap to a map of alleles to reads, where each read is mapped uniquely * to the allele for which it has the greatest associated likelihood * * @return a map from each allele to a list of reads that 'support' the allele */ protected Map<Allele, List<GATKSAMRecord>> getAlleleStratifiedReadMap() { final Map<Allele, List<GATKSAMRecord>> alleleReadMap = new HashMap<>(alleles.size()); for (final Allele allele : alleles) alleleReadMap.put(allele, new ArrayList<GATKSAMRecord>()); for (final Map.Entry<GATKSAMRecord, Map<Allele, Double>> entry : likelihoodReadMap.entrySet()) { final MostLikelyAllele bestAllele = getMostLikelyAllele(entry.getValue()); if (bestAllele.isInformative()) alleleReadMap.get(bestAllele.getMostLikelyAllele()).add(entry.getKey()); } return alleleReadMap; }