UnitTests for allele getting functions in VC in prep for move from set to list
This commit is contained in:
parent
c67f6c076b
commit
822654b119
|
|
@ -6,10 +6,10 @@ package org.broadinstitute.sting.utils.variantcontext;
|
||||||
|
|
||||||
|
|
||||||
import org.broadinstitute.sting.BaseTest;
|
import org.broadinstitute.sting.BaseTest;
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.annotations.BeforeSuite;
|
import org.testng.annotations.BeforeSuite;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.Assert;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -455,14 +455,70 @@ public class VariantContextUnitTest extends BaseTest {
|
||||||
Assert.assertEquals(0, vc5.getChromosomeCount(Aref));
|
Assert.assertEquals(0, vc5.getChromosomeCount(Aref));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Test allele merging
|
||||||
|
//
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
|
||||||
@Test
|
private class GetAllelesTest extends TestDataProvider {
|
||||||
public void testManipulatingAlleles() {
|
List<Allele> alleles;
|
||||||
// todo -- add tests that call add/set/remove
|
|
||||||
|
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
|
@DataProvider(name = "getAlleles")
|
||||||
public void testManipulatingGenotypes() {
|
public Object[][] mergeAllelesData() {
|
||||||
// todo -- add tests that call add/set/remove
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue