From 822654b119ec6e2efefa11c82bc1a86069bac06d Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Sun, 9 Oct 2011 10:36:14 -0700 Subject: [PATCH] UnitTests for allele getting functions in VC in prep for move from set to list --- .../VariantContextUnitTest.java | 72 ++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUnitTest.java index cee7a4782..39f8c0f39 100755 --- a/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/variantcontext/VariantContextUnitTest.java @@ -6,10 +6,10 @@ package org.broadinstitute.sting.utils.variantcontext; import org.broadinstitute.sting.BaseTest; -import org.testng.Assert; import org.testng.annotations.BeforeSuite; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.testng.Assert; import java.util.ArrayList; import java.util.Arrays; @@ -455,14 +455,70 @@ public class VariantContextUnitTest extends BaseTest { Assert.assertEquals(0, vc5.getChromosomeCount(Aref)); } + // -------------------------------------------------------------------------------- + // + // Test allele merging + // + // -------------------------------------------------------------------------------- - @Test - public void testManipulatingAlleles() { - // todo -- add tests that call add/set/remove + private class GetAllelesTest extends TestDataProvider { + List alleles; + + private GetAllelesTest(String name, Allele... arg) { + super(GetAllelesTest.class, name); + this.alleles = Arrays.asList(arg); + } + + public String toString() { + return String.format("%s input=%s", super.toString(), alleles); + } } - @Test - public void testManipulatingGenotypes() { - // todo -- add tests that call add/set/remove + @DataProvider(name = "getAlleles") + public Object[][] mergeAllelesData() { + new GetAllelesTest("A*", Aref); + new GetAllelesTest("-*", delRef); + new GetAllelesTest("A*/C", Aref, C); + new GetAllelesTest("A*/C/T", Aref, C, T); + new GetAllelesTest("A*/T/C", Aref, T, C); + new GetAllelesTest("A*/C/T/-", Aref, C, T, del); + new GetAllelesTest("A*/T/C/-", Aref, T, C, del); + new GetAllelesTest("A*/-/T/C", Aref, del, T, C); + + return GetAllelesTest.getTests(GetAllelesTest.class); + } + + @Test(dataProvider = "getAlleles") + public void testMergeAlleles(GetAllelesTest cfg) { + final List altAlleles = cfg.alleles.subList(1, cfg.alleles.size()); + final VariantContext vc = new VariantContext("test", snpLoc, snpLocStart, snpLocStop, cfg.alleles, null, InferredGeneticContext.NO_NEG_LOG_10PERROR, null, null, (byte)'A'); + + Assert.assertEquals(vc.getAlleles(), cfg.alleles, "VC alleles not the same as input alleles"); + Assert.assertEquals(vc.getNAlleles(), cfg.alleles.size(), "VC getNAlleles not the same as input alleles size"); + Assert.assertEquals(vc.getAlternateAlleles(), altAlleles, "VC alt alleles not the same as input alt alleles"); + + + for ( int i = 0; i < cfg.alleles.size(); i++ ) { + final Allele inputAllele = cfg.alleles.get(i); + + Assert.assertTrue(vc.hasAllele(inputAllele)); + if ( inputAllele.isReference() ) { + final Allele nonRefVersion = Allele.create(inputAllele.getBases(), false); + Assert.assertTrue(vc.hasAllele(nonRefVersion, true)); + Assert.assertFalse(vc.hasAllele(nonRefVersion, false)); + } + + Assert.assertEquals(inputAllele, vc.getAllele(inputAllele.getBaseString())); + Assert.assertEquals(inputAllele, vc.getAllele(inputAllele.getBases())); + + if ( i > 0 ) { // it's an alt allele + Assert.assertEquals(inputAllele, vc.getAlternateAllele(i-1)); + } + } + + final Allele missingAllele = Allele.create("AACCGGTT"); // does not exist + Assert.assertNull(vc.getAllele(missingAllele.getBases())); + Assert.assertFalse(vc.hasAllele(missingAllele)); + Assert.assertFalse(vc.hasAllele(missingAllele, true)); } }