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:
parent
597cc88f33
commit
abb67cfa5e
|
|
@ -1601,7 +1601,8 @@ public class GATKVariantContextUtils {
|
||||||
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
|
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
|
||||||
* @return non-null array of new AD values
|
* @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;
|
final int numADs = indexesOfRelevantAlleles.length;
|
||||||
if ( numADs == originalAD.length )
|
if ( numADs == originalAD.length )
|
||||||
|
|
@ -1610,11 +1611,11 @@ public class GATKVariantContextUtils {
|
||||||
final int[] newAD = new int[numADs];
|
final int[] newAD = new int[numADs];
|
||||||
|
|
||||||
for ( int i = 0; i < numADs; i++ ) {
|
for ( int i = 0; i < numADs; i++ ) {
|
||||||
final int newIndex = indexesOfRelevantAlleles[i];
|
final int oldIndex = indexesOfRelevantAlleles[i];
|
||||||
if ( newIndex >= originalAD.length )
|
if ( oldIndex >= originalAD.length )
|
||||||
newAD[i] = 0;
|
newAD[i] = 0;
|
||||||
else
|
else
|
||||||
newAD[newIndex] = originalAD[i];
|
newAD[i] = originalAD[oldIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
return newAD;
|
return newAD;
|
||||||
|
|
|
||||||
|
|
@ -1662,14 +1662,14 @@ public class GATKVariantContextUtilsUnitTest extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Allele other : otherAlleles) {
|
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,false,true,true),-1);
|
||||||
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,true,false),-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,false,true,false),-1);
|
||||||
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,false,true),-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,false,false,true),-1);
|
||||||
Assert.assertEquals(GATKVariantContextUtils.indexOfAllele(vc,other,true,false,false),-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});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue