allelesToRetain.contains(p.getKey()))
+ .collect(Collectors.toMap(p->p.getKey(), p->p.getValue()));
+ }
+
+ /**
+ * A utility class that provides ordering information, given best and second best haplotype scores.
+ * If there's a tie between the two alleles when comparing their best haplotype score, the second best haplotype score
+ * is used for breaking the tie. In the case that one allele doesn't have a second best allele, i.e. it has only one
+ * supportive haplotype, its second best score is set as null, and is always considered "worse" than another allele
+ * that has the same best haplotype score, but also has a second best haplotype score.
+ * TODO: in the extremely unlikely case that two alleles, having the same best haplotype score, neither have a second
+ * best haplotype score, the case is undecided.
+ */
+ private static final class AlleleScoredByHaplotypeScores {
+ private final Allele allele;
+ private final Double bestHaplotypeScore;
+ private final Double secondBestHaplotypeScore;
+
+ public AlleleScoredByHaplotypeScores(final Allele allele, final Double bestHaplotypeScore, final Double secondBestHaplotypeScore){
+ this.allele = allele;
+ this.bestHaplotypeScore = bestHaplotypeScore;
+ this.secondBestHaplotypeScore = secondBestHaplotypeScore;
+ }
+
+ public int compareTo(final AlleleScoredByHaplotypeScores other) {
+ if(bestHaplotypeScore > other.bestHaplotypeScore) {
+ return 1;
+ } else if (bestHaplotypeScore < other.bestHaplotypeScore) {
+ return -1;
+ } else {
+ return secondBestHaplotypeScore > other.secondBestHaplotypeScore ? 1 : -1;
+ }
+ }
+
+ public Allele getAllele(){
+ return allele;
+ }
+ }
+
/**
* Reduce the number alternative alleles in a read-likelihoods collection to the maximum-alt-allele user parameter value.
*
@@ -462,7 +579,7 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine> constructHaplotypeMapping(final List originalCalls,
- final Set calledHaplotypes) {
+ final Set calledHaplotypes) {
final Map> haplotypeMap = new HashMap<>(originalCalls.size());
for ( final VariantContext call : originalCalls ) {
// don't try to phase if there is not exactly 1 alternate allele
@@ -674,14 +791,13 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine prepareReadAlleleLikelihoodsForAnnotation(
- final ReadLikelihoods readHaplotypeLikelihoods,
- final Map> perSampleFilteredReadList,
- final GenomeLocParser genomeLocParser,
- final boolean emitReferenceConfidence,
- final Map> alleleMapper,
- final ReadLikelihoods readAlleleLikelihoodsForGenotyping,
- final VariantContext call) {
+ protected ReadLikelihoods prepareReadAlleleLikelihoodsForAnnotation(final ReadLikelihoods readHaplotypeLikelihoods,
+ final Map> perSampleFilteredReadList,
+ final GenomeLocParser genomeLocParser,
+ final boolean emitReferenceConfidence,
+ final Map> alleleMapper,
+ final ReadLikelihoods readAlleleLikelihoodsForGenotyping,
+ final VariantContext call) {
final ReadLikelihoods readAlleleLikelihoodsForAnnotations;
final GenomeLoc loc = genomeLocParser.createGenomeLoc(call);
@@ -744,10 +860,10 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine decomposeHaplotypesIntoVariantContexts(final List haplotypes,
- final ReadLikelihoods readLikelihoods,
- final byte[] ref,
- final GenomeLoc refLoc,
- final List activeAllelesToGenotype) {
+ final ReadLikelihoods readLikelihoods,
+ final byte[] ref,
+ final GenomeLoc refLoc,
+ final List activeAllelesToGenotype) {
final boolean in_GGA_mode = !activeAllelesToGenotype.isEmpty();
// Using the cigar from each called haplotype figure out what events need to be written out in a VCF file
@@ -782,8 +898,8 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine getVCsAtThisLocation(final List haplotypes,
- final int loc,
- final List activeAllelesToGenotype) {
+ final int loc,
+ final List activeAllelesToGenotype) {
// the overlapping events to merge into a common reference view
final List eventsAtThisLoc = new ArrayList<>();
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeLikelihoodCalculatorUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeLikelihoodCalculatorUnitTest.java
index e7a9c9467..27c7ac04e 100644
--- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeLikelihoodCalculatorUnitTest.java
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeLikelihoodCalculatorUnitTest.java
@@ -170,6 +170,15 @@ public class GenotypeLikelihoodCalculatorUnitTest {
}
+ @Test
+ public void testComputeMaxAcceptableAlleleCount(){
+ Assert.assertEquals(1024, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(1, 1024));
+ Assert.assertEquals(44, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(2, 1024));
+ Assert.assertEquals(17, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(3, 1024));
+ Assert.assertEquals(5, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(10, 1024));
+ Assert.assertEquals(3, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(20, 1024));
+ Assert.assertEquals(2, GenotypeLikelihoodCalculators.computeMaxAcceptableAlleleCount(100, 1024));
+ }
// Simple inefficient calculation of the genotype count given the ploidy.
private int calculateGenotypeCount(final int ploidy, final int alleleCount) {
if (ploidy == 0)
diff --git a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/haplotype/Haplotype.java b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/haplotype/Haplotype.java
index 28df151c9..59459b027 100644
--- a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/haplotype/Haplotype.java
+++ b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/haplotype/Haplotype.java
@@ -130,6 +130,7 @@ public class Haplotype extends Allele {
final Haplotype ret = new Haplotype(newBases, isReference());
ret.setCigar(newCigar);
ret.setGenomeLocation(loc);
+ ret.setScore(score);
ret.setAlignmentStartHapwrtRef(newStart + getAlignmentStartHapwrtRef());
return ret;
}