GwasTestTest.scala 2.38 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
package nl.lumc.sasc.biopet.pipelines.gwastest

Peter van 't Hof's avatar
Peter van 't Hof committed
3
4
5
6
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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 4/11/16.
  */
class GwasTestTest extends TestNGSuite with Matchers {
  def initPipeline(map: Map[String, Any]): GwasTest = {
    new GwasTest {
      override def configName = "gwastest"
      override def globalConfig = new Config(map)
      qSettings = new QSettings
      qSettings.runName = "test"
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
26
27
28
29
30
31
32
33
  @Test
  def testFromVcf: Unit = {
    val pipeline = initPipeline(GwasTestTest.config ++
      Map("input_vcf" -> GwasTestTest.vcfFile.toString
      )
    )
    pipeline.script()
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  @Test
  def testFromGens: Unit = {
    val pipeline = initPipeline(GwasTestTest.config ++
      Map("input_gens" -> List(Map("genotypes" -> GwasTestTest.vcfFile, "contig" -> "chrQ"))
      )
    )
    pipeline.script()
  }

  @Test
  def testWrongContig: Unit = {
    val pipeline = initPipeline(GwasTestTest.config ++
      Map("input_gens" -> List(Map("genotypes" -> GwasTestTest.vcfFile, "contig" -> "chrBla"))
      )
    )
    intercept[IllegalStateException] {
      pipeline.script()
    }
  }

  @Test
  def testFromSpecs: Unit = {
    val pipeline = initPipeline(GwasTestTest.config ++
      Map("imute_specs_file" -> GwasTestTest.resourcePath("/specs/files.specs"))
    )
    pipeline.script()
  }


Peter van 't Hof's avatar
Peter van 't Hof committed
64
65
  @Test
  def testEmpty: Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
66
    val pipeline = initPipeline(GwasTestTest.config)
Peter van 't Hof's avatar
Peter van 't Hof committed
67
68
69
70
71
    intercept[IllegalArgumentException] {
      pipeline.script()
    }
  }
}
Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

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

  val phenotypeFile = File.createTempFile("gwas.", ".txt")

  val outputDir = Files.createTempDir()
  outputDir.deleteOnExit()

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

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

  val config = Map(
    "reference_fasta" -> GwasTestTest.reference.toString,
    "phenotype_file" -> GwasTestTest.phenotypeFile.toString,
    "output_dir" -> outputDir,
    "snptest" -> Map("exe" -> "test"),
    "md5sum" -> Map("exe" -> "test"),
    "gatk_jar" -> "test"
  )

}