FlexiprepTest.scala 4.08 KB
Newer Older
bow's avatar
bow committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * 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 that are
 * not part of GATK Queue 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
16
17
18
19
package nl.lumc.sasc.biopet.pipelines.flexiprep

import java.io.File

20
21
22
23
24
25
26
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
27
import nl.lumc.sasc.biopet.core.config.Config
Peter van 't Hof's avatar
Peter van 't Hof committed
28
import nl.lumc.sasc.biopet.extensions.{ Sickle, Gzip, Zcat }
29
import nl.lumc.sasc.biopet.tools.Seqstat
Peter van 't Hof's avatar
Peter van 't Hof committed
30
31
32
33
34
35
36
37
38
39
40
41
42
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
43
      qSettings.runName = "test"
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
47
  @DataProvider(name = "flexiprepOptions")
48
49
50
51
52
53
54
55
56
57
58
59
  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
60
61
  }

62
63
64
65
66
  @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
67
    ), Map(FlexiprepTest.executables.toSeq: _*))
Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
    val flexiprep: Flexiprep = initPipeline(map)

70
71
    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 "")))
72
73
    flexiprep.sampleId = Some("1")
    flexiprep.libId = Some("1")
Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
    flexiprep.script()

76
77
78
79
80
    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)
81
    flexiprep.functions.count(_.isInstanceOf[Seqstat]) shouldBe (if (paired) 4 else 2)
82
83
84
85
86
87
    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
88
  }
89
90
91
92
93

  // 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
94
}
95

Peter van 't Hof's avatar
Peter van 't Hof committed
96
object FlexiprepTest {
97
  val outputDir = Files.createTempDir()
Peter van 't Hof's avatar
Peter van 't Hof committed
98

99
  val executables = Map(
Peter van 't Hof's avatar
Peter van 't Hof committed
100
101
102
    "seqstat" -> Map("exe" -> "test"),
    "fastqc" -> Map("exe" -> "test"),
    "seqtk" -> Map("exe" -> "test"),
103
    "sickle" -> Map("exe" -> "test"),
104
105
    "cutadapt" -> Map("exe" -> "test"),
    "md5sum" -> Map("exe" -> "test")
Peter van 't Hof's avatar
Peter van 't Hof committed
106
  )
107
}