Commit 4a71cc17 authored by Peter van 't Hof's avatar Peter van 't Hof

Adding basic unit tests

parent 725b91d5
......@@ -23,6 +23,18 @@
<artifactId>Mapping</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.11</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -40,6 +40,9 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
def biopetScript: Unit = {
val callers = usedCallers.sortBy(_.prio)
require(!inputBams.isEmpty, "No input bams found")
require(callers.exists(_.use), "must select atleast 1 variantcaller")
val cv = new CombineVariants(qscript)
cv.outputFile = finalFile
cv.setKey = "VariantCaller"
......
package nl.lumc.sasc.biopet.pipelines.shiva
import java.io.File
import com.google.common.io.Files
import nl.lumc.sasc.biopet.core.config.Config
import nl.lumc.sasc.biopet.extensions.bcftools.Bcftools
import nl.lumc.sasc.biopet.extensions.gatk.CombineVariants
import nl.lumc.sasc.biopet.tools.{VcfFilter, MpileupToVcf}
import nl.lumc.sasc.biopet.utils.ConfigUtils
import org.apache.commons.io.FileUtils
import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{ AfterClass, Test, DataProvider }
/**
* Created by pjvan_thof on 3/2/15.
*/
class ShivaVariantcallingTest extends TestNGSuite with Matchers {
def initPipeline(map: Map[String, Any]): ShivaVariantcalling = {
new ShivaVariantcalling {
override def configName = "shivavariantcalling"
override def globalConfig = new Config(ConfigUtils.mergeMaps(map, ShivaVariantcallingTest.config))
qSettings = new QSettings
qSettings.runName = "test"
}
}
@DataProvider(name = "shivaVariantcallingOptions")
def mappingOptions = {
val raw = Array(true, false)
val bcftools = Array(true, false)
(for (
bams <- 0 to 3;
raw <- raw;
bcftools <- bcftools
) yield Array[Any](bams, raw, bcftools)
).toArray
}
@Test(dataProvider = "shivaVariantcallingOptions")
def testShivaVariantcalling(bams: Int, raw: Boolean, bcftools: Boolean) = {
val map = Map("use_raw" -> raw, "use_bcftools" -> bcftools)
val pipeline = initPipeline(map)
pipeline.inputBams = (for (n <- 1 to bams) yield new File("bam_" + n + ".bam")).toList
val illegalArgumentException = pipeline.inputBams.isEmpty || !raw && !bcftools
if (illegalArgumentException) intercept[IllegalArgumentException] {
pipeline.script()
}
if (!illegalArgumentException) {
pipeline.script()
pipeline.functions.count(_.isInstanceOf[CombineVariants]) shouldBe 1 + (if (raw) 1 else 0)
//pipeline.functions.count(_.isInstanceOf[Bcftools]) shouldBe (if (bcftools) 1 else 0)
//FIXME: Can not check for bcftools because of piping
pipeline.functions.count(_.isInstanceOf[MpileupToVcf]) shouldBe (if (raw) bams else 0)
pipeline.functions.count(_.isInstanceOf[VcfFilter]) shouldBe (if (raw) bams else 0)
}
}
@AfterClass def removeTempOutputDir() = {
FileUtils.deleteDirectory(ShivaVariantcallingTest.outputDir)
}
}
object ShivaVariantcallingTest {
val outputDir = Files.createTempDir()
val config = Map(
"name_prefix" -> "test",
"output_dir" -> outputDir,
"reference" -> "test",
"gatk_jar" -> "test",
"samtools" -> Map("exe" -> "test"),
"bcftools" -> Map("exe" -> "test")
)
}
\ 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