diff --git a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/VcfStats.scala b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/VcfStats.scala index e1c2f3539b605da089413f5717c4ca03a6ee0902..65801c97f19249391a0adaa6926380e1ac94345f 100644 --- a/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/VcfStats.scala +++ b/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/vcfstats/VcfStats.scala @@ -74,7 +74,7 @@ object VcfStats extends ToolCommand { opt[File]('o', "outputDir") required () unbounded () maxOccurs 1 valueName "" action { (x, c) => c.copy(outputDir = x) } validate { - x => if (x == null) failure("Output directory required") else success + x => if (x == null) failure("Valid output directory required") else if (x.exists) success else failure(s"Output directory does not exist: $x") } text "Path to directory for output (required)" opt[File]('i', "intervals") unbounded () valueName "" action { (x, c) => c.copy(intervals = Some(x)) diff --git a/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfStatsTest.scala b/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfStatsTest.scala index f0eeac2b8df529653b1ec2f05db9fbc007c3597f..0b49c170479d86daf7d7b3e647c31c292485fbe1 100644 --- a/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfStatsTest.scala +++ b/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfStatsTest.scala @@ -15,15 +15,16 @@ package nl.lumc.sasc.biopet.tools import java.io.File -import java.nio.file.{ Files, Paths } +import java.nio.file.{Files, Paths} import htsjdk.variant.vcf.VCFFileReader -import nl.lumc.sasc.biopet.tools.vcfstats.{ SampleStats, SampleToSampleStats, Stats, VcfStats } +import nl.lumc.sasc.biopet.tools.vcfstats.{SampleStats, SampleToSampleStats, Stats, VcfStats} import nl.lumc.sasc.biopet.tools.vcfstats.VcfStats._ import org.scalatest.Matchers import org.scalatest.testng.TestNGSuite import org.testng.annotations.Test import nl.lumc.sasc.biopet.utils.sortAnyAny +import org.apache.commons.io.FileUtils import scala.collection.mutable @@ -162,6 +163,16 @@ class VcfStatsTest extends TestNGSuite with Matchers { valueFromTsv(i, "Sample_ID_3", "bam") should be(empty) } + @Test + def testNoExistOutputDir: Unit = { + val tmp = Files.createTempDirectory("vcfStats") + FileUtils.deleteDirectory(new File(tmp.toAbsolutePath.toString)) + val vcf = resourcePath("/chrQ.vcf.gz") + val ref = resourcePath("/fake_chrQ.fa") + + an [IllegalArgumentException] should be thrownBy main(Array("-I", vcf, "-R", ref, "-o", tmp.toAbsolutePath.toString)) + } + @Test def testMain() = { val tmp = Files.createTempDirectory("vcfStats")