Commit 24ac7790 authored by Sander Bollen's avatar Sander Bollen Committed by GitHub
Browse files

Merge pull request #4 from biopet/fix-BIOPET-379

Fix BIOPET-379
parents 4f5b8b61 9b522749
......@@ -177,4 +177,52 @@ object BiopetQScript {
require(outputDir.getAbsoluteFile.canWrite, s"No premision to write outputdir: $outputDir")
}
def safeInputs(function: QFunction): Option[Seq[File]] = {
try {
Some(function.inputs)
} catch {
case e: NullPointerException => None
}
}
def safeOutputs(function: QFunction): Option[Seq[File]] = {
try {
Some(function.outputs)
} catch {
case e: NullPointerException => None
}
}
def safeDoneFiles(function: QFunction): Option[Seq[File]] = {
try {
Some(function.doneOutputs)
} catch {
case e: NullPointerException => None
}
}
def safeFailFiles(function: QFunction): Option[Seq[File]] = {
try {
Some(function.failOutputs)
} catch {
case e: NullPointerException => None
}
}
def safeIsDone(function: QFunction): Option[Boolean] = {
try {
Some(function.isDone)
} catch {
case e: NullPointerException => None
}
}
def safeIsFail(function: QFunction): Option[Boolean] = {
try {
Some(function.isFail)
} catch {
case e: NullPointerException => None
}
}
}
......@@ -141,11 +141,17 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
/** returns a set with library names or throws error when not found */
protected def libIds: Set[String] = {
val ids = ConfigUtils.getMapFromPath(globalConfig.map, List("samples", sampleId, "libraries")).getOrElse(Map()).keySet
if (ids.isEmpty) {
throw new IllegalStateException(s"No libraries found in config for sample $sampleId")
val ids: Set[String] = try {
ConfigUtils.getMapFromPath(globalConfig.map, List("samples", sampleId, "libraries")).getOrElse(Map()).keySet
} catch {
case e: IllegalStateException if e.getMessage == "Value is not a map: library" =>
Logging.addError("libraries for samples are not formatted correctly")
Set()
}
ids
if (ids.isEmpty) {
Logging.addError(s"No libraries found in config for sample $sampleId")
Set("placeholder")
} else ids
}
/** Name overules the one from qscript */
......
......@@ -90,18 +90,13 @@ object WriteDependencies extends Logging with Configurable {
val files: mutable.Map[File, QueueFile] = mutable.Map()
def outputFiles(function: QFunction) = {
if (function.jobErrorFile == null) function.outputs :+ function.jobOutputFile
else function.outputs :+ function.jobOutputFile :+ function.jobErrorFile
}
for (function <- functions) {
for (input <- function.inputs) {
for (input <- BiopetQScript.safeInputs(function).getOrElse(Seq())) {
val file = files.getOrElse(input, QueueFile(input))
file.addInputJob(function)
files += input -> file
}
for (output <- outputFiles(function)) {
for (output <- BiopetQScript.safeOutputs(function).getOrElse(Seq())) {
val file = files.getOrElse(output, QueueFile(output))
file.addOutputJob(function)
files += output -> file
......@@ -118,16 +113,16 @@ object WriteDependencies extends Logging with Configurable {
case s: WriteSummary if s.qscript.root == null => true
case _ => false
}), "intermediate" -> f.isIntermediate,
"depends_on_intermediate" -> f.inputs.exists(files(_).isIntermediate),
"depends_on_jobs" -> f.inputs.toList.flatMap(files(_).outputJobNames).distinct,
"output_used_by_jobs" -> outputFiles(f).toList.flatMap(files(_).inputJobNames).distinct,
"outputs" -> outputFiles(f).toList,
"inputs" -> f.inputs.toList,
"done_files" -> f.doneOutputs.toList,
"fail_files" -> f.failOutputs.toList,
"depends_on_intermediate" -> BiopetQScript.safeOutputs(f).getOrElse(Seq()).exists(files(_).isIntermediate),
"depends_on_jobs" -> BiopetQScript.safeOutputs(f).getOrElse(Seq()).toList.flatMap(files(_).outputJobNames).distinct,
"output_used_by_jobs" -> BiopetQScript.safeOutputs(f).getOrElse(Seq()).toList.flatMap(files(_).inputJobNames).distinct,
"outputs" -> BiopetQScript.safeOutputs(f).getOrElse(Seq()).toList,
"inputs" -> BiopetQScript.safeOutputs(f).getOrElse(Seq()).toList,
"done_files" -> BiopetQScript.safeDoneFiles(f).getOrElse(Seq()).toList,
"fail_files" -> BiopetQScript.safeFailFiles(f).getOrElse(Seq()).toList,
"stdout_file" -> f.jobOutputFile,
"done_at_start" -> f.isDone,
"fail_at_start" -> f.isFail)
"done_at_start" -> BiopetQScript.safeIsDone(f),
"fail_at_start" -> BiopetQScript.safeIsFail(f))
}.toIterator.toMap
val outputFile = new File(outputDir, s"deps.json")
......
......@@ -15,11 +15,12 @@
package nl.lumc.sasc.biopet.core
import java.io.File
import nl.lumc.sasc.biopet.core.MultiSampleQScript.Gender
import nl.lumc.sasc.biopet.core.extensions.Md5sum
import nl.lumc.sasc.biopet.utils.{ ConfigUtils, Logging }
import nl.lumc.sasc.biopet.utils.{ConfigUtils, Logging}
import nl.lumc.sasc.biopet.utils.config.Config
import org.broadinstitute.gatk.queue.QScript
import org.broadinstitute.gatk.queue.{QScript, QSettings}
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
......@@ -121,7 +122,7 @@ class MultiSampleQScriptTest extends TestNGSuite with Matchers {
@Test
def testNoLibSample(): Unit = {
an[IllegalStateException] shouldBe thrownBy(MultiSampleQScriptTest(noLibSample :: Nil))
an[IllegalStateException] shouldBe thrownBy(MultiSampleQScriptTest(Map("output_dir" -> ".") :: noLibSample :: Nil).script())
}
}
......@@ -203,6 +204,9 @@ object MultiSampleQScriptTest {
def apply(configs: List[Map[String, Any]], only: List[String] = Nil) = {
new QScript with MultiSampleQScript { qscript =>
qSettings = new QSettings()
qSettings.runName = "test"
override val onlySamples = only
var buffer = new ListBuffer[String]()
......@@ -272,7 +276,7 @@ object MultiSampleQScriptTest {
def summaryFiles: Map[String, File] = Map()
/** Name of summary output file */
def summaryFile: File = null
def summaryFile: File = new File("./summary.json")
/** Init for pipeline */
def init(): Unit = {
......
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