Now deletes the dump directory on ant clean

Moving diffengine tests from private to public
This commit is contained in:
Mark DePristo 2011-07-12 08:50:58 -04:00
parent d7d15019dd
commit f313e14e4e
5 changed files with 717 additions and 0 deletions

View File

@ -981,6 +981,7 @@
<delete dir="out"/>
<delete dir="${build.dir}"/>
<delete dir="${lib.dir}"/>
<delete dir="dump"/>
<delete dir="staging"/>
<delete dir="${dist.dir}"/>
<delete dir="pipelinetests"/>

View File

@ -0,0 +1,229 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// our package
package org.broadinstitute.sting.gatk.walkers.diffengine;
// the imports for unit testing.
import org.broadinstitute.sting.BaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.*;
/**
* Basic unit test for DifferableReaders in reduced reads
*/
public class DiffEngineUnitTest extends BaseTest {
DiffEngine engine;
@BeforeClass(enabled = true)
public void createDiffEngine() {
engine = new DiffEngine();
}
// --------------------------------------------------------------------------------
//
// Difference testing routines
//
// --------------------------------------------------------------------------------
private class DifferenceTest extends TestDataProvider {
public DiffElement tree1, tree2;
public List<String> differences;
private DifferenceTest(String tree1, String tree2) {
this(tree1, tree2, Collections.<String>emptyList());
}
private DifferenceTest(String tree1, String tree2, String difference) {
this(tree1, tree2, Arrays.asList(difference));
}
private DifferenceTest(String tree1, String tree2, List<String> differences) {
super(DifferenceTest.class);
this.tree1 = DiffNode.fromString(tree1);
this.tree2 = DiffNode.fromString(tree2);
this.differences = differences;
}
public String toString() {
return String.format("tree1=%s tree2=%s diff=%s",
tree1.toOneLineString(), tree2.toOneLineString(), differences);
}
}
@DataProvider(name = "trees")
public Object[][] createTrees() {
new DifferenceTest("A=X", "A=X");
new DifferenceTest("A=X", "A=Y", "A:X!=Y");
new DifferenceTest("A=X", "B=X", Arrays.asList("A:X!=MISSING", "B:MISSING!=X"));
new DifferenceTest("A=(X=1)", "B=(X=1)", Arrays.asList("A:(X=1)!=MISSING", "B:MISSING!=(X=1)"));
new DifferenceTest("A=(X=1)", "A=(X=1)");
new DifferenceTest("A=(X=1 Y=2)", "A=(X=1 Y=2)");
new DifferenceTest("A=(X=1 Y=2 B=(Z=3))", "A=(X=1 Y=2 B=(Z=3))");
new DifferenceTest("A=(X=1)", "A=(X=2)", "A.X:1!=2");
new DifferenceTest("A=(X=1 Y=2 B=(Z=3))", "A=(X=1 Y=2 B=(Z=4))", "A.B.Z:3!=4");
new DifferenceTest("A=(X=1)", "A=(X=1 Y=2)", "A.Y:MISSING!=2");
new DifferenceTest("A=(X=1 Y=2 B=(Z=3))", "A=(X=1 Y=2)", "A.B:(Z=3)!=MISSING");
return DifferenceTest.getTests(DifferenceTest.class);
}
@Test(enabled = true, dataProvider = "trees")
public void testDiffs(DifferenceTest test) {
logger.warn("Test tree1: " + test.tree1.toOneLineString());
logger.warn("Test tree2: " + test.tree2.toOneLineString());
List<Difference> diffs = engine.diff(test.tree1, test.tree2);
logger.warn("Test expected diff : " + test.differences);
logger.warn("Observed diffs : " + diffs);
}
// --------------------------------------------------------------------------------
//
// Low-level routines for summarizing differences
//
// --------------------------------------------------------------------------------
@Test(enabled = true)
public void testLongestCommonPostfix() {
testLongestCommonPostfixHelper("A", "A", 1);
testLongestCommonPostfixHelper("A", "B", 0);
testLongestCommonPostfixHelper("A.B", "A.B", 2);
testLongestCommonPostfixHelper("A.B.C", "A.B.C", 3);
testLongestCommonPostfixHelper("A.B.C", "X.B.C", 2);
testLongestCommonPostfixHelper("A.B.C", "X.Y.C", 1);
testLongestCommonPostfixHelper("A.B.C", "X.Y.Z", 0);
testLongestCommonPostfixHelper("A.B.C", "A.X.C", 1);
testLongestCommonPostfixHelper("A.B.C", "A.X.Z", 0);
testLongestCommonPostfixHelper("A.B.C", "A.B.Z", 0);
}
public void testLongestCommonPostfixHelper(String p1, String p2, int expected) {
String[] parts1 = p1.split("\\.");
String[] parts2 = p2.split("\\.");
int obs = DiffEngine.longestCommonPostfix(parts1, parts2);
Assert.assertEquals(obs, expected, "p1=" + p1 + " p2=" + p2 + " failed");
}
@Test(enabled = true, dependsOnMethods = "testLongestCommonPostfix")
public void testSummarizePath() {
testSummarizePathHelper("A", "A", "A");
testSummarizePathHelper("A", "B", "*");
testSummarizePathHelper("A.B", "A.B", "A.B");
testSummarizePathHelper("A.B", "X.B", "*.B");
testSummarizePathHelper("A.B", "X.Y", "*.*");
testSummarizePathHelper("A.B.C", "A.B.C", "A.B.C");
testSummarizePathHelper("A.B.C", "X.B.C", "*.B.C");
testSummarizePathHelper("A.B.C", "X.Y.C", "*.*.C");
testSummarizePathHelper("A.B.C", "X.Y.Z", "*.*.*");
testSummarizePathHelper("A.B.C", "A.X.C", "*.*.C");
testSummarizePathHelper("A.B.C", "A.X.Z", "*.*.*");
testSummarizePathHelper("A.B.C", "A.B.Z", "*.*.*");
}
public void testSummarizePathHelper(String p1, String p2, String expected) {
String[] parts1 = DiffEngine.diffNameToPath(p1);
String[] parts2 = DiffEngine.diffNameToPath(p2);
int obs = DiffEngine.longestCommonPostfix(parts1, parts2);
String path = DiffEngine.summarizedPath(parts2, obs);
Assert.assertEquals(path, expected, "p1=" + p1 + " p2=" + p2 + " failed");
}
// --------------------------------------------------------------------------------
//
// High-level difference summary
//
// --------------------------------------------------------------------------------
private class SummarizeDifferenceTest extends TestDataProvider {
List<String> diffs = new ArrayList<String>();
List<String> expecteds = new ArrayList<String>();
public SummarizeDifferenceTest() { super(SummarizeDifferenceTest.class); }
public SummarizeDifferenceTest addDiff(String... diffsToAdd) {
diffs.addAll(Arrays.asList(diffsToAdd));
return this;
}
public SummarizeDifferenceTest addSummary(String... expectedSummary) {
expecteds.addAll(Arrays.asList(expectedSummary));
return this;
}
public String toString() {
return String.format("diffs=%s => expected=%s", diffs, expecteds);
}
public void test() {
List<String[]> diffPaths = new ArrayList<String[]>(diffs.size());
for ( String diff : diffs ) { diffPaths.add(DiffEngine.diffNameToPath(diff)); }
List<DiffEngine.SummarizedDifference> sumDiffs = engine.summarizedDifferencesOfPaths(diffPaths);
Assert.assertEquals(sumDiffs.size(), expecteds.size(), "Unexpected number of summarized differences: " + sumDiffs);
for ( int i = 0; i < sumDiffs.size(); i++ ) {
DiffEngine.SummarizedDifference sumDiff = sumDiffs.get(i);
String expected = expecteds.get(i);
String[] pathCount = expected.split(":");
String path = pathCount[0];
int count = Integer.valueOf(pathCount[1]);
Assert.assertEquals(sumDiff.getPath(), path, "Unexpected path at: " + expected + " obs=" + sumDiff + " all=" + sumDiffs);
Assert.assertEquals(sumDiff.getCount(), count, "Unexpected counts at: " + expected + " obs=" + sumDiff + " all=" + sumDiffs);
}
}
}
@DataProvider(name = "summaries")
public Object[][] createSummaries() {
new SummarizeDifferenceTest().addDiff("A", "A").addSummary("A:2");
new SummarizeDifferenceTest().addDiff("A", "B").addSummary("A:1", "B:1");
new SummarizeDifferenceTest().addDiff("A", "A", "A").addSummary("A:3");
new SummarizeDifferenceTest().addDiff("A", "A", "A", "B").addSummary("A:3", "B:1");
new SummarizeDifferenceTest().addDiff("A", "A", "A", "B", "B").addSummary("A:3", "B:2");
new SummarizeDifferenceTest().addDiff("A", "A", "A", "B", "B", "C").addSummary("A:3", "B:2", "C:1");
new SummarizeDifferenceTest().addDiff("A.X", "A.X").addSummary("A.X:2");
new SummarizeDifferenceTest().addDiff("A.X", "A.X", "B.X").addSummary("*.X:3", "A.X:2", "B.X:1");
new SummarizeDifferenceTest().addDiff("A.X", "A.X", "B.X", "B.X").addSummary("*.X:4", "A.X:2", "B.X:2");
new SummarizeDifferenceTest().addDiff("A.B.C", "X.B.C").addSummary("*.B.C:2", "A.B.C:1", "X.B.C:1");
new SummarizeDifferenceTest().addDiff("A.B.C", "X.Y.C", "X.Y.C").addSummary("*.*.C:3", "X.Y.C:2", "A.B.C:1");
new SummarizeDifferenceTest().addDiff("A.B.C", "A.X.C", "X.Y.C").addSummary("*.*.C:3", "A.B.C:1", "A.X.C:1", "X.Y.C:1");
new SummarizeDifferenceTest().addDiff("A.B.C", "A.X.C", "B.X.C").addSummary("*.*.C:3", "*.X.C:2", "A.B.C:1", "A.X.C:1", "B.X.C:1");
new SummarizeDifferenceTest().addDiff("A.B.C", "A.X.C", "B.X.C", "B.X.C").addSummary("*.*.C:4", "*.X.C:3", "B.X.C:2", "A.B.C:1", "A.X.C:1");
return SummarizeDifferenceTest.getTests(SummarizeDifferenceTest.class);
}
@Test(enabled = true, dependsOnMethods = "testSummarizePath", dataProvider = "summaries")
public void testSummarizeDifferences(SummarizeDifferenceTest test) {
test.test();
}
}

View File

@ -0,0 +1,249 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// our package
package org.broadinstitute.sting.gatk.walkers.diffengine;
// the imports for unit testing.
import org.broadinstitute.sting.BaseTest;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.*;
/**
* Basic unit test for DifferableReaders in reduced reads
*/
public class DiffNodeUnitTest extends BaseTest {
// Data is:
// MY_ROOT
// fields: A=A, B=B
// nodes: C, D
// C: fields: E=E, nodes: none
// D: fields: F=F, G=G, nodes: none
static DiffNode MY_ROOT = DiffNode.rooted("MY_ROOT");
static DiffValue Value_A = new DiffValue("A", MY_ROOT, "A");
static DiffValue Value_B = new DiffValue("B", MY_ROOT, "B");
static DiffNode NODE_C = DiffNode.empty("C", MY_ROOT);
static DiffNode NODE_D = DiffNode.empty("D", MY_ROOT);
static DiffValue Value_E = new DiffValue("E", NODE_C, "E");
static DiffValue Value_F = new DiffValue("F", NODE_D, "F");
static DiffValue Value_G = new DiffValue("G", NODE_D, "G");
static {
MY_ROOT.add(Value_A);
MY_ROOT.add(Value_B);
MY_ROOT.add(NODE_C);
MY_ROOT.add(NODE_D);
NODE_C.add(Value_E);
NODE_D.add(Value_F);
NODE_D.add(Value_G);
}
// --------------------------------------------------------------------------------
//
// Element testing routines
//
// --------------------------------------------------------------------------------
private class ElementTest extends TestDataProvider {
public DiffElement elt;
public String name;
public String fullName;
public DiffElement parent;
private ElementTest(DiffValue elt, DiffValue parent, String name, String fullName) {
this(elt.getBinding(), parent.getBinding(), name, fullName);
}
private ElementTest(DiffElement elt, DiffElement parent, String name, String fullName) {
super(ElementTest.class);
this.elt = elt;
this.name = name;
this.fullName = fullName;
this.parent = parent;
}
public String toString() {
return String.format("ElementTest elt=%s name=%s fullName=%s parent=%s",
elt.toOneLineString(), name, fullName, parent.getName());
}
}
@DataProvider(name = "elementdata")
public Object[][] createElementData() {
new ElementTest(MY_ROOT.getBinding(), DiffElement.ROOT, "MY_ROOT", "MY_ROOT");
new ElementTest(NODE_C, MY_ROOT, "C", "MY_ROOT.C");
new ElementTest(NODE_D, MY_ROOT, "D", "MY_ROOT.D");
new ElementTest(Value_A, MY_ROOT, "A", "MY_ROOT.A");
new ElementTest(Value_B, MY_ROOT, "B", "MY_ROOT.B");
new ElementTest(Value_E, NODE_C, "E", "MY_ROOT.C.E");
new ElementTest(Value_F, NODE_D, "F", "MY_ROOT.D.F");
new ElementTest(Value_G, NODE_D, "G", "MY_ROOT.D.G");
return TestDataProvider.getTests(ElementTest.class);
}
@Test(enabled = true, dataProvider = "elementdata")
public void testElementMethods(ElementTest test) {
Assert.assertNotNull(test.elt.getName());
Assert.assertNotNull(test.elt.getParent());
Assert.assertEquals(test.elt.getName(), test.name);
Assert.assertEquals(test.elt.getParent(), test.parent);
Assert.assertEquals(test.elt.fullyQualifiedName(), test.fullName);
}
// --------------------------------------------------------------------------------
//
// DiffValue testing routines
//
// --------------------------------------------------------------------------------
private class LeafTest extends TestDataProvider {
public DiffValue diffvalue;
public Object value;
private LeafTest(DiffValue diffvalue, Object value) {
super(LeafTest.class);
this.diffvalue = diffvalue;
this.value = value;
}
public String toString() {
return String.format("LeafTest diffvalue=%s value=%s", diffvalue.toOneLineString(), value);
}
}
@DataProvider(name = "leafdata")
public Object[][] createLeafData() {
new LeafTest(Value_A, "A");
new LeafTest(Value_B, "B");
new LeafTest(Value_E, "E");
new LeafTest(Value_F, "F");
new LeafTest(Value_G, "G");
return TestDataProvider.getTests(LeafTest.class);
}
@Test(enabled = true, dataProvider = "leafdata")
public void testLeafMethods(LeafTest test) {
Assert.assertNotNull(test.diffvalue.getValue());
Assert.assertEquals(test.diffvalue.getValue(), test.value);
}
// --------------------------------------------------------------------------------
//
// Node testing routines
//
// --------------------------------------------------------------------------------
private class NodeTest extends TestDataProvider {
public DiffNode node;
public Set<String> fields;
public Set<String> subnodes;
public Set<String> allNames;
private NodeTest(DiffNode node, List<String> fields, List<String> subnodes) {
super(NodeTest.class);
this.node = node;
this.fields = new HashSet<String>(fields);
this.subnodes = new HashSet<String>(subnodes);
this.allNames = new HashSet<String>(fields);
allNames.addAll(subnodes);
}
public String toString() {
return String.format("NodeTest node=%s fields=%s subnodes=%s",
node.toOneLineString(), fields, subnodes);
}
}
@DataProvider(name = "nodedata")
public Object[][] createData1() {
new NodeTest(MY_ROOT, Arrays.asList("A", "B"), Arrays.asList("C", "D"));
new NodeTest(NODE_C, Arrays.asList("E"), Collections.<String>emptyList());
new NodeTest(NODE_D, Arrays.asList("F", "G"), Collections.<String>emptyList());
return TestDataProvider.getTests(NodeTest.class);
}
@Test(enabled = true, dataProvider = "nodedata")
public void testNodeAccessors(NodeTest test) {
Assert.assertNotNull(test.node.getElements());
for ( String name : test.allNames ) {
DiffElement elt = test.node.getElement(name);
Assert.assertNotNull(elt, "Failed to find field " + elt + " in " + test.node);
Assert.assertEquals(elt.getName(), name);
Assert.assertEquals(elt.getValue().isAtomic(), test.fields.contains(name), "Failed atomic/compound expectation: " + test.node);
}
}
// NOTE: add routines are being implicitly tested by the creation of the data structures
@Test(enabled = true, dataProvider = "nodedata")
public void testCounts(NodeTest test) {
Assert.assertEquals(test.node.getElements().size(), test.allNames.size());
Assert.assertEquals(test.node.getElementNames(), test.allNames);
}
// --------------------------------------------------------------------------------
//
// fromString testing routines
//
// --------------------------------------------------------------------------------
private class FromStringTest extends TestDataProvider {
public String string;
public DiffElement expected;
private FromStringTest(String string, DiffElement expected) {
super(FromStringTest.class);
this.string = string;
this.expected = expected;
}
public String toString() {
return String.format("FromStringTest string=%s expected=%s", string, expected.toOneLineString());
}
}
@DataProvider(name = "fromstringdata")
public Object[][] createFromData() {
new FromStringTest("A=A", Value_A.getBinding());
new FromStringTest("B=B", Value_B.getBinding());
new FromStringTest("C=(E=E)", NODE_C.getBinding());
new FromStringTest("D=(F=F G=G)", NODE_D.getBinding());
return TestDataProvider.getTests(FromStringTest.class);
}
@Test(enabled = true, dataProvider = "fromstringdata")
public void parseFromString(FromStringTest test) {
logger.warn("Testing from string: " + test.string);
DiffElement elt = DiffNode.fromString(test.string);
Assert.assertEquals(elt.toOneLineString(), test.expected.toOneLineString());
}
}

View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// our package
package org.broadinstitute.sting.gatk.walkers.diffengine;
// the imports for unit testing.
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.BaseTest;
import org.broadinstitute.sting.utils.variantcontext.Allele;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import java.util.*;
/**
* Basic unit test for DifferableReaders in reduced reads
*/
public class DiffableReaderUnitTest extends BaseTest {
DiffEngine engine;
File vcfFile = new File(testDir + "diffTestMaster.vcf");
File bamFile = new File(testDir + "exampleBAM.bam");
@BeforeClass(enabled = true)
public void createDiffEngine() {
engine = new DiffEngine();
}
@Test(enabled = true)
public void testPluggableDiffableReaders() {
logger.warn("testPluggableDiffableReaders");
Map<String, DiffableReader> readers = engine.getReaders();
Assert.assertNotNull(readers);
Assert.assertTrue(readers.size() > 0);
Assert.assertNotNull(readers.get("VCF"));
for ( Map.Entry<String, DiffableReader> e : engine.getReaders().entrySet() ) {
logger.warn("Found diffable reader: " + e.getKey());
Assert.assertEquals(e.getValue().getName(), e.getKey());
Assert.assertEquals(e.getValue(), engine.getReader(e.getKey()));
}
}
private static void testLeaf(DiffNode rec, String field, Object expected) {
DiffElement value = rec.getElement(field);
Assert.assertNotNull(value, "Expected to see leaf named " + field + " in rec " + rec);
Assert.assertEquals(value.getValue().getValue(), expected, "Expected to leaf named " + field + " to have value " + expected + " in rec " + rec);
}
@Test(enabled = true, dependsOnMethods = "testPluggableDiffableReaders")
public void testVCF1() {
logger.warn("testVCF1");
DiffableReader vcfReader = engine.getReader("VCF");
Assert.assertTrue(vcfReader.canRead(vcfFile));
Assert.assertFalse(vcfReader.canRead(bamFile));
DiffElement diff = vcfReader.readFromFile(vcfFile);
Assert.assertNotNull(diff);
Assert.assertEquals(diff.getName(), vcfFile.getName());
Assert.assertSame(diff.getParent(), DiffElement.ROOT);
DiffNode node = diff.getValueAsNode();
Assert.assertEquals(node.getElements().size(), 9);
// chr1 2646 rs62635284 G A 0.15 PASS AC=2;AF=1.00;AN=2 GT:AD:DP:GL:GQ 1/1:53,75:3:-12.40,-0.90,-0.00:9.03
DiffNode rec1 = node.getElement("chr1:2646").getValueAsNode();
testLeaf(rec1, "CHROM", "chr1");
testLeaf(rec1, "POS", 2646);
testLeaf(rec1, "ID", "rs62635284");
testLeaf(rec1, "REF", Allele.create("G", true));
testLeaf(rec1, "ALT", new HashSet<Allele>(Arrays.asList(Allele.create("A"))));
testLeaf(rec1, "QUAL", 0.15);
testLeaf(rec1, "FILTER", Collections.<Object>emptySet());
testLeaf(rec1, "AC", "2");
testLeaf(rec1, "AF", "1.00");
testLeaf(rec1, "AN", "2");
}
@Test(enabled = true, dependsOnMethods = "testPluggableDiffableReaders")
public void testBAM() {
logger.warn("testBAM");
DiffableReader bamReader = engine.getReader("BAM");
Assert.assertTrue(bamReader.canRead(bamFile));
Assert.assertFalse(bamReader.canRead(vcfFile));
DiffElement diff = bamReader.readFromFile(bamFile);
Assert.assertNotNull(diff);
Assert.assertEquals(diff.getName(), bamFile.getName());
Assert.assertSame(diff.getParent(), DiffElement.ROOT);
DiffNode node = diff.getValueAsNode();
Assert.assertEquals(node.getElements().size(), 33);
// 30PPJAAXX090125:1:42:512:1817#0 99 chr1 200 0 76M =
// 255 -130 ACCCTAACCCTAACCCTAACCCTAACCATAACCCTAAGACTAACCCTAAACCTAACCCTCATAATCGAAATACAAC
// BBBBC@C?AABCBB<63>=B@>+B9-9+)2B8,+@327B5A>90((>-+''3?(/'''A)(''19('7.,**%)3:
// PG:Z:0 RG:Z:exampleBAM.bam SM:Z:exampleBAM.bam
DiffNode rec1 = node.getElement("30PPJAAXX090125:1:42:512:1817#0_1").getValueAsNode();
testLeaf(rec1, "NAME", "30PPJAAXX090125:1:42:512:1817#0");
testLeaf(rec1, "FLAGS", 99);
testLeaf(rec1, "RNAME", "chr1");
testLeaf(rec1, "POS", 200);
testLeaf(rec1, "MAPQ", 0);
testLeaf(rec1, "CIGAR", "76M");
testLeaf(rec1, "RNEXT", "chr1");
testLeaf(rec1, "PNEXT", 255);
testLeaf(rec1, "TLEN", -130);
testLeaf(rec1, "SEQ", "ACCCTAACCCTAACCCTAACCCTAACCATAACCCTAAGACTAACCCTAAACCTAACCCTCATAATCGAAATACAAC");
testLeaf(rec1, "QUAL", "BBBBC@C?AABCBB<63>=B@>+B9-9+)2B8,+@327B5A>90((>-+''3?(/'''A)(''19('7.,**%)3:");
testLeaf(rec1, "PG", "0");
testLeaf(rec1, "RG", "exampleBAM.bam");
testLeaf(rec1, "SM", "exampleBAM.bam");
}
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// our package
package org.broadinstitute.sting.gatk.walkers.diffengine;
// the imports for unit testing.
import org.broadinstitute.sting.BaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Basic unit test for DifferableReaders in reduced reads
*/
public class DifferenceUnitTest extends BaseTest {
// --------------------------------------------------------------------------------
//
// testing routines
//
// --------------------------------------------------------------------------------
private class DifferenceTest extends TestDataProvider {
public DiffElement tree1, tree2;
public String difference;
private DifferenceTest(String tree1, String tree2, String difference) {
this(DiffNode.fromString(tree1), DiffNode.fromString(tree2), difference);
}
private DifferenceTest(DiffElement tree1, DiffElement tree2, String difference) {
super(DifferenceTest.class);
this.tree1 = tree1;
this.tree2 = tree2;
this.difference = difference;
}
public String toString() {
return String.format("tree1=%s tree2=%s diff=%s",
tree1 == null ? "null" : tree1.toOneLineString(),
tree2 == null ? "null" : tree2.toOneLineString(),
difference);
}
}
@DataProvider(name = "data")
public Object[][] createTrees() {
new DifferenceTest("A=X", "A=Y", "A:X!=Y");
new DifferenceTest("A=Y", "A=X", "A:Y!=X");
new DifferenceTest(DiffNode.fromString("A=X"), null, "A:X!=MISSING");
new DifferenceTest(null, DiffNode.fromString("A=X"), "A:MISSING!=X");
return DifferenceTest.getTests(DifferenceTest.class);
}
@Test(enabled = true, dataProvider = "data")
public void testDiffToString(DifferenceTest test) {
logger.warn("Test tree1: " + (test.tree1 == null ? "null" : test.tree1.toOneLineString()));
logger.warn("Test tree2: " + (test.tree2 == null ? "null" : test.tree2.toOneLineString()));
logger.warn("Test expected diff : " + test.difference);
Difference diff = new Difference(test.tree1, test.tree2);
logger.warn("Observed diffs : " + diff);
Assert.assertEquals(diff.toString(), test.difference, "Observed diff string " + diff + " not equal to expected difference string " + test.difference );
}
}