Skip to content
Snippets Groups Projects
Commit 648ed1f3 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fixing vcfstats

parent 4f5b8b61
No related branches found
No related tags found
No related merge requests found
......@@ -14,22 +14,22 @@
*/
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.variant.variantcontext.{ Genotype, VariantContext }
import htsjdk.variant.variantcontext.{Genotype, VariantContext}
import htsjdk.variant.vcf.VCFFileReader
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.mutable
import scala.io.Source
import scala.sys.process.{ Process, ProcessLogger }
import scala.sys.process.{Process, ProcessLogger}
import scala.util.Random
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{ Await, Future }
import scala.concurrent.{Await, Future}
/**
* This tool will generate statistics from a vcf file
......@@ -557,11 +557,15 @@ object VcfStats extends ToolCommand {
val command: String = "Rscript " + file + " " + args.mkString(" ")
logger.info("Starting: " + command)
val process = Process(command).run(ProcessLogger(x => logger.debug(x), x => logger.debug(x)))
if (process.exitValue() == 0) logger.info("Done: " + command)
else {
logger.warn("Failed: " + command)
if (!logger.isDebugEnabled) logger.warn("Use -l debug for more info")
try {
val process = Process(command).run(ProcessLogger(x => logger.debug(x), x => logger.debug(x)))
if (process.exitValue() == 0) logger.info("Done: " + command)
else {
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 {
}
@Test
def testMergeStatsMap = {
def testMergeStatsMap() = {
val m1: mutable.Map[Any, Int] = mutable.Map("a" -> 1)
val m2: mutable.Map[Any, Int] = mutable.Map("b" -> 2)
......@@ -124,7 +124,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testMergeNestedStatsMap = {
def testMergeNestedStatsMap() = {
val m1: mutable.Map[String, mutable.Map[String, mutable.Map[Any, Int]]] = mutable.Map("test" ->
mutable.Map("nested" -> mutable.Map("a" -> 1)))
val m2: Map[String, Map[String, Map[Any, Int]]] = Map("test" ->
......@@ -152,7 +152,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testValueOfTsv = {
def testValueOfTsv() = {
val i = new File(resourcePath("/sample.tsv"))
valueFromTsv(i, "Sample_ID_1", "library") should be(Some("Lib_ID_1"))
......@@ -163,7 +163,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testMain = {
def testMain() = {
val tmp = Files.createTempDirectory("vcfStats")
val vcf = resourcePath("/chrQ.vcf.gz")
val ref = resourcePath("/fake_chrQ.fa")
......@@ -229,7 +229,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testSortAnyAny = {
def testSortAnyAny() = {
//stub
val one: Any = 1
val two: Any = 2
......@@ -245,7 +245,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testCheckGeneral = {
def testCheckGeneral() = {
val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next()
val blah = checkGeneral(record, List())
......@@ -253,7 +253,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
blah.get("chrQ") 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-Called") shouldEqual Some(Map(3 -> 1))
chrq.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1))
......@@ -269,7 +269,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
chrq.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1))
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("ComplexIndel") shouldEqual Some(0)
......@@ -291,7 +291,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("Symbolic") shouldEqual Some(0)
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-Called") shouldEqual Some(Map(3 -> 1))
total.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1))
......@@ -307,7 +307,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
total.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1))
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("ComplexIndel") shouldEqual Some(0)
......@@ -331,7 +331,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
}
@Test
def testCheckGenotype = {
def testCheckGenotype() = {
val record = new VCFFileReader(new File(resourcePath("/chrQ.vcf.gz"))).iterator().next()
val genotype = record.getGenotype(0)
......@@ -341,7 +341,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
blah.get("chrQ") 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("AD") 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 {
chrq.get("AD-ref") shouldEqual Some(Map(24 -> 1))
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("NoCall") shouldEqual Some(0)
general.get("Variant") shouldEqual Some(1)
......@@ -365,7 +365,7 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("Het") shouldEqual Some(1)
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("AD") 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 {
total.get("AD-ref") shouldEqual Some(Map(24 -> 1))
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("NoCall") shouldEqual Some(0)
totGeneral.get("Variant") shouldEqual Some(1)
......
......@@ -14,9 +14,10 @@
*/
package nl.lumc.sasc.biopet.utils
import java.io.{ File, FileInputStream, FileOutputStream, InputStream }
import java.io._
import scala.io.Source
import scala.sys.process.Process
/**
* This object contains generic io methods
......@@ -83,4 +84,13 @@ object IoUtils {
reader.close()
lines
}
def executableExist(exe: String): Boolean = {
try {
val process = Process(Seq(exe)).run()
true
} catch {
case e: IOException => false
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment