Skip to content
Snippets Groups Projects
Commit 68182a4a authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added more tests

parent ac9e3325
No related branches found
No related tags found
No related merge requests found
......@@ -44,5 +44,17 @@
<artifactId>Shiva</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>
......@@ -13,19 +13,18 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
qscript =>
def this() = this(null)
override def callers = {
override def callersList = {
new HaplotypeCallerGvcf ::
new HaplotypeCallerAllele ::
new UnifiedGenotyperAllele ::
new UnifiedGenotyper ::
new HaplotypeCaller ::
super.callers
super.callersList
}
class HaplotypeCaller extends Variantcaller {
val name = "haplotypecaller"
protected val defaultPrio = 1
protected val defaultUse = true
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller.vcf.gz")
......@@ -40,7 +39,6 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
class UnifiedGenotyper extends Variantcaller {
val name = "unifiedgenotyper"
protected val defaultPrio = 20
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + ".unifiedgenotyper.vcf.gz")
......@@ -55,7 +53,6 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
class HaplotypeCallerAllele extends Variantcaller {
val name = "haplotypecaller_allele"
protected val defaultPrio = 5
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller_allele.vcf.gz")
......@@ -72,7 +69,6 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
class UnifiedGenotyperAllele extends Variantcaller {
val name = "unifiedgenotyper_allele"
protected val defaultPrio = 9
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + ".unifiedgenotyper_allele.vcf.gz")
......@@ -89,7 +85,6 @@ class ShivaVariantcallingGatk(val root: Configurable) extends QScript with Shiva
class HaplotypeCallerGvcf extends Variantcaller {
val name = "haplotypecaller_gvcf"
protected val defaultPrio = 5
protected val defaultUse = false
def outputFile = new File(outputDir, namePrefix + ".haplotypecaller_gvcf.vcf.gz")
......
package nl.lumc.sasc.biopet.pipelines.gatk
import java.io.File
import com.google.common.io.Files
import nl.lumc.sasc.biopet.core.config.Config
import nl.lumc.sasc.biopet.extensions.gatk.CombineVariants
import nl.lumc.sasc.biopet.extensions.gatk.broad.{UnifiedGenotyper, HaplotypeCaller}
import nl.lumc.sasc.biopet.tools.{VcfStats, MpileupToVcf, VcfFilter}
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.{DataProvider, Test, AfterClass}
import scala.collection.mutable.ListBuffer
/**
* Created by pjvan_thof on 3/2/15.
*/
class ShivaVariantcallingTest extends TestNGSuite with Matchers {
def initPipeline(map: Map[String, Any]): ShivaVariantcallingGatk = {
new ShivaVariantcallingGatk() {
override def configName = "shivavariantcalling"
override def globalConfig = new Config(ConfigUtils.mergeMaps(map, ShivaVariantcallingTest.config))
qSettings = new QSettings
qSettings.runName = "test"
}
}
@DataProvider(name = "shivaVariantcallingOptions")
def shivaVariantcallingOptions = {
val raw = Array(true, false)
val bcftools = Array(true, false)
val haplotypeCallerGvcf = Array(true, false)
val haplotypeCallerAllele = Array(true, false)
val unifiedGenotyperAllele = Array(true, false)
val unifiedGenotyper = Array(true, false)
val haplotypeCaller = Array(true, false)
(for (
bams <- 0 to 2;
raw <- raw;
bcftools <- bcftools;
haplotypeCallerGvcf <- haplotypeCallerGvcf;
haplotypeCallerAllele <- haplotypeCallerAllele;
unifiedGenotyperAllele <- unifiedGenotyperAllele;
unifiedGenotyper <- unifiedGenotyper;
haplotypeCaller <- haplotypeCaller
) yield Array[Any](bams, raw, bcftools, unifiedGenotyper, haplotypeCaller, haplotypeCallerGvcf, haplotypeCallerAllele, unifiedGenotyperAllele)
).toArray
}
@Test(dataProvider = "shivaVariantcallingOptions")
def testShivaVariantcalling(bams: Int,
raw: Boolean,
bcftools: Boolean,
unifiedGenotyper: Boolean,
haplotypeCaller: Boolean,
haplotypeCallerGvcf: Boolean,
haplotypeCallerAllele: Boolean,
unifiedGenotyperAllele: Boolean) = {
val callers: ListBuffer[String] = ListBuffer()
if (raw) callers.append("raw")
if (bcftools) callers.append("bcftools")
if (unifiedGenotyper) callers.append("unifiedgenotyper")
if (haplotypeCallerGvcf) callers.append("haplotypecaller_gvcf")
if (haplotypeCallerAllele) callers.append("haplotypecaller_allele")
if (unifiedGenotyperAllele) callers.append("unifiedgenotyper_allele")
if (haplotypeCaller) callers.append("haplotypecaller")
val map = Map("variantcallers"-> callers.toList)
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 &&
!haplotypeCaller && !unifiedGenotyper &&
!haplotypeCallerGvcf && !haplotypeCallerAllele && !unifiedGenotyperAllele)
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)
pipeline.functions.count(_.isInstanceOf[HaplotypeCaller]) shouldBe (if (haplotypeCaller) 1 else 0) +
(if (haplotypeCallerAllele) 1 else 0) + (if (haplotypeCallerGvcf) bams else 0)
pipeline.functions.count(_.isInstanceOf[UnifiedGenotyper]) shouldBe (if (unifiedGenotyper) 1 else 0) +
(if (unifiedGenotyperAllele) 1 else 0)
pipeline.functions.count(_.isInstanceOf[VcfStats]) shouldBe (1 + callers.size)
}
}
@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"),
"input_alleles" -> "test"
)
}
\ No newline at end of file
......@@ -38,10 +38,11 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
def finalFile = new File(outputDir, namePrefix + ".final.vcf.gz")
def biopetScript: Unit = {
val callers = usedCallers.sortBy(_.prio)
val configCallers: Set[String] = config("variantcallers")
val callers = callersList.filter(x => configCallers.contains(x.name)).sortBy(_.prio)
require(!inputBams.isEmpty, "No input bams found")
require(callers.exists(_.use), "must select atleast 1 variantcaller")
require(!callers.isEmpty, "must select atleast 1 variantcaller, possible to use: " + callersList.map(_.name).mkString(", "))
val cv = new CombineVariants(qscript)
cv.outputFile = finalFile
......@@ -69,15 +70,11 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
addSummaryJobs
}
def callers: List[Variantcaller] = List(new RawVcf, new Bcftools)
def usedCallers: List[Variantcaller] = callers.filter(_.use)
protected def callersList: List[Variantcaller] = List(new RawVcf, new Bcftools)
trait Variantcaller {
val name: String
def outputDir = new File(qscript.outputDir, name)
protected val defaultUse: Boolean
lazy val use: Boolean = config("use_" + name, default = defaultUse)
protected val defaultPrio: Int
lazy val prio: Int = config("prio_" + name, default = defaultPrio)
def addJobs()
......@@ -87,7 +84,6 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
class Bcftools extends Variantcaller {
val name = "bcftools"
protected val defaultPrio = 8
protected val defaultUse = true
def outputFile = new File(outputDir, namePrefix + ".bcftools.vcf.gz")
......@@ -117,7 +113,6 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
class RawVcf extends Variantcaller {
val name = "raw"
protected val defaultPrio = 999
protected val defaultUse = true
def outputFile = new File(outputDir, namePrefix + ".raw.vcf.gz")
......@@ -154,5 +149,8 @@ trait ShivaVariantcallingTrait extends SummaryQScript with SampleLibraryTag {
def summarySettings = Map()
def summaryFiles: Map[String, File] = usedCallers.map(x => (x.name -> x.outputFile)).toMap + ("final" -> finalFile)
def summaryFiles: Map[String, File] = {
val callers: Set[String] = config("variantcallers")
callersList.filter(x => callers.contains(x.name)).map(x => (x.name -> x.outputFile)).toMap + ("final" -> finalFile)
}
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{ AfterClass, Test, DataProvider }
import scala.collection.mutable.ListBuffer
/**
* Created by pjvan_thof on 3/2/15.
*/
......@@ -36,17 +38,20 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
raw <- raw;
bcftools <- bcftools
) yield Array[Any](bams, raw, bcftools)
).toArray
).toArray
}
@Test(dataProvider = "shivaVariantcallingOptions")
def testShivaVariantcalling(bams: Int, raw: Boolean, bcftools: Boolean) = {
val map = Map("use_raw" -> raw, "use_bcftools" -> bcftools)
val callers: ListBuffer[String] = ListBuffer()
if (raw) callers.append("raw")
if (bcftools) callers.append("bcftools")
val map = Map("variantcallers"-> callers.toList)
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
val illegalArgumentException = pipeline.inputBams.isEmpty || (!raw && !bcftools)
if (illegalArgumentException) intercept[IllegalArgumentException] {
pipeline.script()
......@@ -66,7 +71,6 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
@AfterClass def removeTempOutputDir() = {
FileUtils.deleteDirectory(ShivaVariantcallingTest.outputDir)
}
}
object ShivaVariantcallingTest {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment