Commit 75470c69 authored by Peter van 't Hof's avatar Peter van 't Hof

Changed test for gears

parent a8eedb50
...@@ -48,8 +48,8 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi ...@@ -48,8 +48,8 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi
/** Executed before running the script */ /** Executed before running the script */
def init(): Unit = { def init(): Unit = {
require(fastqR1.isDefined || bamFile.isDefined, "Please specify fastq-file(s) or bam file") if (!fastqR1.isDefined && !bamFile.isDefined) Logging.addError("Please specify fastq-file(s) or bam file")
require(fastqR1.isDefined != bamFile.isDefined, "Provide either a bam file or a R1/R2 file") if (fastqR1.isDefined == bamFile.isDefined) Logging.addError("Provide either a bam file or a R1/R2 file")
if (sampleId == null || sampleId == None) Logging.addError("Missing sample ID on GearsSingle module") if (sampleId == null || sampleId == None) Logging.addError("Missing sample ID on GearsSingle module")
if (outputName == null) { if (outputName == null) {
...@@ -64,7 +64,7 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi ...@@ -64,7 +64,7 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi
if (fastqR1.isDefined) { if (fastqR1.isDefined) {
fastqR1.foreach(inputFiles :+= InputFile(_)) fastqR1.foreach(inputFiles :+= InputFile(_))
fastqR2.foreach(inputFiles :+= InputFile(_)) fastqR2.foreach(inputFiles :+= InputFile(_))
} else inputFiles :+= InputFile(bamFile.get) } else bamFile.foreach(inputFiles :+= InputFile(_))
} }
override def reportClass = { override def reportClass = {
......
...@@ -23,7 +23,6 @@ import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsView ...@@ -23,7 +23,6 @@ import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsView
import nl.lumc.sasc.biopet.extensions.tools.KrakenReportToJson import nl.lumc.sasc.biopet.extensions.tools.KrakenReportToJson
import nl.lumc.sasc.biopet.utils.ConfigUtils import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.config.Config import nl.lumc.sasc.biopet.utils.config.Config
import org.apache.commons.io.FileUtils
import org.broadinstitute.gatk.queue.QSettings import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite import org.scalatest.testng.TestNGSuite
...@@ -35,7 +34,7 @@ import org.testng.annotations._ ...@@ -35,7 +34,7 @@ import org.testng.annotations._
* Created by wyleung on 10/22/15. * Created by wyleung on 10/22/15.
*/ */
class GearsSingleTest extends TestNGSuite with Matchers { abstract class TestGearsSingle extends TestNGSuite with Matchers {
def initPipeline(map: Map[String, Any]): GearsSingle = { def initPipeline(map: Map[String, Any]): GearsSingle = {
new GearsSingle { new GearsSingle {
override def configNamespace = "gearssingle" override def configNamespace = "gearssingle"
...@@ -47,94 +46,159 @@ class GearsSingleTest extends TestNGSuite with Matchers { ...@@ -47,94 +46,159 @@ class GearsSingleTest extends TestNGSuite with Matchers {
} }
} }
@DataProvider(name = "gearsOptions") def paired: Boolean = false
def gearsOptions = { def hasOutputName: Boolean = false
val bool = Array(true, false) def kraken: Option[Boolean] = None
def qiimeClosed: Boolean = false
for ( def qiimeOpen: Boolean = false
fromBam <- bool; def qiimeRtax: Boolean = false
pair <- bool; def seqCount: Boolean = false
hasOutputName <- bool; def downsample: Option[Int] = None
kraken <- bool;
qiimeClosed <- bool; def inputMode: Option[String] = Some("fastq")
qiimeRtax <- bool;
seqCount <- bool
) yield Array("", fromBam, pair, hasOutputName, kraken, qiimeClosed, qiimeRtax, seqCount)
}
@Test(dataProvider = "gearsOptions") @Test
def testGears(dummy: String, def testGears(): Unit = {
fromBam: Boolean,
paired: Boolean,
hasOutputName: Boolean,
kraken: Boolean,
qiimeClosed: Boolean,
qiimeRtax: Boolean,
seqCount: Boolean) = {
val map = ConfigUtils.mergeMaps(Map( val map = ConfigUtils.mergeMaps(Map(
"gears_use_kraken" -> kraken,
"gears_use_qiime_rtax" -> qiimeRtax, "gears_use_qiime_rtax" -> qiimeRtax,
"gears_use_qiime_closed" -> qiimeClosed, "gears_use_qiime_closed" -> qiimeClosed,
"gears_use_qiime_open" -> qiimeOpen,
"gears_use_seq_count" -> seqCount, "gears_use_seq_count" -> seqCount,
"output_dir" -> GearsSingleTest.outputDir "output_dir" -> TestGearsSingle.outputDir
), Map(GearsSingleTest.executables.toSeq: _*)) ) ++
kraken.map("gears_use_kraken" -> _) ++
downsample.map("downsample" -> _),
Map(TestGearsSingle.executables.toSeq: _*))
val gears: GearsSingle = initPipeline(map) val gears: GearsSingle = initPipeline(map)
gears.sampleId = Some("sampleName") gears.sampleId = Some("sampleName")
gears.libId = Some("libName") gears.libId = Some("libName")
if (fromBam) { inputMode match {
gears.bamFile = Some(GearsSingleTest.bam) case Some("fastq") =>
} else { gears.fastqR1 = Some(TestGearsSingle.r1)
gears.fastqR1 = Some(GearsSingleTest.r1) gears.fastqR2 = if (paired) Some(TestGearsSingle.r2) else None
gears.fastqR2 = if (paired) Some(GearsSingleTest.r2) else None case Some("bam") => gears.bamFile = Some(TestGearsSingle.bam)
case None =>
case _ => new IllegalStateException(s"$inputMode not allowed as inputMode")
} }
if (hasOutputName) if (hasOutputName)
gears.outputName = "test" gears.outputName = "test"
gears.script() if (inputMode.isEmpty) {
intercept[IllegalArgumentException] {
if (hasOutputName) { gears.script()
gears.outputName shouldBe "test" }
} else { } else {
// in the following cases the filename should have been determined by the filename
gears.outputName shouldBe (if (fromBam) "bamfile" else "R1") gears.script()
if (hasOutputName) {
gears.outputName shouldBe "test"
} else {
// in the following cases the filename should have been determined by the filename
gears.outputName shouldBe (if (inputMode == Some("bam")) "bamfile" else "R1")
}
gears.summarySettings("gears_use_kraken") shouldBe kraken.getOrElse(true)
gears.summarySettings("gear_use_qiime_rtax") shouldBe qiimeRtax
gears.summarySettings("gear_use_qiime_closed") shouldBe qiimeClosed
gears.summarySettings("gear_use_qiime_open") shouldBe qiimeOpen
gears.krakenScript.isDefined shouldBe kraken.getOrElse(true)
gears.qiimeClosed.isDefined shouldBe qiimeClosed
gears.qiimeOpen.isDefined shouldBe qiimeOpen
gears.qiimeRatx.isDefined shouldBe qiimeRtax
gears.seqCount.isDefined shouldBe seqCount
// SamToFastq should have started if it was started from bam
gears.functions.count(_.isInstanceOf[SamtoolsView]) shouldBe (if (inputMode == Some("bam")) 1 else 0)
gears.functions.count(_.isInstanceOf[SamToFastq]) shouldBe (if (inputMode == Some("bam")) 1 else 0)
gears.functions.count(_.isInstanceOf[Kraken]) shouldBe (if (kraken.getOrElse(true)) 1 else 0)
gears.functions.count(_.isInstanceOf[KrakenReport]) shouldBe (if (kraken.getOrElse(true)) 1 else 0)
gears.functions.count(_.isInstanceOf[KrakenReportToJson]) shouldBe (if (kraken.getOrElse(true)) 1 else 0)
} }
}
}
gears.krakenScript.isDefined shouldBe kraken class GearsSingleNoInputTest extends TestGearsSingle {
gears.qiimeClosed.isDefined shouldBe qiimeClosed override def inputMode = None
gears.qiimeRatx.isDefined shouldBe qiimeRtax }
gears.seqCount.isDefined shouldBe seqCount
// SamToFastq should have started if it was started from bam class GearsSingleDefaultTest extends TestGearsSingle
gears.functions.count(_.isInstanceOf[SamtoolsView]) shouldBe (if (fromBam) 1 else 0) class GearsSingleKrakenTest extends TestGearsSingle {
gears.functions.count(_.isInstanceOf[SamToFastq]) shouldBe (if (fromBam) 1 else 0) override def kraken = Some(true)
}
class GearsSingleQiimeClosedTest extends TestGearsSingle {
override def qiimeClosed = true
}
class GearsSingleQiimeOpenTest extends TestGearsSingle {
override def qiimeOpen = true
}
class GearsSingleQiimeRtaxTest extends TestGearsSingle {
override def qiimeRtax = true
}
class GearsSingleseqCountTest extends TestGearsSingle {
override def seqCount = true
}
gears.functions.count(_.isInstanceOf[Kraken]) shouldBe (if (kraken) 1 else 0) class GearsSingleKrakenPairedTest extends TestGearsSingle {
gears.functions.count(_.isInstanceOf[KrakenReport]) shouldBe (if (kraken) 1 else 0) override def paired = true
gears.functions.count(_.isInstanceOf[KrakenReportToJson]) shouldBe (if (kraken) 1 else 0) override def kraken = Some(true)
} }
class GearsSingleQiimeClosedPairedTest extends TestGearsSingle {
override def paired = true
override def qiimeClosed = true
}
class GearsSingleQiimeOpenPairedTest extends TestGearsSingle {
override def paired = true
override def qiimeOpen = true
}
class GearsSingleQiimeRtaxPairedTest extends TestGearsSingle {
override def paired = true
override def qiimeRtax = true
}
class GearsSingleseqCountPairedTest extends TestGearsSingle {
override def paired = true
override def seqCount = true
}
@Test class GearsSingleAllTest extends TestGearsSingle {
def testNoSample: Unit = { override def kraken = Some(true)
val map = ConfigUtils.mergeMaps(Map( override def qiimeClosed = true
"output_dir" -> GearsSingleTest.outputDir override def qiimeOpen = true
), Map(GearsSingleTest.executables.toSeq: _*)) override def qiimeRtax = true
val gears: GearsSingle = initPipeline(map) override def seqCount = true
}
class GearsSingleAllPairedTest extends TestGearsSingle {
override def kraken = Some(true)
override def qiimeClosed = true
override def qiimeOpen = true
override def qiimeRtax = true
override def seqCount = true
override def paired = true
}
intercept[IllegalArgumentException] { class GearsSingleBamTest extends TestGearsSingle {
gears.script() override def inputMode = Some("bam")
} }
}
// remove temporary run directory all tests in the class have been run class GearsSingleQiimeClosedDownsampleTest extends TestGearsSingle {
@AfterClass def removeTempOutputDir() = { override def paired = true
FileUtils.deleteDirectory(GearsSingleTest.outputDir) override def qiimeClosed = true
} override def downsample = Some(10000)
}
class GearsSingleQiimeOpenDownsampleTest extends TestGearsSingle {
override def paired = true
override def qiimeOpen = true
override def downsample = Some(10000)
} }
object GearsSingleTest { object TestGearsSingle {
val outputDir = Files.createTempDir() val outputDir = Files.createTempDir()
outputDir.deleteOnExit()
new File(outputDir, "input").mkdirs() new File(outputDir, "input").mkdirs()
val r1 = new File(outputDir, "input" + File.separator + "R1.fq") val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
...@@ -155,6 +219,7 @@ object GearsSingleTest { ...@@ -155,6 +219,7 @@ object GearsSingleTest {
"md5sum" -> Map("exe" -> "test"), "md5sum" -> Map("exe" -> "test"),
"assigntaxonomy" -> Map("exe" -> "test"), "assigntaxonomy" -> Map("exe" -> "test"),
"pickclosedreferenceotus" -> Map("exe" -> "test"), "pickclosedreferenceotus" -> Map("exe" -> "test"),
"pickopenreferenceotus" -> Map("exe" -> "test"),
"pickotus" -> Map("exe" -> "test"), "pickotus" -> Map("exe" -> "test"),
"pickrepset" -> Map("exe" -> "test"), "pickrepset" -> Map("exe" -> "test"),
"splitlibrariesfastq" -> Map("exe" -> "test"), "splitlibrariesfastq" -> Map("exe" -> "test"),
......
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version> <version>2.18.1</version>
<configuration> <configuration>
<reuseForks>false</reuseForks>
<forkCount>1C</forkCount> <forkCount>1C</forkCount>
<argLine>-Xmx300m</argLine> <argLine>-Xmx300m</argLine>
<workingDirectory>${project.build.directory}</workingDirectory> <workingDirectory>${project.build.directory}</workingDirectory>
......
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