Fixed bug in generating AD values when new alleles are present for genotpying GVCFs.

This was a dumb mistake that wasn't well tested (but is now).
This commit is contained in:
Eric Banks 2014-02-09 15:15:19 -05:00
parent 597cc88f33
commit abb67cfa5e
2 changed files with 17 additions and 6 deletions

View File

@ -1601,7 +1601,8 @@ public class GATKVariantContextUtils {
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
* @return non-null array of new AD values
*/
private static int[] generateAD(final int[] originalAD, final int[] indexesOfRelevantAlleles) {
protected static int[] generateAD(final int[] originalAD, final int[] indexesOfRelevantAlleles) {
if ( originalAD == null || indexesOfRelevantAlleles == null ) throw new IllegalArgumentException("The list of input AD values and alleles must not be null");
final int numADs = indexesOfRelevantAlleles.length;
if ( numADs == originalAD.length )
@ -1610,11 +1611,11 @@ public class GATKVariantContextUtils {
final int[] newAD = new int[numADs];
for ( int i = 0; i < numADs; i++ ) {
final int newIndex = indexesOfRelevantAlleles[i];
if ( newIndex >= originalAD.length )
final int oldIndex = indexesOfRelevantAlleles[i];
if ( oldIndex >= originalAD.length )
newAD[i] = 0;
else
newAD[newIndex] = originalAD[i];
newAD[i] = originalAD[oldIndex];
}
return newAD;

View File

@ -1662,14 +1662,14 @@ public class GATKVariantContextUtilsUnitTest extends BaseTest {
}
for (final Allele other : otherAlleles) {
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,true,true),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc, other, true, true, true), -1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,false,true,true),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,true,false),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,false,true,false),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,false,true),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,false,false,true),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,false,false),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,false,false,false),-1);
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc, other, false, false, false),-1);
}
}
@ -1708,5 +1708,15 @@ public class GATKVariantContextUtilsUnitTest extends BaseTest {
}
};
}
@Test
public void testGenerateADWithNewAlleles() {
final int[] originalAD = new int[] {1,2,0};
final int[] indexesOfRelevantAlleles = new int[] {0,1,2,2};
final int[] newAD = GATKVariantContextUtils.generateAD(originalAD, indexesOfRelevantAlleles);
Assert.assertEquals(newAD, new int[]{1,2,0,0});
}
}