add a way to test files generated by a walker that aren't command-line arguments; added some example code in CoverageStatisticsIntegrationTest for Chris.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2929 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
aaron 2010-03-04 20:20:58 +00:00
parent adea38fd5e
commit 80cc6bbeb4
2 changed files with 62 additions and 34 deletions

View File

@ -4,7 +4,9 @@ import junit.framework.Assert;
import org.broadinstitute.sting.gatk.CommandLineExecutable;
import org.broadinstitute.sting.gatk.CommandLineGATK;
import org.broadinstitute.sting.utils.Pair;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.Utils;
import org.junit.Before;
import org.junit.Test;
import org.apache.log4j.Appender;
import org.apache.log4j.WriterAppender;
@ -18,6 +20,13 @@ import java.security.MessageDigest;
import java.util.*;
public class WalkerTest extends BaseTest {
// the default output path for the integration test
private File outputFileLocation = null;
public void setOutputFileLocation(File outputFileLocation) {
this.outputFileLocation = outputFileLocation;
}
public String assertMatchingMD5(final String name, final File resultsFile, final String expectedMD5) {
try {
byte[] bytesOfMessage = getBytesFromFile(resultsFile);
@ -89,7 +98,7 @@ public class WalkerTest extends BaseTest {
List<String> md5s = null;
List<String> exts = null;
Map<String,File> auxillaryFiles = new HashMap<String,File>();
protected Map<String, File> auxillaryFiles = new HashMap<String, File>();
public WalkerTestSpec(String args, int nOutputFiles, List<String> md5s) {
this.args = args;
@ -116,19 +125,13 @@ public class WalkerTest extends BaseTest {
protected Pair<List<File>, List<String>> executeTest(final String name, WalkerTestSpec spec) {
List<File> tmpFiles = new ArrayList<File>();
for (int i = 0; i < spec.nOutputFiles; i++) {
try {
String ext = spec.exts == null ? ".tmp" : "." + spec.exts.get(i);
File fl = File.createTempFile(String.format("walktest.tmp_param.%d", i), ext );
fl.deleteOnExit();
File fl = createTempFile(String.format("walktest.tmp_param.%d", i), ext);
tmpFiles.add(fl);
} catch (IOException ex) {
System.err.println("Cannot create temp file: " + ex.getMessage());
}
}
final String args = String.format(spec.args, tmpFiles.toArray());
System.out.println(Utils.dupString('-', 80));
System.out.println(String.format("Executing test %s with GATK arguments: %s", name, args));
List<String> md5s = new LinkedList<String>();
md5s.addAll(spec.md5s);
@ -142,6 +145,15 @@ public class WalkerTest extends BaseTest {
return executeTest(name, md5s, tmpFiles, args);
}
public File createTempFile(String name, String extension) {
try {
File fl = File.createTempFile(name, extension);
//fl.deleteOnExit();
return fl;
} catch (IOException ex) {
throw new StingException("Cannot create temp file: " + ex.getMessage(), ex);
}
}
/**
* execute the test, given the following:
@ -163,6 +175,13 @@ public class WalkerTest extends BaseTest {
else
command = args.split(" ");
if (outputFileLocation != null) {
String[] cmd2 = Arrays.copyOf(command, command.length + 2);
cmd2[command.length] = "-o";
cmd2[command.length + 1] = this.outputFileLocation.getAbsolutePath();
command = cmd2;
}
System.out.println(String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ",command)));
CommandLineExecutable.start(instance, command);
if (CommandLineExecutable.result != 0) {

View File

@ -3,6 +3,7 @@ package org.broadinstitute.sting.oneoffprojects.walkers.coverage;
import org.broadinstitute.sting.WalkerTest;
import org.junit.Test;
import java.io.File;
import java.util.Arrays;
/**
@ -13,11 +14,11 @@ import java.util.Arrays;
*/
public class CoverageStatisticsIntegrationTest extends WalkerTest {
private boolean RUN_TESTS = false;
private boolean RUN_TESTS = true;
private String root = "-T CoverageStatistics ";
private String buildRootCmd(String ref, String bam, String interval) {
return root + "-R "+ref+" -I "+bam+" -L "+interval+" -o %s";
return root + "-R "+ref+" -I "+bam+" -L "+interval;
}
private void execute(String name, WalkerTestSpec spec) {
@ -28,12 +29,20 @@ public class CoverageStatisticsIntegrationTest extends WalkerTest {
@Test
public void testBaseOutputNoFiltering() {
// our base file
File baseOutputFile = this.createTempFile("outputtemp",".tmp");
this.setOutputFileLocation(baseOutputFile);
String bam_file = "/humgen/gsa-hphome1/chartl/projects/depthOfCoverage/testFiles/bams/Ciliopathies_1_88534_3_samples.bam";
String interval_list = "chr1:855534";
String reference = "/seq/references/Homo_sapiens_assembly18/v0/Homo_sapiens_assembly18.fasta";
String cmd = buildRootCmd(reference,bam_file,interval_list) + " -mmq 0 -mbq 0 -omitSampleSummary -omitIntervals -omitLocus";
String expected = "2aee1dbcb69bf1e874d56cd23336afa8";
String cmd = buildRootCmd(reference,bam_file,interval_list) + " -mmq 0 -mbq 0 -omitSampleSummary -omitLocus";
String expected = "d41d8cd98f00b204e9800998ecf8427e";
WalkerTestSpec spec = new WalkerTestSpec(cmd,1, Arrays.asList(expected));
// now add the expected files that get generated
spec.addAuxFile("344936e0bb4613544ff137cd1a002d6c",new File(baseOutputFile.getAbsolutePath() + ".interval_statistics"));
execute("testBaseOutputNoFiltering",spec);
}
}