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