ValidateFastqTest.scala 4.17 KB
Newer Older
1
2
3
4
5
6
7
package nl.lumc.sasc.biopet.tools

import java.nio.file.Paths

import htsjdk.samtools.fastq.FastqRecord
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
Peter van 't Hof's avatar
Peter van 't Hof committed
8
import org.testng.annotations.{ DataProvider, Test }
9
10

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
11
12
 * This class test ValidateFatq
 *
Peter van 't Hof's avatar
Peter van 't Hof committed
13
14
 * Created by pjvan_thof on 2/17/16.
 */
15
16
17
class ValidateFastqTest extends TestNGSuite with Matchers {

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
18
  def testCheckMate(): Unit = {
19
20
21
22
23
24
25
26
    ValidateFastq.checkMate(new FastqRecord("read_1", "ATCG", "", "AAAA"), new FastqRecord("read_1", "ATCG", "", "AAAA"))

    intercept[IllegalStateException] {
      ValidateFastq.checkMate(new FastqRecord("read_1", "ATCG", "", "AAAA"), new FastqRecord("read_2", "ATCG", "", "AAAA"))
    }
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
27
  def testDuplicateCheck(): Unit = {
28
29
30
31
32
33
34
35
36
37
    ValidateFastq.duplicateCheck(new FastqRecord("read_1", "ATCG", "", "AAAA"), None)
    ValidateFastq.duplicateCheck(new FastqRecord("read_1", "ATCG", "", "AAAA"), Some(new FastqRecord("read_2", "ATCG", "", "AAAA")))

    intercept[IllegalStateException] {
      ValidateFastq.duplicateCheck(new FastqRecord("read_1", "ATCG", "", "AAAA"), Some(new FastqRecord("read_1", "ATCG", "", "AAAA")))
    }
  }

  @DataProvider(name = "providerGetPossibleEncodings")
  def providerGetPossibleEncodings = Array(
Peter van 't Hof's avatar
Peter van 't Hof committed
38
39
40
41
42
43
44
45
46
47
48
    Array(None, None, Nil),
    Array(Some('A'), None, Nil),
    Array(None, Some('A'), Nil),
    Array(Some('E'), Some('E'), List("Sanger", "Solexa", "Illumina 1.3+", "Illumina 1.5+", "Illumina 1.8+")),
    Array(Some('+'), Some('+'), List("Sanger", "Illumina 1.8+")),
    Array(Some('!'), Some('I'), List("Sanger", "Illumina 1.8+")),
    Array(Some('!'), Some('J'), List("Illumina 1.8+")),
    Array(Some(';'), Some('h'), List("Solexa")),
    Array(Some('@'), Some('h'), List("Solexa", "Illumina 1.3+")),
    Array(Some('C'), Some('h'), List("Solexa", "Illumina 1.3+", "Illumina 1.5+"))
  )
49
50
51
52
53
54
55
56
57

  @Test(dataProvider = "providerGetPossibleEncodings")
  def testGetPossibleEncodings(min: Option[Char], max: Option[Char], output: List[String]): Unit = {
    ValidateFastq.minQual = min
    ValidateFastq.maxQual = max
    ValidateFastq.getPossibleEncodings shouldBe output
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
58
  def testGetPossibleEncodingsFail(): Unit = {
Peter van 't Hof's avatar
Peter van 't Hof committed
59
60
61
    ValidateFastq.minQual = Some('!')
    ValidateFastq.maxQual = Some('h')
    ValidateFastq.getPossibleEncodings shouldBe Nil
62
63
64
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
65
  def testCheckQualEncoding(): Unit = {
66
67
68
    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None
    ValidateFastq.checkQualEncoding(new FastqRecord("read_1", "ATCG", "", "AAAA"))
Peter van 't Hof's avatar
Peter van 't Hof committed
69
    ValidateFastq.getPossibleEncodings should not be Nil
70

Peter van 't Hof's avatar
Peter van 't Hof committed
71
72
    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None
73

Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
78
79
80
81
82
    ValidateFastq.checkQualEncoding(new FastqRecord("read_1", "ATCG", "", "A!hA"))
    ValidateFastq.getPossibleEncodings shouldBe Nil

    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None

    ValidateFastq.checkQualEncoding(new FastqRecord("read_1", "ATCG", "", "hhhh"))
    ValidateFastq.checkQualEncoding(new FastqRecord("read_1", "ATCG", "", "!!!!"))
    ValidateFastq.getPossibleEncodings shouldBe Nil
83
84
85
86

    intercept[IllegalStateException] {
      ValidateFastq.minQual = None
      ValidateFastq.maxQual = None
Peter van 't Hof's avatar
Peter van 't Hof committed
87
      ValidateFastq.checkQualEncoding(new FastqRecord("read_1", "ATCG", "", "!! !!"))
88
89
90
91
    }
  }

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
92
  def testValidFastqRecord(): Unit = {
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None
    ValidateFastq.validFastqRecord(new FastqRecord("read_1", "ATCG", "", "AAAA"))

    intercept[IllegalStateException] {
      ValidateFastq.validFastqRecord(new FastqRecord("read_1", "ATCG", "", "AAA"))
    }

    intercept[IllegalStateException] {
      ValidateFastq.validFastqRecord(new FastqRecord("read_1", "ATYG", "", "AAAA"))
    }
  }

  private def resourcePath(p: String): String =
    Paths.get(getClass.getResource(p).toURI).toString

  @Test
Peter van 't Hof's avatar
Peter van 't Hof committed
110
  def testMain(): Unit = {
111
112
113
114
115
116
117
118
119
120
121
122
123
    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None
    val r1 = resourcePath("/paired01a.fq")
    val r2 = resourcePath("/paired01b.fq")
    ValidateFastq.main(Array("-i", r1, "-j", r2))

    //TODO: capture logs
    ValidateFastq.minQual = None
    ValidateFastq.maxQual = None
    val r2fail = resourcePath("/paired01c.fq")
    ValidateFastq.main(Array("-i", r1, "-j", r2fail))
  }
}