Commit 2fdf69e7 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

This will remove tempfiles on exit

parent 6300d051
......@@ -231,6 +231,7 @@ object ReportBuilder {
case Some(template) => template
case _ =>
val tempFile = File.createTempFile("ssp-template", new File(location).getName)
tempFile.deleteOnExit()
IoUtils.copyStreamToFile(getClass.getResourceAsStream(location), tempFile)
templateCache += location -> tempFile
tempFile
......
......@@ -625,6 +625,7 @@ object VcfStats extends ToolCommand {
def executeRscript(resource: String, args: Array[String]): Unit = {
val is = getClass.getResourceAsStream(resource)
val file = File.createTempFile("script.", "." + resource)
file.deleteOnExit()
val os = new FileOutputStream(file)
org.apache.commons.io.IOUtils.copy(is, os)
os.close()
......
......@@ -31,6 +31,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
@Test def testMainVcf = {
val tmp = File.createTempFile("basty_out", ".fa")
tmp.deleteOnExit()
val tmppath = tmp.getAbsolutePath
tmp.deleteOnExit()
......@@ -40,6 +41,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
@Test def testMainVcfAndBam = {
val tmp = File.createTempFile("basty_out", ".fa")
tmp.deleteOnExit()
val tmppath = tmp.getAbsolutePath
tmp.deleteOnExit()
......@@ -49,6 +51,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
@Test def testMainVcfAndBamMore = {
val tmp = File.createTempFile("basty_out", ".fa")
tmp.deleteOnExit()
val tmppath = tmp.getAbsolutePath
tmp.deleteOnExit()
......
......@@ -56,6 +56,7 @@ class BiopetFlagstatTest extends TestNGSuite with MockitoSugar with Matchers {
def testMain() = {
//TODO: Test output file
val output = File.createTempFile("testMain", ".biopetflagstat")
output.deleteOnExit()
main(Array("-I", bam.getAbsolutePath, "-o", output.toString))
}
......
......@@ -23,7 +23,7 @@ class FastqSplitterTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testMain() = {
val temp = File.createTempFile("out", ".fastq")
temp.deleteOnExit()
val args = Array("-I", fq, "-o", temp.getAbsolutePath)
main(args)
}
......@@ -31,6 +31,7 @@ class FastqSplitterTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testManyOutMain() = {
val files = (0 until 10).map(_ => File.createTempFile("out", ".fastq"))
files.foreach(_.deleteOnExit())
var args = Array("-I", fq)
files.foreach(x => args ++= Array("-o", x.getAbsolutePath))
main(args)
......
......@@ -29,6 +29,7 @@ class FindRepeatsPacBioTest extends TestNGSuite with MockitoSugar with Matchers
def testMain() = {
val outputFile = File.createTempFile("repeats", ".tsv")
outputFile.deleteOnExit()
val args = Array("-I", bam, "-b", bed, "-o", outputFile.toString)
main(args)
}
......
......@@ -28,6 +28,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testMain() = {
val tmp = File.createTempFile("mpileup", ".vcf")
tmp.deleteOnExit()
val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath)
main(args)
......@@ -36,6 +37,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def validateOutVcf() = {
val tmp = File.createTempFile("mpileup", ".vcf")
tmp.deleteOnExit()
val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1", "--minAP", "1")
main(args)
......@@ -51,6 +53,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def extraValidateOutVcf() = {
val tmp = File.createTempFile("mpileup", ".vcf")
tmp.deleteOnExit()
val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1", "--minAP", "1")
main(args)
......
......@@ -26,6 +26,7 @@ class PrefixFastqTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testMain() = {
val temp = File.createTempFile("out", ".fastq")
temp.deleteOnExit()
val args = Array("-i", fq, "-o", temp.getAbsolutePath, "-s", "AAA")
main(args)
......@@ -34,6 +35,7 @@ class PrefixFastqTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testOutput() = {
val temp = File.createTempFile("out", ".fastq")
temp.deleteOnExit()
val args = Array("-i", fq, "-o", temp.getAbsolutePath, "-s", "AAA")
main(args)
......
......@@ -22,6 +22,7 @@ class SageCountFastqTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testMain() = {
val temp = File.createTempFile("out", ".fastq")
temp.deleteOnExit()
val args = Array("-I", fq, "-o", temp.getAbsolutePath)
main(args)
......
......@@ -29,9 +29,13 @@ class SageCreateLibaryTest extends TestNGSuite with MockitoSugar with Matchers {
val input = resourcePath("/mini.transcriptome.fa")
val output = File.createTempFile("sageCreateLibrary", ".tsv")
output.deleteOnExit()
val noTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
noTagsOutput.deleteOnExit()
val antiTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
antiTagsOutput.deleteOnExit()
val allGenesOutput = File.createTempFile("sageCreateLibrary", ".tsv")
allGenesOutput.deleteOnExit()
val args = Array("-I", input, "-o", output.getAbsolutePath, "--tag", "CATG",
"--length", "17", "--noTagsOutput", noTagsOutput.getAbsolutePath, "--noAntiTagsOutput",
......@@ -52,9 +56,13 @@ class SageCreateLibaryTest extends TestNGSuite with MockitoSugar with Matchers {
def testOutPut = {
val input = resourcePath("/mini.transcriptome.fa")
val output = File.createTempFile("sageCreateLibrary", ".tsv")
output.deleteOnExit()
val noTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
noTagsOutput.deleteOnExit()
val antiTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
antiTagsOutput.deleteOnExit()
val allGenesOutput = File.createTempFile("sageCreateLibrary", ".tsv")
allGenesOutput.deleteOnExit()
val args = Array("-I", input, "-o", output.getAbsolutePath, "--tag", "CATG",
"--length", "17", "--noTagsOutput", noTagsOutput.getAbsolutePath, "--noAntiTagsOutput",
......
......@@ -26,9 +26,13 @@ class SageCreateTagCountsTest extends TestNGSuite with MockitoSugar with Matcher
val tagLib = resourcePath("/sageTest.tsv")
val sense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
sense.deleteOnExit()
val allSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
allSense.deleteOnExit()
val antiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
antiSense.deleteOnExit()
val allAntiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
allAntiSense.deleteOnExit()
noException should be thrownBy main(Array("-I", input, "--tagLib", tagLib,
"--countSense", sense.getAbsolutePath, "--countAllSense", allSense.getAbsolutePath,
......@@ -50,9 +54,13 @@ class SageCreateTagCountsTest extends TestNGSuite with MockitoSugar with Matcher
val tagLib = resourcePath("/sageTest.tsv")
val sense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
sense.deleteOnExit()
val allSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
allSense.deleteOnExit()
val antiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
antiSense.deleteOnExit()
val allAntiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
allAntiSense.deleteOnExit()
main(Array("-I", input, "--tagLib", tagLib, "--countSense", sense.getAbsolutePath,
"--countAllSense", allSense.getAbsolutePath, "--countAntiSense", antiSense.getAbsolutePath,
......
......@@ -21,6 +21,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
def testCorrectSampleTsv = {
val tsv = resourcePath("/sample.tsv")
val output = File.createTempFile("testCorrectSampleTsv", ".json")
output.deleteOnExit()
noException should be thrownBy main(Array("-i", tsv, "-o", output.toString))
}
......@@ -29,6 +30,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
def testNoSampleColumn() = {
val tsv = resourcePath("/no_sample.tsv")
val output = File.createTempFile("testNoSampleColumn", ".json")
output.deleteOnExit()
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
thrown.getMessage should equal("Sample column does not exist in: " + tsv)
}
......@@ -37,6 +39,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
def testNumberInLibs = {
val tsv = resourcePath("/number.tsv")
val output = File.createTempFile("testNumberInLibs", ".json")
output.deleteOnExit()
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
thrown.getMessage should equal("Sample or library may not start with a number")
}
......@@ -45,6 +48,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
def testSampleIDs = {
val tsv = resourcePath("/same.tsv")
val output = File.createTempFile("testSampleIDs", ".json")
output.deleteOnExit()
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
thrown.getMessage should equal("Combination of Sample_ID_1 and Lib_ID_1 is found multiple times")
......
......@@ -24,6 +24,7 @@ class SummaryToTsvTest extends TestNGSuite with MockitoSugar with Matchers {
def testMain = {
val tsv = resourcePath("/test.summary.json")
val output = File.createTempFile("main", "tsv")
output.deleteOnExit()
noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
"-m", "root", "-o", output.toString))
......
......@@ -47,50 +47,57 @@ class VcfWithVcfTest extends TestNGSuite with MockitoSugar with Matchers {
val rand = new Random()
@Test def testOutputTypeVcf() = {
val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
tmpFile.deleteOnExit()
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
main(arguments)
}
@Test def testOutputTypeVcfGz() = {
val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf.gz").getAbsolutePath
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf.gz")
tmpFile.deleteOnExit()
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
main(arguments)
}
@Test def testOutputTypeBcf() = {
val tmpPath = File.createTempFile("VcfWithVcf_", ".bcf").getAbsolutePath
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
val tmpFile = File.createTempFile("VcfWithVcf_", ".bcf")
tmpFile.deleteOnExit()
val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
main(arguments)
}
@Test def testOutputFieldException = {
val tmpPath = File.createTempFile("VCFWithVCf", ".vcf").getAbsolutePath
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:AC")
val tmpFile = File.createTempFile("VCFWithVCf", ".vcf")
tmpFile.deleteOnExit()
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:AC")
an[IllegalArgumentException] should be thrownBy main(args)
val thrown = the[IllegalArgumentException] thrownBy main(args)
thrown.getMessage should equal("Field 'AC' already exists in input vcf")
}
@Test def testInputFieldException = {
val tmpPath = File.createTempFile("VCFWithVCf", ".vcf").getAbsolutePath
val args = Array("-I", unveppedPath, "-s", unveppedPath, "-o", tmpPath, "-f", "CSQ:NEW_CSQ")
val tmpFile = File.createTempFile("VCFWithVCf", ".vcf")
tmpFile.deleteOnExit()
val args = Array("-I", unveppedPath, "-s", unveppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:NEW_CSQ")
an[IllegalArgumentException] should be thrownBy main(args)
val thrown = the[IllegalArgumentException] thrownBy main(args)
thrown.getMessage should equal("Field 'CSQ' does not exist in secondary vcf")
}
@Test def testMinMethodException = {
val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:CSQ:min")
val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
tmpFile.deleteOnExit()
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:CSQ:min")
an[IllegalArgumentException] should be thrownBy main(args)
val thrown = the[IllegalArgumentException] thrownBy main(args)
thrown.getMessage should equal("Type of field CSQ is not numeric")
}
@Test def testMaxMethodException = {
val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:CSQ:max")
val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
tmpFile.deleteOnExit()
val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:CSQ:max")
an[IllegalArgumentException] should be thrownBy main(args)
val thrown = the[IllegalArgumentException] thrownBy main(args)
thrown.getMessage should equal("Type of field CSQ is not numeric")
......
......@@ -47,38 +47,44 @@ class VepNormalizerTest extends TestNGSuite with MockitoSugar with Matchers {
val rand = new Random()
@Test def testGzOutputExplode(): Unit = {
val tmpPath = File.createTempFile("VepNormalizer_", ".vcf.gz").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpPath, "-m", "explode")
val tmpFile = File.createTempFile("VepNormalizer_", ".vcf.gz")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
main(arguments)
}
@Test def testVcfOutputExplode(): Unit = {
val tmpPath = File.createTempFile("VepNormalizer_", ".vcf").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpPath, "-m", "explode")
val tmpFile = File.createTempFile("VepNormalizer_", ".vcf")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
main(arguments)
}
@Test def testBcfOutputExplode(): Unit = {
val tmp_path = File.createTempFile("VepNormalizer_", ".bcf").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "explode")
val tmpFile = File.createTempFile("VepNormalizer_", ".bcf")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
main(arguments)
}
@Test def testGzOutputStandard(): Unit = {
val tmp_path = File.createTempFile("VepNormalizer_", ".vcf.gz").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
val tmpFile = File.createTempFile("VepNormalizer_", ".vcf.gz")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
main(arguments)
}
@Test def testVcfOutputStandard(): Unit = {
val tmp_path = File.createTempFile("VepNormalizer_", ".vcf").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
val tmpFile = File.createTempFile("VepNormalizer_", ".vcf")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
main(arguments)
}
@Test def testBcfOutputStandard(): Unit = {
val tmp_path = File.createTempFile("VepNormalizer_", ".bcf").getAbsolutePath
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
val tmpFile = File.createTempFile("VepNormalizer_", ".bcf")
tmpFile.deleteOnExit()
val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
main(arguments)
}
......
......@@ -28,7 +28,11 @@ trait Rscript extends Configurable {
} else {
val rScript: File = dir match {
case Some(dir) => new File(dir, script.getName)
case _ => File.createTempFile(script.getName, ".R")
case _ => {
val file = File.createTempFile(script.getName, ".R")
file.deleteOnExit()
file
}
}
if (!rScript.getParentFile.exists) rScript.getParentFile.mkdirs
......
......@@ -228,6 +228,7 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
object ConfigUtilsTest {
def writeTemp(text: String, extension: String): File = {
val file = File.createTempFile("TestConfigUtils.", extension)
file.deleteOnExit()
val w = new PrintWriter(file)
w.write(text)
w.close()
......
......@@ -39,6 +39,7 @@ class BedRecordListTest extends TestNGSuite with Matchers {
records.header shouldBe Nil
val tempFile = File.createTempFile("region", ".bed")
tempFile.deleteOnExit()
records.writeToFile(tempFile)
BedRecordList.fromFile(tempFile) shouldBe records
tempFile.delete()
......@@ -50,6 +51,7 @@ class BedRecordListTest extends TestNGSuite with Matchers {
records.header shouldBe BedRecordListTest.ucscHeader.split("\n").toList
val tempFile = File.createTempFile("region", ".bed")
tempFile.deleteOnExit()
records.writeToFile(tempFile)
BedRecordList.fromFile(tempFile) shouldBe records
tempFile.delete()
......@@ -129,13 +131,6 @@ class BedRecordListTest extends TestNGSuite with Matchers {
list.scatter(100).allRecords.size shouldBe 15
list.scatter(100).length shouldBe 1500
}
@AfterClass
def end: Unit = {
BedRecordListTest.bedFile.delete()
BedRecordListTest.corruptBedFile.delete()
BedRecordListTest.bedFileUcscHeader.delete()
}
}
object BedRecordListTest {
......@@ -149,6 +144,9 @@ object BedRecordListTest {
|chr22 2000 6000 cloneB 900 - 2000 6000 0 2 433,399 0,3601""".stripMargin
val bedFile = File.createTempFile("regions", ".bed")
bedFile.deleteOnExit()
val corruptBedFile = File.createTempFile("regions", ".bed")
corruptBedFile.deleteOnExit()
val bedFileUcscHeader = File.createTempFile("regions", ".bed")
bedFileUcscHeader.deleteOnExit()
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment