Commit 6c7f4701 authored by Peter van 't Hof's avatar Peter van 't Hof

Fixed unit tests

parent a87e2991
......@@ -93,6 +93,12 @@ class ShivaTest extends TestNGSuite with Matchers {
object ShivaTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): String = {
val file = new File(outputDir, "input" + File.separator + name)
Files.touch(file)
file.getAbsolutePath
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......@@ -136,8 +142,8 @@ object ShivaTest {
val sample1 = Map(
"samples" -> Map("sample1" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "1_1_R1.fq",
"R2" -> "1_1_R2.fq"
"R1" -> inputTouch("1_1_R1.fq"),
"R2" -> inputTouch("1_1_R2.fq")
)
)
)))
......@@ -145,8 +151,8 @@ object ShivaTest {
val sample2 = Map(
"samples" -> Map("sample2" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "2_1_R1.fq",
"R2" -> "2_1_R2.fq"
"R1" -> inputTouch("2_1_R1.fq"),
"R2" -> inputTouch("2_1_R2.fq")
)
)
)))
......@@ -154,12 +160,12 @@ object ShivaTest {
val sample3 = Map(
"samples" -> Map("sample3" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "3_1_R1.fq",
"R2" -> "3_1_R2.fq"
"R1" -> inputTouch("3_1_R1.fq"),
"R2" -> inputTouch("3_1_R2.fq")
),
"lib2" -> Map(
"R1" -> "3_2_R1.fq",
"R2" -> "3_2_R2.fq"
"R1" -> inputTouch("3_2_R1.fq"),
"R2" -> inputTouch("3_2_R2.fq")
)
)
)))
......
......@@ -73,7 +73,7 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
val map = Map("variantcallers" -> callers.toList)
val pipeline = initPipeline(map)
pipeline.inputBams = (for (n <- 1 to bams) yield new File("bam_" + n + ".bam")).toList
pipeline.inputBams = (for (n <- 1 to bams) yield ShivaVariantcallingTest.inputTouch("bam_" + n + ".bam")).toList
val illegalArgumentException = pipeline.inputBams.isEmpty ||
(!raw && !bcftools &&
......@@ -107,6 +107,12 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
object ShivaVariantcallingTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): File = {
val file = new File(outputDir, "input" + File.separator + name).getAbsoluteFile
Files.touch(file)
file
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
......@@ -69,7 +69,7 @@ class BamMetricsTest extends TestNGSuite with Matchers {
Map("regions_of_interest" -> (1 to rois).map("roi_" + _ + ".bed").toList)
val bammetrics: BamMetrics = initPipeline(map)
bammetrics.inputBam = new File("input.bam")
bammetrics.inputBam = BamMetricsTest.bam
bammetrics.sampleId = Some("1")
bammetrics.libId = Some("1")
bammetrics.script()
......@@ -98,6 +98,10 @@ class BamMetricsTest extends TestNGSuite with Matchers {
object BamMetricsTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
val bam = new File(outputDir, "input" + File.separator + "bla.bam")
Files.touch(bam)
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
......@@ -57,7 +57,7 @@ class MpileupToVcf(val root: Configurable) extends ToolCommandFuntion with Refer
}
override def beforeCmd(): Unit = {
if (sample == null && inputBam.exists()) {
if (sample == null && inputBam.exists() && inputBam.length() > 0) {
val inputSam = SamReaderFactory.makeDefault.open(inputBam)
val readGroups = inputSam.getFileHeader.getReadGroups
val samples = readGroups.map(readGroup => readGroup.getSample).distinct
......
......@@ -97,6 +97,12 @@ class CarpTest extends TestNGSuite with Matchers {
object CarpTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): String = {
val file = new File(outputDir, "input" + File.separator + name)
Files.touch(file)
file.getAbsolutePath
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......@@ -127,8 +133,8 @@ object CarpTest {
val sample1 = Map(
"samples" -> Map("sample1" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "1_1_R1.fq",
"R2" -> "1_1_R2.fq"
"R1" -> inputTouch("1_1_R1.fq"),
"R2" -> inputTouch("1_1_R2.fq")
)
)
)))
......@@ -136,8 +142,8 @@ object CarpTest {
val sample2 = Map(
"samples" -> Map("sample2" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "2_1_R1.fq",
"R2" -> "2_1_R2.fq"
"R1" -> inputTouch("2_1_R1.fq"),
"R2" -> inputTouch("2_1_R2.fq")
)
)
)))
......@@ -145,12 +151,12 @@ object CarpTest {
val sample3 = Map(
"samples" -> Map("sample3" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "3_1_R1.fq",
"R2" -> "3_1_R2.fq"
"R1" -> inputTouch("3_1_R1.fq"),
"R2" -> inputTouch("3_1_R2.fq")
),
"lib2" -> Map(
"R1" -> "3_2_R1.fq",
"R2" -> "3_2_R2.fq"
"R1" -> inputTouch("3_2_R1.fq"),
"R2" -> inputTouch("3_2_R2.fq")
)
)
)))
......@@ -158,8 +164,8 @@ object CarpTest {
val threatment1 = Map(
"samples" -> Map("threatment" -> Map("control" -> "control1", "libraries" -> Map(
"lib1" -> Map(
"R1" -> "threatment_1_R1.fq",
"R2" -> "threatment_1_R2.fq"
"R1" -> inputTouch("threatment_1_R1.fq"),
"R2" -> inputTouch("threatment_1_R2.fq")
)
)
)))
......@@ -167,8 +173,8 @@ object CarpTest {
val control1 = Map(
"samples" -> Map("control1" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "control_1_R1.fq",
"R2" -> "control_1_R2.fq"
"R1" -> inputTouch("control_1_R1.fq"),
"R2" -> inputTouch("control_1_R2.fq")
)
)
)))
......
......@@ -67,8 +67,8 @@ class FlexiprepTest extends TestNGSuite with Matchers {
), Map(FlexiprepTest.executables.toSeq: _*))
val flexiprep: Flexiprep = initPipeline(map)
flexiprep.input_R1 = new File(flexiprep.outputDir, "bla_R1.fq" + (if (zipped) ".gz" else ""))
if (paired) flexiprep.input_R2 = Some(new File(flexiprep.outputDir, "bla_R2.fq" + (if (zipped) ".gz" else "")))
flexiprep.input_R1 = (if (zipped) FlexiprepTest.r1Zipped else FlexiprepTest.r1)
if (paired) flexiprep.input_R2 = Some((if (zipped) FlexiprepTest.r2Zipped else FlexiprepTest.r2))
flexiprep.sampleId = Some("1")
flexiprep.libId = Some("1")
flexiprep.script()
......@@ -95,6 +95,16 @@ class FlexiprepTest extends TestNGSuite with Matchers {
object FlexiprepTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
Files.touch(r1)
val r2 = new File(outputDir, "input" + File.separator + "R2.fq")
Files.touch(r2)
val r1Zipped = new File(outputDir, "input" + File.separator + "R1.fq.gz")
Files.touch(r1Zipped)
val r2Zipped = new File(outputDir, "input" + File.separator + "R2.fq.gz")
Files.touch(r2Zipped)
val executables = Map(
"seqstat" -> Map("exe" -> "test"),
......
......@@ -43,8 +43,8 @@ class GentrapTest extends TestNGSuite with Matchers {
/** Convenience method for making library config */
private def makeLibConfig(idx: Int, paired: Boolean = true) = {
val files = Map("R1" -> "test_R1.fq")
if (paired) (s"lib_$idx", files ++ Map("R2" -> "test_R2.fq"))
val files = Map("R1" -> GentrapTest.inputTouch("test_R1.fq"))
if (paired) (s"lib_$idx", files ++ Map("R2" -> GentrapTest.inputTouch("test_R2.fq")))
else (s"lib_$idx", files)
}
......@@ -179,6 +179,12 @@ class GentrapTest extends TestNGSuite with Matchers {
object GentrapTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): String = {
val file = new File(outputDir, "input" + File.separator + name)
Files.touch(file)
file.getAbsolutePath
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
......@@ -79,11 +79,11 @@ class MappingTest extends TestNGSuite with Matchers {
val mapping: Mapping = initPipeline(map)
if (zipped) {
mapping.input_R1 = new File(mapping.outputDir, "bla_R1.fq.gz")
if (paired) mapping.input_R2 = Some(new File(mapping.outputDir, "bla_R2.fq.gz"))
mapping.input_R1 = MappingTest.r1Zipped
if (paired) mapping.input_R2 = Some(MappingTest.r2Zipped)
} else {
mapping.input_R1 = new File(mapping.outputDir, "bla_R1.fq")
if (paired) mapping.input_R2 = Some(new File(mapping.outputDir, "bla_R2.fq"))
mapping.input_R1 = MappingTest.r1
if (paired) mapping.input_R2 = Some(MappingTest.r2)
}
mapping.sampleId = Some("1")
mapping.libId = Some("1")
......@@ -131,6 +131,16 @@ class MappingTest extends TestNGSuite with Matchers {
object MappingTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
Files.touch(r1)
val r2 = new File(outputDir, "input" + File.separator + "R2.fq")
Files.touch(r2)
val r1Zipped = new File(outputDir, "input" + File.separator + "R1.fq.gz")
Files.touch(r1Zipped)
val r2Zipped = new File(outputDir, "input" + File.separator + "R2.fq.gz")
Files.touch(r2Zipped)
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
......@@ -88,6 +88,12 @@ class ShivaTest extends TestNGSuite with Matchers {
object ShivaTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): String = {
val file = new File(outputDir, "input" + File.separator + name)
Files.touch(file)
file.getAbsolutePath
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......@@ -131,8 +137,8 @@ object ShivaTest {
val sample1 = Map(
"samples" -> Map("sample1" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "1_1_R1.fq",
"R2" -> "1_1_R2.fq"
"R1" -> inputTouch("1_1_R1.fq"),
"R2" -> inputTouch("1_1_R2.fq")
)
)
)))
......@@ -140,8 +146,8 @@ object ShivaTest {
val sample2 = Map(
"samples" -> Map("sample2" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "2_1_R1.fq",
"R2" -> "2_1_R2.fq"
"R1" -> inputTouch("2_1_R1.fq"),
"R2" -> inputTouch("2_1_R2.fq")
)
)
)))
......@@ -149,12 +155,12 @@ object ShivaTest {
val sample3 = Map(
"samples" -> Map("sample3" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> "3_1_R1.fq",
"R2" -> "3_1_R2.fq"
"R1" -> inputTouch("3_1_R1.fq"),
"R2" -> inputTouch("3_1_R2.fq")
),
"lib2" -> Map(
"R1" -> "3_2_R1.fq",
"R2" -> "3_2_R2.fq"
"R1" -> inputTouch("3_2_R1.fq"),
"R2" -> inputTouch("3_2_R2.fq")
)
)
)))
......
......@@ -61,7 +61,7 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
val map = Map("variantcallers" -> callers.toList)
val pipeline = initPipeline(map)
pipeline.inputBams = (for (n <- 1 to bams) yield new File("bam_" + n + ".bam")).toList
pipeline.inputBams = (for (n <- 1 to bams) yield ShivaVariantcallingTest.inputTouch("bam_" + n + ".bam")).toList
val illegalArgumentException = pipeline.inputBams.isEmpty || (!raw && !bcftools && !freebayes)
......@@ -88,6 +88,12 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
object ShivaVariantcallingTest {
val outputDir = Files.createTempDir()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): File = {
val file = new File(outputDir, "input" + File.separator + name).getAbsoluteFile
Files.touch(file)
file
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
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