Fixes for bugs uncovered by unit tests
This commit is contained in:
parent
b07106b3a7
commit
0a2dded093
|
|
@ -102,17 +102,24 @@ public class AlleleBiasedDownsamplingUtils {
|
|||
}
|
||||
|
||||
private static int scoreAlleleCounts(final int[] alleleCounts) {
|
||||
final int maxIndex = MathUtils.maxElementIndex(alleleCounts);
|
||||
final int maxCount = alleleCounts[maxIndex];
|
||||
if ( alleleCounts.length < 2 )
|
||||
return 0;
|
||||
|
||||
int nonMaxCount = 0;
|
||||
for ( int i = 0; i < 4; i++ ) {
|
||||
if ( i != maxIndex )
|
||||
nonMaxCount += alleleCounts[i];
|
||||
}
|
||||
// sort the counts (in ascending order)
|
||||
final int[] alleleCountsCopy = alleleCounts.clone();
|
||||
Arrays.sort(alleleCountsCopy);
|
||||
|
||||
// try to get the best score: in the het case the counts should be equal and in the hom case the non-max should be zero
|
||||
return Math.min(Math.abs(maxCount - nonMaxCount), Math.abs(nonMaxCount));
|
||||
final int maxCount = alleleCountsCopy[alleleCounts.length - 1];
|
||||
final int nextBestCount = alleleCountsCopy[alleleCounts.length - 2];
|
||||
|
||||
int remainderCount = 0;
|
||||
for ( int i = 0; i < alleleCounts.length - 2; i++ )
|
||||
remainderCount += alleleCountsCopy[i];
|
||||
|
||||
// try to get the best score:
|
||||
// - in the het case the counts should be equal with nothing else
|
||||
// - in the hom case the non-max should be zero
|
||||
return Math.min(maxCount - nextBestCount + remainderCount, Math.abs(nextBestCount + remainderCount));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class AlleleBiasedDownsamplingUtilsUnitTest extends BaseTest {
|
|||
actualCounts[3] += addT;
|
||||
|
||||
final int[] results = AlleleBiasedDownsamplingUtils.runSmartDownsampling(actualCounts, (int)(pileupSize * contaminationFraction));
|
||||
Assert.assertTrue(countsAreEqual(actualCounts, targetCounts));
|
||||
Assert.assertTrue(countsAreEqual(results, targetCounts));
|
||||
}
|
||||
|
||||
private static boolean countsAreEqual(final int[] counts1, final int[] counts2) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue