CarpTest.scala 3.41 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
64
65
66
67
68
69
70
71
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package nl.lumc.sasc.biopet.pipelines.carp

import java.io.File

import nl.lumc.sasc.biopet.core.config.{ConfigValueIndex, Config}
import nl.lumc.sasc.biopet.utils.ConfigUtils
import org.broadinstitute.gatk.queue.QSettings
import org.testng.annotations.{DataProvider, Test}
import org.testng.annotations.{Test, DataProvider}
import org.scalatest.Assertions._

/**
 * Created by pjvan_thof on 2/13/15.
 */
class CarpTest {
  def initPipeline(map: Map[String, Any]): Carp = {
    new Carp() {
      override def configName = "carp"
      override def globalConfig = new Config(map)
      qSettings = new QSettings
      qSettings.runName = "test"
    }
  }

  @DataProvider(name = "carpOptions", parallel = true)
  def carpOptions = {
    val bool = Array(true, false)

    for (s1 <- bool; s2 <- bool; s3 <- bool; t <- bool; c <- bool) yield
      Array("", s1, s2, s3, t, c)
  }

  @Test(dataProvider = "carpOptions")
  def testCarp(f:String, sample1:Boolean, sample2:Boolean, sample3:Boolean, threatment:Boolean, control:Boolean): Unit = {
    val map = {
      var m = ConfigUtils.mergeMaps(Map("output_dir" -> CarpTest.outputDir
      ), CarpTest.excutables)

      if (sample1) m = ConfigUtils.mergeMaps(CarpTest.sample1, m.toMap)
      if (sample2) m = ConfigUtils.mergeMaps(CarpTest.sample2, m.toMap)
      if (sample3) m = ConfigUtils.mergeMaps(CarpTest.sample3, m.toMap)
      if (threatment) m = ConfigUtils.mergeMaps(CarpTest.threatment1, m.toMap)
      if (control) m = ConfigUtils.mergeMaps(CarpTest.control1, m.toMap)
      m
    }

    if (!sample1 && !sample2 && !sample3 && !threatment && !control) { // When no samples
      intercept[IllegalArgumentException] {
        initPipeline(map).script()
      }
    } else if (threatment && !control) { // If control of a samples does not exist in samples
      intercept[IllegalStateException] {
        initPipeline(map).script()
      }
    } else { // When samples are correct
      val carp = initPipeline(map)
      carp.script()


    }
  }
}

object CarpTest {
  val outputDir = System.getProperty("java.io.tmpdir") + File.separator + "flexiprep"

  val excutables = Map(
    "reference" -> "test",
    "seqstat" -> Map("exe" -> "test"),
    "fastqc" -> Map("exe" -> "test"),
    "seqtk" -> Map("exe" -> "test"),
    "sickle" -> Map("exe" -> "test"),
    "bwa" -> Map("exe" -> "test"),
    "samtools" -> Map("exe" -> "test"),
    "macs2" -> Map("exe" -> "test")
  )

  val sample1 = Map(
    "samples" -> Map( "sample1" -> Map( "libraries" -> Map(
      "lib1" -> Map(
        "R1" -> "1_1_R1.fq",
        "R2" -> "1_1_R2.fq"
      )
    )
    )))

  val sample2 = Map(
    "samples" -> Map( "sample2" -> Map( "libraries" -> Map(
      "lib1" -> Map(
        "R1" -> "2_1_R1.fq",
        "R2" -> "2_1_R2.fq"
      )
    )
  )))

  val sample3 = Map(
    "samples" -> Map( "sample3" -> Map( "libraries" -> Map(
      "lib1" -> Map(
        "R1" -> "3_1_R1.fq",
        "R2" -> "3_1_R2.fq"
      ),
      "lib2" -> Map(
        "R1" -> "3_2_R1.fq",
        "R2" -> "3_2_R2.fq"
      )
    )
    )))

  val threatment1 = Map(
    "samples" -> Map( "threatment" -> Map( "control" -> "control1","libraries" -> Map(
      "lib1" -> Map(
        "R1" -> "threatment_1_R1.fq",
        "R2" -> "threatment_1_R2.fq"
      )
    )
    )))

  val control1 = Map(
    "samples" -> Map( "control1" -> Map( "libraries" -> Map(
      "lib1" -> Map(
        "R1" -> "control_1_R1.fq",
        "R2" -> "control_1_R2.fq"
      )
    )
    )))

}