use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.
the class AlleleListUnitTest method testShufflePermutation.
@Test(dataProvider = "singleAlleleListData", dependsOnMethods = { "testAsList", "testEquals" })
public void testShufflePermutation(final List<Allele> alleles1) {
final AlleleList<Allele> originalAlleleList = new IndexedAlleleList<>(alleles1);
if (originalAlleleList.numberOfAlleles() <= 1) {
//return because this input is invalid for this test
return;
}
final Allele[] targetAlleleArray = originalAlleleList.asListOfAlleles().toArray(new Allele[originalAlleleList.numberOfAlleles()]);
final int[] fromIndex = new int[targetAlleleArray.length];
for (int i = 0; i < fromIndex.length; i++) fromIndex[i] = i;
for (int i = 0; i < targetAlleleArray.length - 1; i++) {
final int swapIndex = rnd.nextInt(targetAlleleArray.length - i - 1);
final int otherIndex = fromIndex[swapIndex + i + 1];
final Allele other = targetAlleleArray[swapIndex + i + 1];
fromIndex[swapIndex + i + 1] = fromIndex[i];
fromIndex[i] = otherIndex;
targetAlleleArray[swapIndex + i + 1] = targetAlleleArray[i];
targetAlleleArray[i] = other;
}
final AlleleList<Allele> targetAlleleList = new IndexedAlleleList<>(targetAlleleArray);
final AlleleListPermutation<Allele> permutation = originalAlleleList.permutation(targetAlleleList);
Assert.assertFalse(permutation.isNonPermuted());
AlleleListUnitTester.assertAlleleList(originalAlleleList, permutation.fromList());
AlleleListUnitTester.assertAlleleList(targetAlleleList, permutation.toList());
Assert.assertFalse(permutation.isPartial());
Assert.assertEquals(permutation.fromSize(), originalAlleleList.numberOfAlleles());
Assert.assertEquals(permutation.toSize(), targetAlleleList.numberOfAlleles());
for (int i = 0; i < permutation.fromSize(); i++) {
Assert.assertEquals(permutation.toIndex(i), targetAlleleList.indexOfAllele(originalAlleleList.getAllele(i)));
Assert.assertEquals(permutation.fromIndex(i), originalAlleleList.indexOfAllele(targetAlleleList.getAllele(i)));
Assert.assertEquals(permutation.fromIndex(i), fromIndex[i]);
}
Assert.assertTrue(AlleleList.equals(permutation, targetAlleleList));
}
use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.
the class ReadLikelihoodsUnitTest method testAlleleQueries.
private void testAlleleQueries(final AlleleList<Allele> alleles, ReadLikelihoods<Allele> result) {
final Set<Integer> alleleIndices = new LinkedHashSet<>();
for (final Allele allele : alleles.asListOfAlleles()) {
final int indexOfAllele = result.indexOfAllele(allele);
Assert.assertTrue(indexOfAllele >= 0);
Assert.assertFalse(alleleIndices.contains(indexOfAllele));
alleleIndices.add(indexOfAllele);
Assert.assertSame(allele, alleles.getAllele(indexOfAllele));
}
}
use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.
the class ReadLikelihoodsUnitTest method testAlleleQueries.
private void testAlleleQueries(Allele[] alleles, ReadLikelihoods<Allele> result) {
final Set<Integer> alleleIndices = new LinkedHashSet<>();
for (final Allele allele : alleles) {
final int indexOfAllele = result.indexOfAllele(allele);
Assert.assertTrue(indexOfAllele >= 0);
Assert.assertFalse(alleleIndices.contains(indexOfAllele));
alleleIndices.add(indexOfAllele);
Assert.assertSame(allele, alleles[indexOfAllele]);
}
}
use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.
the class ReadLikelihoodsUnitTest method testMarginalization.
@Test(dataProvider = "marginalizationDataSets")
public void testMarginalization(final String[] samples, final Allele[] alleles, final Map<String, List<GATKRead>> reads, final Map<Allele, List<Allele>> newToOldAlleleMapping) {
final ReadLikelihoods<Allele> original = new ReadLikelihoods<>(new IndexedSampleList(samples), new IndexedAlleleList<>(alleles), reads);
fillWithRandomLikelihoods(samples, alleles, original);
final ReadLikelihoods<Allele> marginalized = original.marginalize(newToOldAlleleMapping);
Assert.assertNotNull(marginalized);
Assert.assertEquals(newToOldAlleleMapping.size(), marginalized.numberOfAlleles());
for (int a = 0; a < marginalized.numberOfAlleles(); a++) {
final List<Allele> oldAlleles = newToOldAlleleMapping.get(marginalized.getAllele(a));
Assert.assertNotNull(oldAlleles);
for (int s = 0; s < samples.length; s++) {
final LikelihoodMatrix<Allele> oldSmapleLikelihoods = original.sampleMatrix(s);
final LikelihoodMatrix<Allele> sampleLikelihoods = marginalized.sampleMatrix(s);
final int sampleReadCount = sampleLikelihoods.numberOfReads();
final int oldSampleReadCount = oldSmapleLikelihoods.numberOfReads();
Assert.assertEquals(oldSampleReadCount, sampleReadCount);
for (int r = 0; r < sampleReadCount; r++) {
double oldBestLk = Double.NEGATIVE_INFINITY;
for (final Allele oldAllele : oldAlleles) {
oldBestLk = Math.max(oldSmapleLikelihoods.get(original.indexOfAllele(oldAllele), r), oldBestLk);
}
Assert.assertEquals(sampleLikelihoods.get(a, r), oldBestLk);
}
}
}
}
use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.
the class ReadLikelihoodsUnitTest method testBestAlleleMap.
@Test(dataProvider = "dataSets")
public void testBestAlleleMap(final String[] samples, final Allele[] alleles, final Map<String, List<GATKRead>> reads) {
final ReadLikelihoods<Allele> original = new ReadLikelihoods<>(new IndexedSampleList(samples), new IndexedAlleleList<>(alleles), reads);
fillWithRandomLikelihoods(samples, alleles, original);
final Map<Allele, List<GATKRead>> expected = new LinkedHashMap<>(alleles.length);
for (final Allele allele : alleles) expected.put(allele, new ArrayList<>());
final int numberOfAlleles = alleles.length;
for (int s = 0; s < samples.length; s++) {
final int sampleReadCount = original.sampleReadCount(s);
final LikelihoodMatrix<Allele> sampleMatrix = original.sampleMatrix(s);
for (int r = 0; r < sampleReadCount; r++) {
int bestindexOfAllele = -1;
double bestAlleleLk = Double.NEGATIVE_INFINITY;
double secondBestAlleleLk = Double.NEGATIVE_INFINITY;
for (int a = 0; a < numberOfAlleles; a++) {
final double lk = sampleMatrix.get(a, r);
if (lk > bestAlleleLk) {
secondBestAlleleLk = bestAlleleLk;
bestAlleleLk = lk;
bestindexOfAllele = a;
} else if (lk > secondBestAlleleLk) {
secondBestAlleleLk = lk;
}
}
if ((bestAlleleLk - secondBestAlleleLk) > ReadLikelihoods.BestAllele.INFORMATIVE_THRESHOLD)
expected.get(alleles[bestindexOfAllele]).add(sampleMatrix.getRead(r));
}
}
final Map<Allele, List<GATKRead>> actual = original.readsByBestAlleleMap();
Assert.assertEquals(actual.size(), alleles.length);
for (final Allele allele : alleles) {
final List<GATKRead> expectedList = expected.get(allele);
final List<GATKRead> actualList = actual.get(allele);
final Set<GATKRead> expectedSet = new LinkedHashSet<>(expectedList);
final Set<GATKRead> actualSet = new LinkedHashSet<>(actualList);
Assert.assertEquals(actualSet, expectedSet);
}
}
Aggregations