Commit 648ed1f3 authored by Peter van 't Hof's avatar Peter van 't Hof

Fixing vcfstats

parent 4f5b8b61
...@@ -14,22 +14,22 @@ ...@@ -14,22 +14,22 @@
*/ */
package nl.lumc.sasc.biopet.tools.vcfstats package nl.lumc.sasc.biopet.tools.vcfstats
import java.io.{ File, FileOutputStream, PrintWriter } import java.io.{File, FileOutputStream, IOException, PrintWriter}
import htsjdk.samtools.util.Interval import htsjdk.samtools.util.Interval
import htsjdk.variant.variantcontext.{ Genotype, VariantContext } import htsjdk.variant.variantcontext.{Genotype, VariantContext}
import htsjdk.variant.vcf.VCFFileReader import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.intervals.BedRecordList import nl.lumc.sasc.biopet.utils.intervals.BedRecordList
import nl.lumc.sasc.biopet.utils.{ ConfigUtils, FastaUtils, ToolCommand, VcfUtils } import nl.lumc.sasc.biopet.utils.{ConfigUtils, FastaUtils, ToolCommand, VcfUtils}
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
import scala.collection.mutable import scala.collection.mutable
import scala.io.Source import scala.io.Source
import scala.sys.process.{ Process, ProcessLogger } import scala.sys.process.{Process, ProcessLogger}
import scala.util.Random import scala.util.Random
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._ import scala.concurrent.duration._
import scala.concurrent.{ Await, Future } import scala.concurrent.{Await, Future}
/** /**
* This tool will generate statistics from a vcf file * This tool will generate statistics from a vcf file
...@@ -557,11 +557,15 @@ object VcfStats extends ToolCommand { ...@@ -557,11 +557,15 @@ object VcfStats extends ToolCommand {
val command: String = "Rscript " + file + " " + args.mkString(" ") val command: String = "Rscript " + file + " " + args.mkString(" ")
logger.info("Starting: " + command) logger.info("Starting: " + command)
val process = Process(command).run(ProcessLogger(x => logger.debug(x), x => logger.debug(x))) try {
if (process.exitValue() == 0) logger.info("Done: " + command) val process = Process(command).run(ProcessLogger(x => logger.debug(x), x => logger.debug(x)))
else { if (process.exitValue() == 0) logger.info("Done: " + command)
logger.warn("Failed: " + command) else {
if (!logger.isDebugEnabled) logger.warn("Use -l debug for more info") logger.warn("Failed: " + command)
if (!logger.isDebugEnabled) logger.warn("Use -l debug for more info")
}
} catch {
case e: IOException =>
} }
} }
} }
...@@ -103,7 +103,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -103,7 +103,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testMergeStatsMap = { def testMergeStatsMap() = {
val m1: mutable.Map[Any, Int] = mutable.Map("a" -> 1) val m1: mutable.Map[Any, Int] = mutable.Map("a" -> 1)
val m2: mutable.Map[Any, Int] = mutable.Map("b" -> 2) val m2: mutable.Map[Any, Int] = mutable.Map("b" -> 2)
...@@ -124,7 +124,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -124,7 +124,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testMergeNestedStatsMap = { def testMergeNestedStatsMap() = {
val m1: mutable.Map[String, mutable.Map[String, mutable.Map[Any, Int]]] = mutable.Map("test" -> val m1: mutable.Map[String, mutable.Map[String, mutable.Map[Any, Int]]] = mutable.Map("test" ->
mutable.Map("nested" -> mutable.Map("a" -> 1))) mutable.Map("nested" -> mutable.Map("a" -> 1)))
val m2: Map[String, Map[String, Map[Any, Int]]] = Map("test" -> val m2: Map[String, Map[String, Map[Any, Int]]] = Map("test" ->
...@@ -152,7 +152,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -152,7 +152,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testValueOfTsv = { def testValueOfTsv() = {
val i = new File(resourcePath("/sample.tsv")) val i = new File(resourcePath("/sample.tsv"))
valueFromTsv(i, "Sample_ID_1", "library") should be(Some("Lib_ID_1")) valueFromTsv(i, "Sample_ID_1", "library") should be(Some("Lib_ID_1"))
...@@ -163,7 +163,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -163,7 +163,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testMain = { def testMain() = {
val tmp = Files.createTempDirectory("vcfStats") val tmp = Files.createTempDirectory("vcfStats")
val vcf = resourcePath("/chrQ.vcf.gz") val vcf = resourcePath("/chrQ.vcf.gz")
val ref = resourcePath("/fake_chrQ.fa") val ref = resourcePath("/fake_chrQ.fa")
...@@ -229,7 +229,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -229,7 +229,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testSortAnyAny = { def testSortAnyAny() = {
//stub //stub
val one: Any = 1 val one: Any = 1
val two: Any = 2 val two: Any = 2
...@@ -245,7 +245,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -245,7 +245,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testCheckGeneral = { def testCheckGeneral() = {
val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next() val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next()
val blah = checkGeneral(record, List()) val blah = checkGeneral(record, List())
...@@ -253,7 +253,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -253,7 +253,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
blah.get("chrQ") should not be empty blah.get("chrQ") should not be empty
blah.get("total") should not be empty blah.get("total") should not be empty
val chrq = blah.get("chrQ").get val chrq = blah("chrQ")
chrq.get("SampleDistribution-NonInformative") shouldEqual Some(Map(0 -> 1)) chrq.get("SampleDistribution-NonInformative") shouldEqual Some(Map(0 -> 1))
chrq.get("SampleDistribution-Called") shouldEqual Some(Map(3 -> 1)) chrq.get("SampleDistribution-Called") shouldEqual Some(Map(3 -> 1))
chrq.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1)) chrq.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1))
...@@ -269,7 +269,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -269,7 +269,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
chrq.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1)) chrq.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1))
chrq.get("general") should not be empty chrq.get("general") should not be empty
val general = chrq.get("general").get val general = chrq("general")
general.get("PolymorphicInSamples") shouldEqual Some(1) general.get("PolymorphicInSamples") shouldEqual Some(1)
general.get("ComplexIndel") shouldEqual Some(0) general.get("ComplexIndel") shouldEqual Some(0)
...@@ -291,7 +291,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -291,7 +291,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("Symbolic") shouldEqual Some(0) general.get("Symbolic") shouldEqual Some(0)
general.get("SimpleInsertion") shouldEqual Some(1) general.get("SimpleInsertion") shouldEqual Some(1)
val total = blah.get("total").get val total = blah("total")
total.get("SampleDistribution-NonInformative") shouldEqual Some(Map(0 -> 1)) total.get("SampleDistribution-NonInformative") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Called") shouldEqual Some(Map(3 -> 1)) total.get("SampleDistribution-Called") shouldEqual Some(Map(3 -> 1))
total.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1)) total.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1))
...@@ -307,7 +307,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -307,7 +307,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
total.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1)) total.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1))
chrq.get("general") should not be empty chrq.get("general") should not be empty
val totGeneral = total.get("general").get val totGeneral = total("general")
totGeneral.get("PolymorphicInSamples") shouldEqual Some(1) totGeneral.get("PolymorphicInSamples") shouldEqual Some(1)
totGeneral.get("ComplexIndel") shouldEqual Some(0) totGeneral.get("ComplexIndel") shouldEqual Some(0)
...@@ -331,7 +331,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -331,7 +331,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
} }
@Test @Test
def testCheckGenotype = { def testCheckGenotype() = {
val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next() val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next()
val genotype = record.getGenotype(0) val genotype = record.getGenotype(0)
...@@ -341,7 +341,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -341,7 +341,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
blah.get("chrQ") should not be empty blah.get("chrQ") should not be empty
blah.get("total") should not be empty blah.get("total") should not be empty
val chrq = blah.get("chrQ").get val chrq = blah("chrQ")
chrq.get("GQ") shouldEqual Some(Map(99 -> 1)) chrq.get("GQ") shouldEqual Some(Map(99 -> 1))
chrq.get("AD") shouldEqual Some(Map(24 -> 1, 21 -> 1)) chrq.get("AD") shouldEqual Some(Map(24 -> 1, 21 -> 1))
chrq.get("AD-used") shouldEqual Some(Map(24 -> 1, 21 -> 1)) chrq.get("AD-used") shouldEqual Some(Map(24 -> 1, 21 -> 1))
...@@ -350,7 +350,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -350,7 +350,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
chrq.get("AD-ref") shouldEqual Some(Map(24 -> 1)) chrq.get("AD-ref") shouldEqual Some(Map(24 -> 1))
chrq.get("general") should not be empty chrq.get("general") should not be empty
val general = chrq.get("general").get val general = chrq("general")
general.get("Hom") shouldEqual Some(0) general.get("Hom") shouldEqual Some(0)
general.get("NoCall") shouldEqual Some(0) general.get("NoCall") shouldEqual Some(0)
general.get("Variant") shouldEqual Some(1) general.get("Variant") shouldEqual Some(1)
...@@ -365,7 +365,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -365,7 +365,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("Het") shouldEqual Some(1) general.get("Het") shouldEqual Some(1)
general.get("HetNonRef") shouldEqual Some(0) general.get("HetNonRef") shouldEqual Some(0)
val total = blah.get("total").get val total = blah("total")
total.get("GQ") shouldEqual Some(Map(99 -> 1)) total.get("GQ") shouldEqual Some(Map(99 -> 1))
total.get("AD") shouldEqual Some(Map(24 -> 1, 21 -> 1)) total.get("AD") shouldEqual Some(Map(24 -> 1, 21 -> 1))
total.get("AD-used") shouldEqual Some(Map(24 -> 1, 21 -> 1)) total.get("AD-used") shouldEqual Some(Map(24 -> 1, 21 -> 1))
...@@ -374,7 +374,7 @@ class VcfStatsTest extends TestNGSuite with Matchers { ...@@ -374,7 +374,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
total.get("AD-ref") shouldEqual Some(Map(24 -> 1)) total.get("AD-ref") shouldEqual Some(Map(24 -> 1))
total.get("general") should not be empty total.get("general") should not be empty
val totGeneral = total.get("general").get val totGeneral = total("general")
totGeneral.get("Hom") shouldEqual Some(0) totGeneral.get("Hom") shouldEqual Some(0)
totGeneral.get("NoCall") shouldEqual Some(0) totGeneral.get("NoCall") shouldEqual Some(0)
totGeneral.get("Variant") shouldEqual Some(1) totGeneral.get("Variant") shouldEqual Some(1)
......
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
*/ */
package nl.lumc.sasc.biopet.utils package nl.lumc.sasc.biopet.utils
import java.io.{ File, FileInputStream, FileOutputStream, InputStream } import java.io._
import scala.io.Source import scala.io.Source
import scala.sys.process.Process
/** /**
* This object contains generic io methods * This object contains generic io methods
...@@ -83,4 +84,13 @@ object IoUtils { ...@@ -83,4 +84,13 @@ object IoUtils {
reader.close() reader.close()
lines lines
} }
def executableExist(exe: String): Boolean = {
try {
val process = Process(Seq(exe)).run()
true
} catch {
case e: IOException => false
}
}
} }
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