GwasTestTest.scala 2.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
15
16
package nl.lumc.sasc.biopet.pipelines.gwastest

Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
19
20
import java.io.File
import java.nio.file.Paths

import com.google.common.io.Files
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import nl.lumc.sasc.biopet.utils.Logging
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.utils.config.Config
Peter van 't Hof's avatar
Peter van 't Hof committed
23
import org.apache.commons.io.FileUtils
Peter van 't Hof's avatar
Peter van 't Hof committed
24
25
26
import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
Peter van 't Hof's avatar
Peter van 't Hof committed
27
import org.testng.annotations.{ AfterClass, Test }
Peter van 't Hof's avatar
Peter van 't Hof committed
28
29

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
30
31
 * Created by pjvan_thof on 4/11/16.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
32
33
34
class GwasTestTest extends TestNGSuite with Matchers {
  def initPipeline(map: Map[String, Any]): GwasTest = {
    new GwasTest {
Peter van 't Hof's avatar
Peter van 't Hof committed
35
      override def configNamespace = "gwastest"
Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
38
39
40
41
      override def globalConfig = new Config(map)
      qSettings = new QSettings
      qSettings.runName = "test"
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
42
43
  private var dirs: List[File] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
  @Test
  def testFromVcf: Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
46
47
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
Peter van 't Hof's avatar
Peter van 't Hof committed
48
    Logging.errors.clear()
Peter van 't Hof's avatar
Peter van 't Hof committed
49
    val pipeline = initPipeline(GwasTestTest.config(outputDir) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
50
51
52
53
54
      Map("input_vcf" -> GwasTestTest.vcfFile.toString
      )
    )
    pipeline.script()
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
55
56
57

  @Test
  def testEmpty: Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
58
59
60
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(GwasTestTest.config(outputDir))
Peter van 't Hof's avatar
Peter van 't Hof committed
61
62
63
64
    intercept[IllegalArgumentException] {
      pipeline.script()
    }
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
65
66
67
68
69

  // remove temporary run directory all tests in the class have been run
  @AfterClass def removeTempOutputDir() = {
    dirs.foreach(FileUtils.deleteDirectory)
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
70
}
Peter van 't Hof's avatar
Peter van 't Hof committed
71
72
73
74
75
76
77

object GwasTestTest {
  val vcfFile = File.createTempFile("gwas.", ".vcf")
  Files.touch(vcfFile)
  vcfFile.deleteOnExit()

  val phenotypeFile = File.createTempFile("gwas.", ".txt")
Peter van 't Hof's avatar
Peter van 't Hof committed
78
  phenotypeFile.deleteOnExit()
Peter van 't Hof's avatar
Peter van 't Hof committed
79
80
81
82
83
84
85

  val reference = new File(resourcePath("/fake_chrQ.fa"))

  private def resourcePath(p: String): String = {
    Paths.get(getClass.getResource(p).toURI).toString
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
86
  def config(outputDir: File) = Map(
87
    "skip_write_dependencies" -> true,
Peter van 't Hof's avatar
Peter van 't Hof committed
88
89
    "reference_fasta" -> reference.toString,
    "phenotype_file" -> phenotypeFile.toString,
Peter van 't Hof's avatar
Peter van 't Hof committed
90
91
92
93
94
95
96
    "output_dir" -> outputDir,
    "snptest" -> Map("exe" -> "test"),
    "md5sum" -> Map("exe" -> "test"),
    "gatk_jar" -> "test"
  )

}