VcfFilterTest.scala 2.98 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof 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.
 */
Sander Bollen's avatar
Sander Bollen committed
16
17
package nl.lumc.sasc.biopet.tools

18
import java.io.File
Sander Bollen's avatar
Sander Bollen committed
19
20
import java.nio.file.Paths

21
import htsjdk.variant.vcf.VCFFileReader
Sander Bollen's avatar
Sander Bollen committed
22
23
24
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
Peter van 't Hof's avatar
Peter van 't Hof committed
25
import org.testng.annotations.Test
Sander Bollen's avatar
Sander Bollen committed
26
27
28
29

import scala.util.Random

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
30
31
 * Test class for [[VcfFilter]]
 *
Sander Bollen's avatar
Sander Bollen committed
32
33
34
35
36
37
38
39
40
41
 * Created by ahbbollen on 9-4-15.
 */
class VcfFilterTest extends TestNGSuite with MockitoSugar with Matchers {

  import VcfFilter._
  private def resourcePath(p: String): String = {
    Paths.get(getClass.getResource(p).toURI).toString
  }

  val vepped_path = resourcePath("/VEP_oneline.vcf")
42
  val vepped = new File(vepped_path)
Sander Bollen's avatar
Sander Bollen committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  val rand = new Random()

  @Test def testOutputTypeVcf() = {
    val tmp_path = "/tmp/VcfFilter_" + rand.nextString(10) + ".vcf"
    val arguments: Array[String] = Array("-I", vepped_path, "-o", tmp_path)
    main(arguments)
  }

  @Test def testOutputTypeBcf() = {
    val tmp_path = "/tmp/VcfFilter_" + rand.nextString(10) + ".bcf"
    val arguments: Array[String] = Array("-I", vepped_path, "-o", tmp_path)
    main(arguments)
  }

  @Test def testOutputTypeVcfGz() = {
    val tmp_path = "/tmp/VcfFilter_" + rand.nextString(10) + ".vcf.gz"
    val arguments: Array[String] = Array("-I", vepped_path, "-o", tmp_path)
    main(arguments)
  }

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  @Test def testHasGenotype() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    hasGenotype(record, List("Child_7006504:HET")) shouldBe true
    hasGenotype(record, List("Child_7006504:HOM_VAR")) shouldBe false
    hasGenotype(record, List("Child_7006504:HOM_REF")) shouldBe false
    hasGenotype(record, List("Child_7006504:NO_CALL")) shouldBe false
    hasGenotype(record, List("Child_7006504:MIXED")) shouldBe false

    hasGenotype(record, List("Mother_7006508:HET")) shouldBe false
    hasGenotype(record, List("Mother_7006508:HOM_VAR")) shouldBe false
    hasGenotype(record, List("Mother_7006508:HOM_REF")) shouldBe true
    hasGenotype(record, List("Mother_7006508:NO_CALL")) shouldBe false
    hasGenotype(record, List("Mother_7006508:MIXED")) shouldBe false

    hasGenotype(record, List("Mother_7006508:HOM_REF", "Child_7006504:HET")) shouldBe true
    hasGenotype(record, List("Mother_7006508:HET", "Child_7006504:HOM_HET")) shouldBe false
  }

Sander Bollen's avatar
Sander Bollen committed
83
}