TinyCapTest.scala 4.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * 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 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
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
/**
 * Created by wyleung on 11-2-16.
 */

/**
 * 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.
 */
package nl.lumc.sasc.biopet.pipelines.tinycap

import java.io.File

import com.google.common.io.Files
import nl.lumc.sasc.biopet.extensions.HtseqCount
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.config.Config
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 }

class TinyCapTest extends TestNGSuite with Matchers {

Peter van 't Hof's avatar
Peter van 't Hof committed
50
51
  private var dirs: List[File] = Nil

Peter van 't Hof's avatar
Peter van 't Hof committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  def initPipeline(map: Map[String, Any]): TinyCap = {
    new TinyCap() {
      override def configNamespace = "tinycap"

      override def globalConfig = new Config(map)

      qSettings = new QSettings
      qSettings.runName = "test"
    }
  }

  @DataProvider(name = "tinyCapOptions")
  def tinyCapOptions = {
    val bool = Array(true)

    for (
      s1 <- bool
    ) yield Array("", s1)
  }

  @Test(dataProvider = "tinyCapOptions")
  def testTinyCap(dummy: String, sample1: Boolean): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
    val outputDir = TinyCapTest.outputDir
    dirs :+= outputDir
Peter van 't Hof's avatar
Peter van 't Hof committed
76
    val map = {
Peter van 't Hof's avatar
Peter van 't Hof committed
77
      var m: Map[String, Any] = TinyCapTest.config(outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
      if (sample1) m = ConfigUtils.mergeMaps(TinyCapTest.sample1, m)
      m
    }

    if (!sample1) { // When no samples
      intercept[IllegalArgumentException] {
        initPipeline(map).script()
      }
    }

    val pipeline = initPipeline(map)
    pipeline.script()
    // expect 2 instances of HtSeqCount, one for mirna.gff other for transcripts.gtf
    pipeline.functions.count(_.isInstanceOf[HtseqCount]) shouldBe 2

  }

  // remove temporary run directory all tests in the class have been run
  @AfterClass def removeTempOutputDir() = {
Peter van 't Hof's avatar
Peter van 't Hof committed
97
    dirs.foreach(FileUtils.deleteDirectory)
Peter van 't Hof's avatar
Peter van 't Hof committed
98
99
100
101
  }
}

object TinyCapTest {
Peter van 't Hof's avatar
Peter van 't Hof committed
102
103
  def outputDir = Files.createTempDir()
  val inputDir = Files.createTempDir()
Peter van 't Hof's avatar
Peter van 't Hof committed
104

Peter van 't Hof's avatar
Peter van 't Hof committed
105
  val r1 = new File(inputDir, "R1.fq.gz")
Peter van 't Hof's avatar
Peter van 't Hof committed
106
  Files.touch(r1)
Peter van 't Hof's avatar
Peter van 't Hof committed
107
  val bam = new File(inputDir, "bamfile.bam")
Peter van 't Hof's avatar
Peter van 't Hof committed
108
109
  Files.touch(bam)

Peter van 't Hof's avatar
Peter van 't Hof committed
110
  val referenceFasta = new File(inputDir, "ref.fa")
Peter van 't Hof's avatar
Peter van 't Hof committed
111
  Files.touch(referenceFasta)
Peter van 't Hof's avatar
Peter van 't Hof committed
112
  val referenceFastaDict = new File(inputDir, "ref.dict")
Peter van 't Hof's avatar
Peter van 't Hof committed
113
  Files.touch(referenceFastaDict)
Peter van 't Hof's avatar
Peter van 't Hof committed
114
  val bowtieIndex = new File(inputDir, "ref.1.ebwt")
Peter van 't Hof's avatar
Peter van 't Hof committed
115
116
  Files.touch(bowtieIndex)

Peter van 't Hof's avatar
Peter van 't Hof committed
117
118
119
  val annotationGFF = new File(inputDir, "annot.gff")
  val annotationGTF = new File(inputDir, "annot.gtf")
  val annotationRefflat = new File(inputDir, "annot.refflat")
Peter van 't Hof's avatar
Peter van 't Hof committed
120
121
122
123
  Files.touch(annotationGFF)
  Files.touch(annotationGTF)
  Files.touch(annotationRefflat)

Peter van 't Hof's avatar
Peter van 't Hof committed
124
  def config(outputDir: File) = Map(
125
    "skip_write_dependencies" -> true,
Peter van 't Hof's avatar
Peter van 't Hof committed
126
127
128
129
130
131
132
133
134
    "output_dir" -> outputDir,
    "reference_fasta" -> (referenceFasta.getAbsolutePath),
    "bowtie_index" -> (bowtieIndex.getAbsolutePath),

    "annotation_gff" -> annotationGFF,
    "annotation_gtf" -> annotationGTF,
    "annotation_refflat" -> annotationRefflat,

    "md5sum" -> Map("exe" -> "test"),
Peter van 't Hof's avatar
Peter van 't Hof committed
135
    "rscript" -> Map("exe" -> "test"),
Peter van 't Hof's avatar
Peter van 't Hof committed
136
137
138
139
140
141
    "fastqc" -> Map("exe" -> "test"),
    "seqtk" -> Map("exe" -> "test"),
    "sickle" -> Map("exe" -> "test"),
    "cutadapt" -> Map("exe" -> "test"),
    "bowtie" -> Map("exe" -> "test"),
    "htseqcount" -> Map("exe" -> "test"),
142
    "igvtools" -> Map("exe" -> "test", "igvtools_jar" -> "test"),
Peter van 't Hof's avatar
Peter van 't Hof committed
143
144
145
146
147
148
149
150
151
152
153
154
    "wigtobigwig" -> Map("exe" -> "test")
  )

  val sample1 = Map(
    "samples" -> Map("sample1" -> Map("libraries" -> Map(
      "lib1" -> Map(
        "R1" -> r1.getAbsolutePath
      )
    )
    )))

}