VcfFilterTest.scala 6.79 KB
Newer Older
Sander Bollen's avatar
Sander Bollen committed
1
2
3
4
5
import java.io.File

import nl.lumc.sasc.biopet.extensions.tools.VcfFilter
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
6
import org.testng.annotations.{ DataProvider, Test }
Sander Bollen's avatar
Sander Bollen committed
7
8

/**
9
10
 * Created by ahbbollen on 2-3-16.
 */
Sander Bollen's avatar
Sander Bollen committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class VcfFilterTest extends TestNGSuite with Matchers {

  def cmd(s: String) = {
    s.replace("'", "").replace("  ", " ").trim
  }

  @Test
  def testBeforeGraph() = {
    val filterer = new VcfFilter(null)
    val iVcf = File.createTempFile("vcfFilter", ".vcf.gz")
    val oVcf = File.createTempFile("vcfFilter", ".vcf.gz")
    iVcf.deleteOnExit()
    oVcf.deleteOnExit()
    filterer.inputVcf = iVcf
    filterer.outputVcf = oVcf

    filterer.beforeGraph()
    filterer.outputVcfIndex.getAbsolutePath shouldBe oVcf.getAbsolutePath + ".tbi"
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
31
32
33
34
35
  @DataProvider(name = "functions")
  def functions = {
    Array(
      () => testCommand(minSampleDepth = Some(2)),
      () => testCommand(minTotalDepth = Some(2)),
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      () => testCommand(minAlternateDepth = Some(2)),
      () => testCommand(minSamplesPass = Some(2)),
      () => testCommand(minGenomeQuality = Some(50)),
      () => testCommand(filterRefCalls = true),
      () => testCommand(invertedOutputVcf = Some(File.createTempFile("vcfFilter", ".vcf"))),
      () => testCommand(resToDom = Some("dummy")),
      () => testCommand(trioCompound = Some("dummy")),
      () => testCommand(deNovoInSample = Some("dummy")),
      () => testCommand(deNovoTrio = Some("dummy")),
      () => testCommand(trioLossOfHet = Some("dummy")),
      () => testCommand(mustHaveVariant = List("sample1", "sample2")),
      () => testCommand(calledIn = List("sample1", "sample2")),
      () => testCommand(mustHaveGenotype = List("sample1:HET", "sample2:HET")),
      () => testCommand(diffGenotype = List("sample1:sample2", "sample2:sample3")),
      () => testCommand(minQualScore = Some(50.0)),
      () => testCommand(filterHetVarToHomVar = List("dummy")),
      () => testCommand(id = List("rs01", "rs02")),
      () => testCommand(idFile = Some(File.createTempFile("vcfFilter", ".txt")))
Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
56
57
58
59
    ).map(Array(_))
  }

  @Test(dataProvider = "functions")
  def executer(function0: Function0[Unit]): Unit = function0()

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  protected def testCommand(minSampleDepth: Option[Int] = None,
                            minTotalDepth: Option[Int] = None,
                            minAlternateDepth: Option[Int] = None,
                            minSamplesPass: Option[Int] = None,
                            minGenomeQuality: Option[Int] = None,
                            filterRefCalls: Boolean = false,
                            invertedOutputVcf: Option[File] = None,
                            resToDom: Option[String] = None,
                            trioCompound: Option[String] = None,
                            deNovoInSample: Option[String] = None,
                            deNovoTrio: Option[String] = None,
                            trioLossOfHet: Option[String] = None,
                            mustHaveVariant: List[String] = Nil,
                            calledIn: List[String] = Nil,
                            mustHaveGenotype: List[String] = Nil,
                            diffGenotype: List[String] = Nil,
                            filterHetVarToHomVar: List[String] = Nil,
                            minQualScore: Option[Double] = None,
                            id: List[String] = Nil,
                            idFile: Option[File] = None): Unit = {

Peter van 't Hof's avatar
Peter van 't Hof committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    val vcfFilter = new VcfFilter(null)
    vcfFilter.minSampleDepth = minSampleDepth
    vcfFilter.minTotalDepth = minTotalDepth
    vcfFilter.minAlternateDepth = minAlternateDepth
    vcfFilter.minSamplesPass = minSamplesPass
    vcfFilter.minGenomeQuality = minGenomeQuality
    vcfFilter.filterRefCalls = filterRefCalls
    vcfFilter.invertedOutputVcf = invertedOutputVcf
    vcfFilter.resToDom = resToDom
    vcfFilter.trioCompound = trioCompound
    vcfFilter.deNovoInSample = deNovoInSample
    vcfFilter.deNovoTrio = deNovoTrio
    vcfFilter.trioLossOfHet = trioLossOfHet
    vcfFilter.mustHaveVariant = mustHaveVariant
    vcfFilter.calledIn = calledIn
    vcfFilter.mustHaveGenotype = mustHaveGenotype
    vcfFilter.diffGenotype = diffGenotype
    vcfFilter.filterHetVarToHomVar = filterHetVarToHomVar
    vcfFilter.minQualScore = minQualScore
    vcfFilter.id = id
    vcfFilter.idFile = idFile
102
103
104
105
106
107
108
109
110
111
112
113
    val command = cmd(vcfFilter.cmdLine)

    var cmdString: List[String] = Nil
    if (minSampleDepth.isDefined) {
      cmdString = "--minSampleDepth " + minSampleDepth.getOrElse("") :: cmdString
    }

    if (minTotalDepth.isDefined) {
      cmdString = "--minTotalDepth " + minTotalDepth.getOrElse("") :: cmdString
    }

    if (minAlternateDepth.isDefined) {
114
      cmdString = "--minAlternateDepth " + minAlternateDepth.getOrElse("") :: cmdString
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    }

    if (minSamplesPass.isDefined) {
      cmdString = "--minSamplesPass " + minSamplesPass.getOrElse("") :: cmdString
    }

    if (minGenomeQuality.isDefined) {
      cmdString = "--minGenomeQuality " + minGenomeQuality.getOrElse("") :: cmdString
    }

    if (filterRefCalls) {
      cmdString = "--filterRefCalls" :: cmdString
    }

    if (invertedOutputVcf.isDefined) {
      cmdString = "--invertedOutputVcf " + invertedOutputVcf.getOrElse(new File("")).getAbsolutePath :: cmdString
    }

    if (resToDom.isDefined) {
      cmdString = "--resToDom " + resToDom.getOrElse("") :: cmdString
    }

    if (trioCompound.isDefined) {
      cmdString = "--trioCompound " + trioCompound.getOrElse("") :: cmdString
    }

    if (deNovoInSample.isDefined) {
      cmdString = "--deNovoInSample " + deNovoInSample.getOrElse("") :: cmdString
    }

    if (deNovoTrio.isDefined) {
      cmdString = "--deNovoTrio " + deNovoTrio.getOrElse("") :: cmdString
    }

    if (trioLossOfHet.isDefined) {
      cmdString = "--trioLossOfHet " + trioLossOfHet.getOrElse("") :: cmdString
    }

    if (mustHaveVariant.nonEmpty) {
      cmdString = mustHaveVariant.map(x => "--mustHaveVariant " + x) ::: cmdString
    }

    if (calledIn.nonEmpty) {
      cmdString = calledIn.map(x => "--calledIn " + x) ::: cmdString
    }

    if (mustHaveGenotype.nonEmpty) {
      cmdString = mustHaveGenotype.map(x => "--mustHaveGenotype " + x) ::: cmdString
    }

    if (diffGenotype.nonEmpty) {
      cmdString = diffGenotype.map(x => "--diffGenotype " + x) ::: cmdString
    }

    if (filterHetVarToHomVar.nonEmpty) {
      cmdString = filterHetVarToHomVar.map(x => "--filterHetVarToHomVar " + x) ::: cmdString
    }

    if (id.nonEmpty) {
      cmdString = id.map(x => "--id " + x) ::: cmdString
    }

    if (idFile.isDefined) {
      cmdString = "--idFile " + idFile.getOrElse(new File("")).getAbsolutePath :: cmdString
    }

    if (minQualScore.isDefined) {
      cmdString = "--minQualScore " + minQualScore.getOrElse("") :: cmdString
    }

    cmdString.foreach(x => command.contains(x) shouldBe true)
Peter van 't Hof's avatar
Peter van 't Hof committed
186
187
  }

Sander Bollen's avatar
Sander Bollen committed
188
}