DownloadGenomesTest.scala 7.07 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
package nl.lumc.sasc.biopet.pipelines.generateindexes

Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
19
20
21
import com.google.common.io.Files
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.utils.config.Config
Peter van 't Hof's avatar
Peter van 't Hof committed
22
import org.apache.commons.io.FileUtils
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
25
import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
Peter van 't Hof's avatar
Peter van 't Hof committed
26
import org.testng.annotations.{AfterClass, Test}
Peter van 't Hof's avatar
Peter van 't Hof committed
27
28
29
30

/**
 * Created by pjvan_thof on 13-5-16.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
31
class DownloadGenomesTest extends TestNGSuite with Matchers {
Peter van 't Hof's avatar
Peter van 't Hof committed
32
  def initPipeline(map: Map[String, Any], outputDir: File): DownloadGenomes = {
Peter van 't Hof's avatar
Peter van 't Hof committed
33
    new DownloadGenomes() {
Peter van 't Hof's avatar
Peter van 't Hof committed
34
      override def configNamespace = "generateindexes"
Peter van 't Hof's avatar
Peter van 't Hof committed
35
      override def globalConfig = new Config(ConfigUtils.mergeMaps(map, DownloadGenomesTest.config(outputDir)))
Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
38
39
40
      qSettings = new QSettings
      qSettings.runName = "test"
    }
  }

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

Peter van 't Hof's avatar
Peter van 't Hof committed
43
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
44
  def testNoFastaUri(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
45
46
47
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map(), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
48
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("" -> "")))
49
    an[IllegalArgumentException] should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
50
51
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
52
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
53
  def testNcbiAssembly(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
56
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map(), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
57
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("ncbi_assembly_report" -> "id")))
Peter van 't Hof's avatar
Peter van 't Hof committed
58
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
59
60
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
61
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
62
  def testSingleFasta(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
63
64
65
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map(), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
66
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri")))
Peter van 't Hof's avatar
Peter van 't Hof committed
67
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
70
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
71
  def testMultiFasta(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
74
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map(), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
75
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> List("uri", "uri2", "uri3.gz"))))
Peter van 't Hof's avatar
Peter van 't Hof committed
76
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
77
78
79
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
80
  def testSingleDbsnp(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
81
82
83
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
84
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
85
      "dbsnp" -> Map("version" -> Map("vcf_uri" -> "uri.vcf.gz")))))
Peter van 't Hof's avatar
Peter van 't Hof committed
86
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
87
88
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
89
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
90
  def testContigMapDbsnp(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
91
92
93
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
94
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
95
      "dbsnp" -> Map("version" -> Map("vcf_uri" -> "uri.vcf.gz", "contig_map" -> Map("1" -> "chr1"))))))
Peter van 't Hof's avatar
Peter van 't Hof committed
96
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
97
98
99
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
100
  def testUnzippedContigMapDbsnp(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
101
102
103
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
104
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
105
      "dbsnp" -> Map("version" -> Map("vcf_uri" -> "uri.vcf", "contig_map" -> Map("1" -> "chr1"))))))
Peter van 't Hof's avatar
Peter van 't Hof committed
106
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
107
108
109
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
110
  def testSingleUnzippedDbsnp(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
111
112
113
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
114
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
115
      "dbsnp" -> Map("version" -> Map(("vcf_uri" -> "uri.vcf"))))))
Peter van 't Hof's avatar
Peter van 't Hof committed
116
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
117
118
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
119
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
120
  def testMultiDbsnp(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
121
122
123
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
124
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
125
      "dbsnp" -> Map("version" -> Map("vcf_uri" -> List("uri.vcf.gz", "uri2.vcf.gz"))))))
Peter van 't Hof's avatar
Peter van 't Hof committed
126
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
127
128
129
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
130
  def testVep(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
131
132
133
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
134
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
135
      "vep" -> Map("version" -> Map("cache_uri" -> "something/human_vep_80_hg19.tar.gz")))))
Peter van 't Hof's avatar
Peter van 't Hof committed
136
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
137
138
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
139
  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
140
  def testGtfZipped(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
141
142
143
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
144
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
145
      "gene_annotation" -> Map("version" -> Map("gtf_uri" -> "bla.gf.gz")))))
Peter van 't Hof's avatar
Peter van 't Hof committed
146
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
147
148
149
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
150
  def testGtf(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
151
152
153
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
154
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
155
      "gene_annotation" -> Map("version" -> Map("gtf_uri" -> "bla.gf")))))
Peter van 't Hof's avatar
Peter van 't Hof committed
156
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
157
158
159
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
160
  def testGff(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
161
162
163
    val outputDir = Files.createTempDir()
    dirs :+= outputDir
    val pipeline = initPipeline(Map("download_annotations" -> true), outputDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
164
    pipeline.referenceConfig = Map("s1" -> Map("g1" -> Map("fasta_uri" -> "uri",
Peter van 't Hof's avatar
Peter van 't Hof committed
165
      "gene_annotation" -> Map("version" -> Map("gff_uri" -> "bla.gf")))))
Peter van 't Hof's avatar
Peter van 't Hof committed
166
    noException should be thrownBy pipeline.script()
Peter van 't Hof's avatar
Peter van 't Hof committed
167
168
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
169
170
171
172
  // remove temporary run directory all tests in the class have been run
  @AfterClass def removeTempOutputDir() = {
    dirs.foreach(FileUtils.deleteDirectory)
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
173
174
}

Peter van 't Hof's avatar
Peter van 't Hof committed
175
object DownloadGenomesTest {
Peter van 't Hof's avatar
Peter van 't Hof committed
176
  def config(outputDir: File) = Map(
177
178
    "skip_write_dependencies" -> true,
    "output_dir" -> outputDir,
Peter van 't Hof's avatar
Peter van 't Hof committed
179
180
    "bwa" -> Map("exe" -> "test"),
    "star" -> Map("exe" -> "test"),
Peter van 't Hof's avatar
Peter van 't Hof committed
181
    "hisat2build" -> Map("exe" -> "test"),
Peter van 't Hof's avatar
Peter van 't Hof committed
182
183
184
185
186
187
    "bowtiebuild" -> Map("exe" -> "test"),
    "bowtie2build" -> Map("exe" -> "test"),
    "gmapbuild" -> Map("exe" -> "test"),
    "samtools" -> Map("exe" -> "test"),
    "md5sum" -> Map("exe" -> "test"),
    "gatk_jar" -> "test",
Peter van 't Hof's avatar
Peter van 't Hof committed
188
189
    "tabix" -> Map("exe" -> "test"),
    "gffread" -> Map("exe" -> "test")
Peter van 't Hof's avatar
Peter van 't Hof committed
190
191
  )
}