FlexiprepTest.scala 4.06 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
import com.google.common.io.Files
21
import nl.lumc.sasc.biopet.extensions.tools.{ ValidateFastq, SeqStat }
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import nl.lumc.sasc.biopet.utils.ConfigUtils
23
import nl.lumc.sasc.biopet.utils.config.Config
24
25
26
27
28
29
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
30
/**
Peter van 't Hof's avatar
Peter van 't Hof committed
31
32
 * Test class for [[Flexiprep]]
 *
Peter van 't Hof's avatar
Peter van 't Hof committed
33
34
35
36
37
38
39
40
41
 * 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
42
      qSettings.runName = "test"
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
45
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
46
  @DataProvider(name = "flexiprepOptions")
47
48
49
50
51
  def flexiprepOptions = {
    val paired = Array(true, false)
    val skipTrims = Array(true, false)
    val skipClips = Array(true, false)
    val zipped = Array(true, false)
52
    val abortOnCorruptFastqs = Array(true, false)
53
54
55
56
57

    for (
      pair <- paired;
      skipTrim <- skipTrims;
      skipClip <- skipClips;
58
59
60
      zip <- zipped;
      abortOnCorruptFastq <- abortOnCorruptFastqs
    ) yield Array("", pair, skipTrim, skipClip, zip, abortOnCorruptFastq)
Peter van 't Hof's avatar
Peter van 't Hof committed
61
62
  }

63
  @Test(dataProvider = "flexiprepOptions")
64
65
  def testFlexiprep(f: String, paired: Boolean, skipTrim: Boolean, skipClip: Boolean,
                    zipped: Boolean, abortOnCorruptFastq: Boolean) = {
66
67
    val map = ConfigUtils.mergeMaps(Map("output_dir" -> FlexiprepTest.outputDir,
      "skip_trim" -> skipTrim,
68
69
      "skip_clip" -> skipClip,
      "abort_on_corrupt_fastq" -> abortOnCorruptFastq
70
    ), Map(FlexiprepTest.executables.toSeq: _*))
Peter van 't Hof's avatar
Peter van 't Hof committed
71
72
    val flexiprep: Flexiprep = initPipeline(map)

Sander van der Zeeuw's avatar
Sander van der Zeeuw committed
73
    flexiprep.inputR1 = (if (zipped) FlexiprepTest.r1Zipped else FlexiprepTest.r1)
74
    if (paired) flexiprep.inputR2 = Some((if (zipped) FlexiprepTest.r2Zipped else FlexiprepTest.r2))
75
76
    flexiprep.sampleId = Some("1")
    flexiprep.libId = Some("1")
Peter van 't Hof's avatar
Peter van 't Hof committed
77
78
    flexiprep.script()

Peter van 't Hof's avatar
Peter van 't Hof committed
79
    flexiprep.functions.count(_.isInstanceOf[Fastqc]) shouldBe (if (paired) 4 else 2)
bow's avatar
bow committed
80
    flexiprep.functions.count(_.isInstanceOf[SeqStat]) shouldBe (if (paired) 4 else 2)
81
82
83
84

    flexiprep.functions.count(_.isInstanceOf[ValidateFastq]) shouldBe 2
    flexiprep.functions.count(_.isInstanceOf[CheckValidateFastq]) shouldBe (if (abortOnCorruptFastq) 2 else 0)

Peter van 't Hof's avatar
Peter van 't Hof committed
85
  }
86
87
88
89
90

  // 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
91
}
92

Peter van 't Hof's avatar
Peter van 't Hof committed
93
object FlexiprepTest {
94
  val outputDir = Files.createTempDir()
Peter van 't Hof's avatar
Peter van 't Hof committed
95
96
97
98
99
100
101
102
103
104
  new File(outputDir, "input").mkdirs()

  val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
  Files.touch(r1)
  val r2 = new File(outputDir, "input" + File.separator + "R2.fq")
  Files.touch(r2)
  val r1Zipped = new File(outputDir, "input" + File.separator + "R1.fq.gz")
  Files.touch(r1Zipped)
  val r2Zipped = new File(outputDir, "input" + File.separator + "R2.fq.gz")
  Files.touch(r2Zipped)
Peter van 't Hof's avatar
Peter van 't Hof committed
105

106
  val executables = Map(
Peter van 't Hof's avatar
Peter van 't Hof committed
107
108
109
    "seqstat" -> Map("exe" -> "test"),
    "fastqc" -> Map("exe" -> "test"),
    "seqtk" -> Map("exe" -> "test"),
110
    "sickle" -> Map("exe" -> "test"),
111
112
    "cutadapt" -> Map("exe" -> "test"),
    "md5sum" -> Map("exe" -> "test")
Peter van 't Hof's avatar
Peter van 't Hof committed
113
  )
114
}