Commit 8962942b authored by Peter van 't Hof's avatar Peter van 't Hof

Added unit testing

parent 2da435a6
......@@ -24,7 +24,7 @@ import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/** Extension for zcat */
class Zcat(val root: Configurable) extends BiopetCommandLineFunction with Version {
@Input(doc = "Zipped file", required = true)
var input: List[File] = _
var input: List[File] = Nil
@Output(doc = "Unzipped file", required = true)
var output: File = _
......
......@@ -16,7 +16,7 @@
package nl.lumc.sasc.biopet
import nl.lumc.sasc.biopet.pipelines.generateindexes.GenerateIndexes
import nl.lumc.sasc.biopet.utils.{BiopetExecutable, MainCommand}
import nl.lumc.sasc.biopet.utils.{ BiopetExecutable, MainCommand }
object BiopetExecutableMain extends BiopetExecutable {
def pipelines: List[MainCommand] = List(
......
......@@ -45,6 +45,18 @@
<artifactId>BiopetExtensions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package nl.lumc.sasc.biopet.pipelines.generateindexes
import java.io.File
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
/**
* Created by pjvan_thof on 13-5-16.
*/
class FastaMerging(val root: Configurable) extends BiopetCommandLineFunction {
@Input
var input: List[File] = Nil
@Output(required = true)
var output: File = _
var cmds: Array[BiopetCommandLineFunction] = Array()
def cmdLine = cmds.mkString(" && ")
}
......@@ -19,9 +19,9 @@ import java.io.PrintWriter
import java.util
import nl.lumc.sasc.biopet.core.extensions.Md5sum
import nl.lumc.sasc.biopet.core.{BiopetCommandLineFunction, BiopetQScript, PipelineCommand}
import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, BiopetQScript, PipelineCommand }
import nl.lumc.sasc.biopet.extensions._
import nl.lumc.sasc.biopet.extensions.bowtie.{Bowtie2Build, BowtieBuild}
import nl.lumc.sasc.biopet.extensions.bowtie.{ Bowtie2Build, BowtieBuild }
import nl.lumc.sasc.biopet.extensions.bwa.BwaIndex
import nl.lumc.sasc.biopet.extensions.gatk.CombineVariants
import nl.lumc.sasc.biopet.extensions.gmap.GmapBuild
......@@ -30,6 +30,7 @@ import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsFaidx
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.utils.commandline.Output
import scala.collection.JavaConversions._
import scala.language.reflectiveCalls
......@@ -40,7 +41,7 @@ class GenerateIndexes(val root: Configurable) extends QScript with BiopetQScript
@Argument(required = true)
var referenceConfigFiles: List[File] = Nil
var referenceConfig: Map[String, Any] = Map()
var referenceConfig: Map[String, Any] = null
var configDeps: List[File] = Nil
......@@ -48,7 +49,8 @@ class GenerateIndexes(val root: Configurable) extends QScript with BiopetQScript
/** This is executed before the script starts */
def init(): Unit = {
referenceConfig = referenceConfigFiles.foldLeft(Map[String, Any]())((a,b) => ConfigUtils.mergeMaps(a, ConfigUtils.fileToConfigMap(b)))
if (referenceConfig == null)
referenceConfig = referenceConfigFiles.foldLeft(Map[String, Any]())((a, b) => ConfigUtils.mergeMaps(a, ConfigUtils.fileToConfigMap(b)))
}
/** Method where jobs must be added */
......@@ -61,8 +63,8 @@ class GenerateIndexes(val root: Configurable) extends QScript with BiopetQScript
val genomeConfig = ConfigUtils.any2map(c)
val fastaUris = genomeConfig.getOrElse("fasta_uri",
throw new IllegalArgumentException(s"No fasta_uri found for $speciesName - $genomeName")) match {
case a: Array[_] => a.map(_.toString)
case a => Array(a.toString)
case a: Traversable[_] => a.map(_.toString).toArray
case a => Array(a.toString)
}
val genomeDir = new File(speciesDir, genomeName)
......@@ -83,16 +85,8 @@ class GenerateIndexes(val root: Configurable) extends QScript with BiopetQScript
curl.output
}
val fastaCat = new CommandLineFunction {
var cmds: Array[BiopetCommandLineFunction] = Array()
@Input
var input: List[File] = Nil
@Output
var output = fastaFile
def commandLine = cmds.mkString(" && ")
}
val fastaCat = new FastaMerging(this)
fastaCat.output = fastaFile
if (fastaUris.length > 1 || fastaFiles.filter(_.getName.endsWith(".gz")).nonEmpty) {
fastaFiles.foreach { file =>
......@@ -260,6 +254,8 @@ class GenerateIndexes(val root: Configurable) extends QScript with BiopetQScript
add(new InProcessFunction {
@Input val deps: List[File] = configDeps
@Output val out = outputConfigFile
def run: Unit = {
val writer = new PrintWriter(outputConfigFile)
writer.println(ConfigUtils.mapToJson(Map("references" -> outputConfig)).spaces2)
......
package nl.lumc.sasc.biopet.pipelines.generateindexes
import com.google.common.io.Files
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.config.Config
import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvan_thof on 13-5-16.
*/
class GenerateIndexesTest extends TestNGSuite with Matchers {
def initPipeline(map: Map[String, Any]): GenerateIndexes = {
new GenerateIndexes() {
override def configNamespace = "generateindexes"
override def globalConfig = new Config(ConfigUtils.mergeMaps(map, GenerateIndexesTest.config))
qSettings = new QSettings
qSettings.runName = "test"
}
}
@Test
def testNoFastaUri: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("" -> "")))
intercept[IllegalArgumentException] {
pipeline.script()
}
}
@Test
def testSingleFasta: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri")))
pipeline.script()
}
@Test
def testMultiFasta: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> List("uri", "uri2", "uri3.gz"))))
pipeline.script()
}
@Test
def testSingleDbsnp: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri", "dbsnp_vcf_uri" -> "uri.vcf.gz")))
pipeline.script()
}
@Test
def testMultiDbsnp: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri", "dbsnp_vcf_uri" -> List("uri.vcf.gz", "uri2.vcf.gz"))))
pipeline.script()
}
@Test
def testVep: Unit = {
val pipeline = initPipeline(Map())
pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri", "vep_cache_uri" -> "something/human_vep_80_hg19.tar.gz")))
pipeline.script()
}
}
object GenerateIndexesTest {
val outputDir = Files.createTempDir()
outputDir.deleteOnExit()
val config = Map("output_dir" -> outputDir,
"bwa" -> Map("exe" -> "test"),
"star" -> Map("exe" -> "test"),
"bowtiebuild" -> Map("exe" -> "test"),
"bowtie2build" -> Map("exe" -> "test"),
"gmapbuild" -> Map("exe" -> "test"),
"samtools" -> Map("exe" -> "test"),
"md5sum" -> Map("exe" -> "test"),
"gatk_jar" -> "test",
"tabix" -> Map("exe" -> "test")
)
}
......@@ -161,6 +161,7 @@ class ShivaWithAnnotationTest extends ShivaTestTrait {
object ShivaTest {
val outputDir = Files.createTempDir()
outputDir.deleteOnExit()
new File(outputDir, "input").mkdirs()
def inputTouch(name: String): String = {
val file = new File(outputDir, "input" + File.separator + 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