VcfFilterTest.scala 5.36 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

Peter van 't Hof's avatar
Peter van 't Hof committed
21
import htsjdk.variant.variantcontext.GenotypeType
22
import htsjdk.variant.vcf.VCFFileReader
Sander Bollen's avatar
Sander Bollen committed
23
24
25
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
26
import org.testng.annotations.Test
Sander Bollen's avatar
Sander Bollen committed
27
28
29
30

import scala.util.Random

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
31
32
 * Test class for [[VcfFilter]]
 *
Sander Bollen's avatar
Sander Bollen committed
33
34
35
36
37
38
39
40
41
42
 * 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")
43
  val vepped = new File(vepped_path)
Sander Bollen's avatar
Sander Bollen committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  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)
  }

64
65
66
67
  @Test def testHasGenotype() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

Peter van 't Hof's avatar
Peter van 't Hof committed
68
69
70
71
72
    hasGenotype(record, List(("Child_7006504", GenotypeType.HET))) shouldBe true
    hasGenotype(record, List(("Child_7006504", GenotypeType.HOM_VAR))) shouldBe false
    hasGenotype(record, List(("Child_7006504", GenotypeType.HOM_REF))) shouldBe false
    hasGenotype(record, List(("Child_7006504", GenotypeType.NO_CALL))) shouldBe false
    hasGenotype(record, List(("Child_7006504", GenotypeType.MIXED))) shouldBe false
73

Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
78
    hasGenotype(record, List(("Mother_7006508", GenotypeType.HET))) shouldBe false
    hasGenotype(record, List(("Mother_7006508", GenotypeType.HOM_VAR))) shouldBe false
    hasGenotype(record, List(("Mother_7006508", GenotypeType.HOM_REF))) shouldBe true
    hasGenotype(record, List(("Mother_7006508", GenotypeType.NO_CALL))) shouldBe false
    hasGenotype(record, List(("Mother_7006508", GenotypeType.MIXED))) shouldBe false
79

Peter van 't Hof's avatar
Peter van 't Hof committed
80
81
    hasGenotype(record, List(("Mother_7006508", GenotypeType.HOM_REF), ("Child_7006504", GenotypeType.HET))) shouldBe true
    hasGenotype(record, List(("Mother_7006508", GenotypeType.HET), ("Child_7006504", GenotypeType.HOM_REF))) shouldBe false
82
83
  }

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  @Test def testMinQualScore() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    minQualscore(record, 2000) shouldBe false
    minQualscore(record, 1000) shouldBe true

  }

  @Test def testHasNonRefCalls() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    hasNonRefCalls(record) shouldBe true
  }

  @Test def testHasCalls() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    hasCalls(record) shouldBe true
  }

  @Test def testHasMinDP() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    hasMinTotalDepth(record, 100) shouldBe true
    hasMinTotalDepth(record, 200) shouldBe false
  }

  @Test def testHasMinSampleDP() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    hasMinSampleDepth(record, 30, 1) shouldBe true
    hasMinSampleDepth(record, 30, 2) shouldBe true
    hasMinSampleDepth(record, 30, 3) shouldBe true
    hasMinSampleDepth(record, 40, 1) shouldBe true
    hasMinSampleDepth(record, 40, 2) shouldBe true
    hasMinSampleDepth(record, 40, 3) shouldBe false
    hasMinSampleDepth(record, 50, 1) shouldBe false
    hasMinSampleDepth(record, 50, 2) shouldBe false
    hasMinSampleDepth(record, 50, 3) shouldBe false
  }

  @Test def testHasMinSampleAD() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    minAlternateDepth(record, 0, 3) shouldBe true
    minAlternateDepth(record, 10, 2) shouldBe true
    minAlternateDepth(record, 10, 3) shouldBe false
    minAlternateDepth(record, 20, 1) shouldBe true
    minAlternateDepth(record, 20, 2) shouldBe false
  }

  @Test def testMustHaveVariant() = {
    val reader = new VCFFileReader(vepped, false)
    val record = reader.iterator().next()

    mustHaveVariant(record, List("Child_7006504")) shouldBe true
    mustHaveVariant(record, List("Child_7006504", "Father_7006506")) shouldBe true
    mustHaveVariant(record, List("Child_7006504", "Father_7006506", "Mother_7006508")) shouldBe false
  }

Sander Bollen's avatar
Sander Bollen committed
150
}