FlexiprepTest.scala 3.16 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
package nl.lumc.sasc.biopet.pipelines.flexiprep

import java.io.File

5
6
7
8
9
10
11
import com.google.common.io.Files
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, DataProvider, Test }

Peter van 't Hof's avatar
Peter van 't Hof committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import nl.lumc.sasc.biopet.core.config.Config
import nl.lumc.sasc.biopet.extensions.{ Gzip, Zcat }
import nl.lumc.sasc.biopet.tools.FastqSync
import nl.lumc.sasc.biopet.utils.ConfigUtils

/**
 * Created by pjvan_thof on 2/11/15.
 */
class FlexiprepTest extends TestNGSuite with Matchers {

  def initPipeline(map: Map[String, Any]): Flexiprep = {
    new Flexiprep() {
      override def configName = "flexiprep"
      override def globalConfig = new Config(map)
      qSettings = new QSettings
Peter van 't Hof's avatar
Peter van 't Hof committed
27
      qSettings.runName = "test"
Peter van 't Hof's avatar
Peter van 't Hof committed
28
29
30
    }
  }

31
32
33
34
35
36
37
38
39
40
41
42
43
  @DataProvider(name = "flexiprepOptions", parallel = true)
  def flexiprepOptions = {
    val paired = Array(true, false)
    val skipTrims = Array(true, false)
    val skipClips = Array(true, false)
    val zipped = Array(true, false)

    for (
      pair <- paired;
      skipTrim <- skipTrims;
      skipClip <- skipClips;
      zip <- zipped
    ) yield Array("", pair, skipTrim, skipClip, zip)
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
  }

46
47
48
49
50
51
  @Test(dataProvider = "flexiprepOptions")
  def testFlexiprep(f: String, paired: Boolean, skipTrim: Boolean, skipClip: Boolean, zipped: Boolean) = {
    val map = ConfigUtils.mergeMaps(Map("output_dir" -> FlexiprepTest.outputDir,
      "skip_trim" -> skipTrim,
      "skip_clip" -> skipClip
    ), Map(FlexiprepTest.excutables.toSeq: _*))
Peter van 't Hof's avatar
Peter van 't Hof committed
52
53
    val flexiprep: Flexiprep = initPipeline(map)

54
55
    flexiprep.input_R1 = new File(flexiprep.outputDir, "bla_R1.fq" + (if (zipped) ".gz" else ""))
    if (paired) flexiprep.input_R2 = Some(new File(flexiprep.outputDir, "bla_R2.fq" + (if (zipped) ".gz" else "")))
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57
58
59
    flexiprep.sampleId = "1"
    flexiprep.libId = "1"
    flexiprep.script()

60
61
62
63
64
65
66
67
68
69
70
    flexiprep.functions.count(_.isInstanceOf[Fastqc]) shouldBe (
      if (paired && (skipClip && skipTrim)) 2
      else if (!paired && (skipClip && skipTrim)) 1
      else if (paired && !(skipClip && skipTrim)) 4
      else if (!paired && !(skipClip && skipTrim)) 2)
    flexiprep.functions.count(_.isInstanceOf[Zcat]) shouldBe (if (zipped) (if (paired) 2 else 1) else 0)
    flexiprep.functions.count(_.isInstanceOf[SeqtkSeq]) shouldBe (if (paired) 2 else 1)
    flexiprep.functions.count(_.isInstanceOf[Cutadapt]) shouldBe (if (skipClip) 0 else (if (paired) 2 else 1))
    flexiprep.functions.count(_.isInstanceOf[FastqSync]) shouldBe (if (skipClip) 0 else (if (paired) 1 else 0))
    flexiprep.functions.count(_.isInstanceOf[Sickle]) shouldBe (if (skipTrim) 0 else 1)
    flexiprep.functions.count(_.isInstanceOf[Gzip]) shouldBe (if (paired) 2 else 1)
Peter van 't Hof's avatar
Peter van 't Hof committed
71
  }
72
73
74
75
76

  // remove temporary run directory all tests in the class have been run
  @AfterClass def removeTempOutputDir() = {
    FileUtils.deleteDirectory(FlexiprepTest.outputDir)
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
77
}
78

Peter van 't Hof's avatar
Peter van 't Hof committed
79
object FlexiprepTest {
80
  val outputDir = Files.createTempDir()
Peter van 't Hof's avatar
Peter van 't Hof committed
81
82
83
84
85
86
87
88

  val excutables = Map(
    "seqstat" -> Map("exe" -> "test"),
    "fastqc" -> Map("exe" -> "test"),
    "seqtk" -> Map("exe" -> "test"),
    "sickle" -> Map("exe" -> "test")
  )
}