restructure and add more tests

This commit is contained in:
Ron Levine 2014-12-25 13:57:54 -05:00
parent 069398ad46
commit a7fba5c209
1 changed files with 65 additions and 81 deletions

View File

@ -56,13 +56,15 @@ import htsjdk.variant.variantcontext.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.broadinstitute.gatk.utils.GenomeLocParser;
import org.broadinstitute.gatk.utils.BaseTest;
import org.broadinstitute.gatk.utils.fasta.CachingIndexedFastaSequenceFile;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -70,31 +72,30 @@ public class PhasingUtilsUnitTest extends BaseTest {
private final int start = 10;
private ReferenceSequenceFile referenceFile;
private Genotype genotype1;
private Genotype genotype2;
private String contig;
private List<Allele> alleleList1;
private List<Allele> alleleList2;
@BeforeClass
@BeforeSuite
public void init() throws FileNotFoundException {
referenceFile = new CachingIndexedFastaSequenceFile(new File(b37KGReference));
referenceFile = new CachingIndexedFastaSequenceFile(new File("/Users/ronlevine/src/human_g1k_v37.fasta"));
alleleList1 = Arrays.asList(Allele.create("T", true), Allele.create("C", false));
alleleList2 = Arrays.asList(Allele.create("G", true), Allele.create("A", false));
genotype1 = new GenotypeBuilder().name("sample1").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).make();
genotype2 = new GenotypeBuilder().name("sample2").attribute("HP", new String[]{"10-2", "10-1"}).alleles(alleleList2).make();
contig = new String("1");
}
@Test
public void TestMatchHaplotypeAllelesKeyHP() {
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", false));
alleleList1.add(Allele.create("C", false));
final Genotype genotype1 = new GenotypeBuilder("TC").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).make();
// Attributes in different order
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("G", false));
alleleList2.add(Allele.create("A", false));
final Genotype genotype2 = new GenotypeBuilder("GA").attribute("HP", new String[]{"10-2", "10-1"}).alleles(alleleList2).make();
PhasingUtils.SameHaplotypeAlleles sameHaplotypeAlleles = PhasingUtils.matchHaplotypeAlleles(genotype1, genotype2);
PhasingUtils.SameHaplotypeAlleles sameHaplotypeAllelesAnswer = new PhasingUtils.SameHaplotypeAlleles();
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", false), Allele.create("A", false)));
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("C", false), Allele.create("G", false)));
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", true), Allele.create("A", false)));
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("C", false), Allele.create("G", true)));
sameHaplotypeAllelesAnswer.requiresSwap = true;
Assert.assertEquals(sameHaplotypeAlleles.hapAlleles, sameHaplotypeAllelesAnswer.hapAlleles);
@ -104,22 +105,12 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test
public void TestMatchHaplotypeAllelesNoKeyHP() {
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", false));
alleleList1.add(Allele.create("C", false));
final Genotype genotype1 = new GenotypeBuilder("TC").alleles(alleleList1).make();
// Attributes in different order
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("G", false));
alleleList2.add(Allele.create("A", false));
final Genotype genotype2 = new GenotypeBuilder("GA").alleles(alleleList2).make();
// Must match because the same genotype
PhasingUtils.SameHaplotypeAlleles sameHaplotypeAlleles = PhasingUtils.matchHaplotypeAlleles(genotype1, genotype2);
Genotype genotype3 = new GenotypeBuilder().name("TC").alleles(alleleList1).make();
Genotype genotype4 = new GenotypeBuilder().name("GA").alleles(alleleList2).make();
PhasingUtils.SameHaplotypeAlleles sameHaplotypeAlleles = PhasingUtils.matchHaplotypeAlleles(genotype3, genotype4);
PhasingUtils.SameHaplotypeAlleles sameHaplotypeAllelesAnswer = new PhasingUtils.SameHaplotypeAlleles();
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", false), Allele.create("G", false)));
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("T", true), Allele.create("G", true)));
sameHaplotypeAllelesAnswer.hapAlleles.add(new PhasingUtils.AlleleOneAndTwo(Allele.create("C", false), Allele.create("A", false)));
Assert.assertEquals(sameHaplotypeAlleles.hapAlleles, sameHaplotypeAllelesAnswer.hapAlleles);
Assert.assertEquals(sameHaplotypeAlleles.requiresSwap, sameHaplotypeAllelesAnswer.requiresSwap);
@ -127,31 +118,49 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test
public void TestMergeIntoMNPvalidationTrueCheck() {
final String contig = new String("1");
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", true));
alleleList1.add(Allele.create("C", false));
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("A", true));
alleleList2.add(Allele.create("C", false));
final VariantContext vc1 = new VariantContextBuilder("TC", contig, start, start, alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder("AC", contig, start+1, start+1, alleleList2).make();
// TODO - genotypes must have the same sample name
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).make();
Assert.assertTrue(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
}
@Test
public void TestMergeIntoMNPvalidationCheckLocBefore() {
final String contig = new String("1");
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", true));
alleleList1.add(Allele.create("C", false));
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("A", true));
alleleList2.add(Allele.create("C", false));
final VariantContext vc1 = new VariantContextBuilder("TC", contig, start+1, start+1, alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder("AC", contig, start, start, alleleList2).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start).stop(start).alleles(alleleList2).make();
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
}
@Test
public void TestMergeIntoMNPvalidationFiltered() {
List<String> filters = Arrays.asList("filter");
Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).filters(filters).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
}
@Test
public void TestMergeIntoMNPvalidationNoCall() {
List<Allele> alleleList = Arrays.asList(Allele.create("T", true), Allele.create(".", false));
Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
}
@Test
public void TestMergeIntoMNPvalidationDiffSampleNames() {
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
@ -159,16 +168,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test
public void TestMergeIntoMNPvalidationDiffContigs() {
final String contig1 = new String("1");
final String contig2 = new String("2");
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", true));
alleleList1.add(Allele.create("C", false));
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("A", true));
alleleList2.add(Allele.create("C", false));
final VariantContext vc1 = new VariantContextBuilder("TC", contig1, start+1, start+1, alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder("AC", contig2, start, start, alleleList2).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
GenomeLocParser genomeLocParser = new GenomeLocParser(referenceFile);
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
@ -182,40 +183,23 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test
public void TestMergeVariantContextAttributes() {
final String contig = new String("1");
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", true));
alleleList1.add(Allele.create("C", false));
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("A", true));
alleleList2.add(Allele.create("C", false));
final VariantContext vc1 = new VariantContextBuilder("TC", contig, start, start, alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder("AC", contig, start+1, start+1, alleleList2).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
Assert.assertEquals(0, PhasingUtils.mergeVariantContextAttributes(vc1, vc2).size());
}
@Test
public void TestAllSamplesAreMergeableDiffSampleNames() {
final String contig = new String("1");
final List<Allele> alleleList1 = new ArrayList<>();
alleleList1.add(Allele.create("T", true));
alleleList1.add(Allele.create("C", false));
final List<Allele> alleleList2 = new ArrayList<>();
alleleList2.add(Allele.create("A", true));
alleleList2.add(Allele.create("C", false));
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("AC").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype2).make();
final Genotype g1 = new GenotypeBuilder().name("sample1").alleles(alleleList1).make();
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(g1).make();
Genotype g2 = new GenotypeBuilder().name("sample2").alleles(alleleList2).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("i21").source("AC").start(start).stop(start).alleles(alleleList2).genotypes(g2).make();
Assert.assertFalse( PhasingUtils.allSamplesAreMergeable(vc1, vc2));
Assert.assertFalse(PhasingUtils.allSamplesAreMergeable(vc1, vc2));
}
@Test
public void TestAlleleSegregationIsKnown(){
Assert.assertTrue(PhasingUtils.alleleSegregationIsKnown(genotype1, genotype2));
}
@Test