SummaryToTsvTest.scala 2.99 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
2
3
4
5
6
7
8
9
10
/**
 * 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
 *
11
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
Peter van 't Hof's avatar
Peter van 't Hof committed
12
13
14
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
Sander Bollen's avatar
Sander Bollen committed
15
16
17
18
19
package nl.lumc.sasc.biopet.tools

import java.io.File
import java.nio.file.Paths

20
import nl.lumc.sasc.biopet.tools.SamplesTsvToConfig._
Sander Bollen's avatar
Sander Bollen committed
21
22
23
24
25
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test

26
import nl.lumc.sasc.biopet.utils.summary.Summary
Sander Bollen's avatar
Sander Bollen committed
27
28
29
30
31
32
33
34
35
36
37
38
39

/**
 * Created by ahbbollen on 31-8-15.
 */
class SummaryToTsvTest extends TestNGSuite with MockitoSugar with Matchers {
  import SummaryToTsv._
  private def resourcePath(p: String): String = {
    Paths.get(getClass.getResource(p).toURI).toString
  }

  @Test
  def testMain = {
    val tsv = resourcePath("/test.summary.json")
40
    val output = File.createTempFile("main", "tsv")
41
    output.deleteOnExit()
Sander Bollen's avatar
Sander Bollen committed
42
43

    noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
44
      "-m", "root", "-o", output.toString))
Sander Bollen's avatar
Sander Bollen committed
45
    noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
46
      "-m", "sample", "-o", output.toString))
Sander Bollen's avatar
Sander Bollen committed
47
    noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
48
      "-m", "lib", "-o", output.toString))
Sander Bollen's avatar
Sander Bollen committed
49
50
51
  }

  @Test
Sander Bollen's avatar
Sander Bollen committed
52
  def testHeader = {
Sander Bollen's avatar
Sander Bollen committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    val tsv = resourcePath("/test.summary.json")
    val path = List("something=flexiprep:settings:skip_trim")

    val paths = path.map(x => {
      val split = x.split("=", 2)
      split(0) -> split(1).split(":")
    }).toMap

    createHeader(paths) should equal("\tsomething")
  }

  @Test
  def testLine = {
    val tsv = resourcePath("/test.summary.json")
    val path = List("something=flexiprep:settings:skip_trim")

    val paths = path.map(x => {
      val split = x.split("=", 2)
      split(0) -> split(1).split(":")
    }).toMap

    val summary = new Summary(new File(tsv))
    val values = fetchValues(summary, paths)

    val line = values.head._2.keys.map(x => createLine(paths, values, x)).head
    line should equal("value\t")
Sander van der Zeeuw's avatar
Sander van der Zeeuw committed
79
80
81
    val sampleValues = fetchValues(summary, paths, true, false)
    val sampleLine = sampleValues.head._2.keys.map(x => createLine(paths, sampleValues, x)).head
    sampleLine should equal("016\t")
Sander Bollen's avatar
Sander Bollen committed
82

Sander van der Zeeuw's avatar
Sander van der Zeeuw committed
83
84
85
    val libValues = fetchValues(summary, paths, false, true)
    val libLine = libValues.head._2.keys.map(x => createLine(paths, libValues, x)).head
    libLine should equal("016-L001\tfalse")
Sander Bollen's avatar
Sander Bollen committed
86
87
88
  }

}