UnitTests for allele getting functions in VC in prep for move from set to list

This commit is contained in:
Mark DePristo 2011-10-09 10:36:14 -07:00
parent c67f6c076b
commit 822654b119
1 changed files with 64 additions and 8 deletions

View File

@ -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<Allele> 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<Allele> 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));
}
}