VEPNormalizerTest.scala 3.47 KB
Newer Older
bow's avatar
bow 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.
 */
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package nl.lumc.sasc.biopet.tools

import org.scalatest.testng.TestNGSuite
import org.scalatest.mock.MockitoSugar
import org.scalatest.Matchers
import java.io.File
import java.nio.file.Paths
import org.testng.annotations.Test
import htsjdk.variant.vcf.VCFFileReader
import htsjdk.tribble.TribbleException
import scala.collection.JavaConversions._
import htsjdk.variant.variantcontext.VariantContext

/**
 * This class tests the VEPNormalizer
 * Created by ahbbollen on 11/24/14.
 */
class VEPNormalizerTest extends TestNGSuite with MockitoSugar with Matchers {
  import VEPNormalizer._

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

  val vcf3 = new File(resourcePath("/VCFv3.vcf"))
  val vepped = new File(resourcePath("/VEP_oneline.vcf"))
  val unvepped = new File(resourcePath("/unvepped.vcf"))

  @Test def testVEPHeaderLength() = {
    val reader = new VCFFileReader(vepped, false)
    val header = reader.getFileHeader
47
    parseCsq(header).length should be(27)
48
49
50
51
52
  }

  @Test def testExplodeVEPLength() = {
    val reader = new VCFFileReader(vepped, false)
    val header = reader.getFileHeader
53
    val new_infos = parseCsq(header)
54
    explodeTranscripts(reader.iterator().next(), new_infos, true).length should be(11)
55
56
57
58
59
  }

  @Test def testStandardVEPLength() = {
    val reader = new VCFFileReader(vepped, false)
    val header = reader.getFileHeader
60
    val new_infos = parseCsq(header)
61
    Array(standardTranscripts(reader.iterator().next(), new_infos, true)).length should be(1)
62
63
64
65
66
  }

  @Test def testStandardVEPAttributeLength() = {
    val reader = new VCFFileReader(vepped, false)
    val header = reader.getFileHeader
67
    val new_infos = parseCsq(header)
68
    val record = standardTranscripts(reader.iterator().next(), new_infos, true)
69
70
71
72
73
    def checkItems(items: Array[String]) = {
      items.foreach { check }
    }

    def check(item: String) = {
Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
      record.getAttribute(item) match {
        case l: List[_] => l.length should be(11)
        case _          =>
      }
78
79
80
81
82
83
    }

    val items = Array("AA_MAF", "AFR_MAF", "ALLELE_NUM", "AMR_MAF", "ASN_MAF", "Allele",
      "Amino_acids", "CDS_position", "CLIN_SIG", "Codons", "Consequence", "DISTANCE",
      "EA_MAF", "EUR_MAF", "Existing_variation", "Feature", "Feature_type",
      "GMAF", "Gene", "HGVSc", "HGVSp", "PUBMED", "Protein_position", "STRAND", "SYMBOL",
84
      "SYMBOL_SOURCE", "cDNA_position").map("VEP_" + _)
85
86
87
88
89
90
91
92
93

    checkItems(items)
  }

  @Test(expectedExceptions = Array(classOf[TribbleException.MalformedFeatureFile]))
  def testVCF3TribbleException() = {
    val reader = new VCFFileReader(vcf3, false)
  }

94
  @Test(expectedExceptions = Array(classOf[IllegalArgumentException]))
95
  def testNoCSQTagException() {
96
    csqCheck(new VCFFileReader(unvepped, false).getFileHeader)
97
98
99
  }

}