WriteDependenciesTest.scala 2.85 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.
 */
15
16
17
18
package nl.lumc.sasc.biopet.core

import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
19
import com.google.common.io.Files
Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.utils.ConfigUtils
21
22
23
24
25
26
import org.broadinstitute.gatk.queue.function.QFunction
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
27
28
 * Created by pjvanthof on 09/05/16.
 */
29
30
31
32
33
34
35
36
37
38
39
40
41
class WriteDependenciesTest extends TestNGSuite with Matchers {

  import WriteDependenciesTest._

  case class Qfunc(in: Seq[File], out: Seq[File]) extends QFunction {
    override def inputs = in
    override def outputs = out
    override def doneOutputs = out.map(x => new File(x.getParentFile, s".${x.getName}.done"))
    override def failOutputs = out.map(x => new File(x.getParentFile, s".${x.getName}.fail"))
    jobOutputFile = new File(out.head + ".out")
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
42
  def testDeps(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
43
44
    val tempDir = Files.createTempDir()
    tempDir.deleteOnExit()
Peter van 't Hof's avatar
Peter van 't Hof committed
45
    val outputFile = new File(tempDir, s"deps.json")
46
    outputFile.deleteOnExit()
Peter van 't Hof's avatar
Peter van 't Hof committed
47
48
    val func1 = Qfunc(file1 :: Nil, file2 :: Nil)
    val func2 = Qfunc(file2 :: Nil, file3 :: Nil)
Peter van 't Hof's avatar
Peter van 't Hof committed
49
    WriteDependencies.writeDependencies(func1 :: func2 :: Nil, tempDir)
Peter van 't Hof's avatar
Peter van 't Hof committed
50
51
52
53
54
55
56
    val deps = ConfigUtils.fileToConfigMap(outputFile)
    deps("jobs") shouldBe a[Map[_, _]]
    val jobs = deps("jobs").asInstanceOf[Map[String, Map[String, Any]]]
    jobs.count(_._1.contains("Qfunc")) shouldBe 2

    deps("files") shouldBe a[List[_]]
    val files = deps("files").asInstanceOf[List[Map[String, Any]]]
Peter van 't Hof's avatar
Peter van 't Hof committed
57
    val paths = files.flatMap(x => x.get("path"))
Peter van 't Hof's avatar
Peter van 't Hof committed
58
59
60
61
62
63
64
    assert(paths.contains(file1.toString))
    assert(paths.contains(file2.toString))
    assert(paths.contains(file3.toString))

    files.find(_.get("path") == Some(file1.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(true)
    files.find(_.get("path") == Some(file2.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(false)
    files.find(_.get("path") == Some(file3.toString)).flatMap(_.get("pipeline_input")) shouldBe Some(false)
65
66
67
68
  }
}

object WriteDependenciesTest {
Peter van 't Hof's avatar
Peter van 't Hof committed
69
  val tempDir = Files.createTempDir()
70
71
72
73
74
  tempDir.deleteOnExit()
  val file1 = new File(tempDir, "file1.txt")
  val file2 = new File(tempDir, "file2.txt")
  val file3 = new File(tempDir, "file3.txt")
}