Commit 58d986d3 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'fix-vcffilter-extension' into 'develop'

Fix vcffilter extension



See merge request !335
parents 8c75f931 c75b0c16
......@@ -44,6 +44,24 @@
<artifactId>BiopetTools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>2.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -39,6 +39,20 @@ class VcfFilter(val root: Configurable) extends ToolCommandFunction {
var minSamplesPass: Option[Int] = config("min_samples_pass")
var minGenomeQuality: Option[Int] = config("min_genome_quality")
var filterRefCalls: Boolean = config("filter_ref_calls", default = false)
var invertedOutputVcf: Option[File] = None
var resToDom: Option[String] = None
var trioCompound: Option[String] = None
var deNovoInSample: Option[String] = None
var deNovoTrio: Option[String] = None
var trioLossOfHet: Option[String] = None
var mustHaveVariant: List[String] = Nil
var calledIn: List[String] = Nil
var mustHaveGenotype: List[String] = Nil
var diffGenotype: List[String] = Nil
var filterHetVarToHomVar: List[String] = Nil
var minQualScore: Option[Double] = None
var id: List[String] = Nil
var idFile: Option[File] = None
override def defaultCoreMemory = 3.0
......@@ -55,5 +69,19 @@ class VcfFilter(val root: Configurable) extends ToolCommandFunction {
optional("--minAlternateDepth", minAlternateDepth) +
optional("--minSamplesPass", minSamplesPass) +
optional("--minGenomeQuality", minGenomeQuality) +
conditional(filterRefCalls, "--filterRefCalls")
conditional(filterRefCalls, "--filterRefCalls") +
optional("--invertedOutputVcf", invertedOutputVcf) +
optional("--resToDom", resToDom) +
optional("--trioCompound", trioCompound) +
optional("--deNovoInSample", deNovoInSample) +
optional("--deNovoTrio", deNovoTrio) +
optional("--trioLossOfHet", trioLossOfHet) +
repeat("--mustHaveVariant", mustHaveVariant) +
repeat("--calledIn", calledIn) +
repeat("--mustHaveGenotype", mustHaveGenotype) +
repeat("--diffGenotype", diffGenotype) +
repeat("--filterHetVarToHomVar", filterHetVarToHomVar) +
optional("--minQualScore", minQualScore) +
repeat("--id", id) +
optional("--idFile", idFile)
}
import java.io.File
import nl.lumc.sasc.biopet.extensions.tools.VcfFilter
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{DataProvider, Test}
/**
* Created by ahbbollen on 2-3-16.
*/
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"
}
@DataProvider(name = "functions")
def functions = {
Array(
() => testCommand(minSampleDepth = Some(2)),
() => testCommand(minTotalDepth = Some(2)),
() => 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")))
).map(Array(_))
}
@Test(dataProvider = "functions")
def executer(function0: Function0[Unit]): Unit = function0()
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 = {
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
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) {
cmdString = "--minAlternateDepth " + minAlternateDepth.getOrElse("") :: cmdString
}
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)
}
}
......@@ -169,6 +169,11 @@ object SeqStat extends ToolCommand {
procesRead(read)
numReads += 1
}
if (numReads % 1000000 == 0) {
logger.info(s"Processed $numReads reads")
}
numReads
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment