diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java index ad0f2b773..1f31e7cd6 100644 --- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java +++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngine.java @@ -487,7 +487,8 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine excessAlternativeAlleles(final GenotypingLikelihoods genotypeLikelihoods, final int maxAlternativeAlleles) { + @VisibleForTesting + static Set excessAlternativeAlleles(final GenotypingLikelihoods genotypeLikelihoods, final int maxAlternativeAlleles) { final int alleleCount = genotypeLikelihoods.alleleCount(); final int excessAlternativeAlleleCount = Math.max(0, alleleCount - 1 - maxAlternativeAlleles); if (excessAlternativeAlleleCount <= 0) { @@ -539,8 +540,11 @@ public class HaplotypeCallerGenotypingEngine extends GenotypingEngine result = new HashSet<>(excessAlternativeAlleleCount); diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java index f8dd4b39c..25ed5e59e 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGenotypingEngineUnitTest.java @@ -59,10 +59,15 @@ package org.broadinstitute.gatk.tools.walkers.haplotypecaller; import htsjdk.samtools.reference.ReferenceSequenceFile; import htsjdk.variant.variantcontext.*; +import org.broadinstitute.gatk.tools.walkers.genotyper.*; import org.broadinstitute.gatk.utils.BaseTest; import org.broadinstitute.gatk.utils.*; import org.broadinstitute.gatk.utils.collections.Pair; import org.broadinstitute.gatk.utils.fasta.CachingIndexedFastaSequenceFile; +import org.broadinstitute.gatk.utils.genotyper.AlleleList; +import org.broadinstitute.gatk.utils.genotyper.IndexedAlleleList; +import org.broadinstitute.gatk.utils.genotyper.IndexedSampleList; +import org.broadinstitute.gatk.utils.genotyper.ReadLikelihoods; import org.broadinstitute.gatk.utils.haplotype.EventMap; import org.broadinstitute.gatk.utils.haplotype.Haplotype; import org.broadinstitute.gatk.utils.pileup.ReadBackedPileup; @@ -531,4 +536,33 @@ public class HaplotypeCallerGenotypingEngineUnitTest extends BaseTest { Assert.assertEquals(uniqueGroups.size(), expectedNumGroups); Assert.assertEquals(counter, expectedGroupSize); } + + @Test + public void testExcessAlternativeAllelesKeepRef(){ + + // prep data + final Allele ref = Allele.create("A", true); + final Allele altC = Allele.create("C", false); + final Allele altG = Allele.create("G", false); + final Allele altT = Allele.create("T", false); + final AlleleList indexedAlleleList = new IndexedAlleleList<>(altC, altG, altT, ref);// specifically make the ref allele not at index 0 + + final IndexedSampleList indexedSampleList = new IndexedSampleList("Dummy"); + + final List reads = new ArrayList<>(); + for (int i=0; i<10; ++i) { + reads.add(GATKSAMRecord.createRandomRead(101)); + } + final Map> sampleToReads = Collections.singletonMap(indexedSampleList.sampleAt(0), reads); + final ReadLikelihoods readLikelihoods = new ReadLikelihoods<>(indexedSampleList, indexedAlleleList, sampleToReads); + final PloidyModel ploidyModel = new HomogeneousPloidyModel(indexedSampleList, 2); + final GenotypingModel genotypingModel = new InfiniteRandomMatingPopulationModel(); + + final GenotypingLikelihoods genotypeLikelihoods = genotypingModel.calculateLikelihoods(readLikelihoods, new GenotypingData<>(ploidyModel,readLikelihoods)); + + // test + final Set excessAltAlleles = HaplotypeCallerGenotypingEngine.excessAlternativeAlleles(genotypeLikelihoods, 2); + Assert.assertFalse(excessAltAlleles.contains(ref)); + Assert.assertEquals(excessAltAlleles.size(), 1); + } }