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

Error cache now also works on executables

parent fbed4e7c
......@@ -66,7 +66,7 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
super.freezeFieldValues()
}
protected def checkExecutable {
protected[core] def checkExecutable {
if (!BiopetCommandLineFunctionTrait.executableMd5Cache.contains(executable)) {
try if (executable != null) {
if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable)) {
......@@ -79,8 +79,7 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
val file = new File(executable)
executable = file.getCanonicalPath
} else {
logger.error("executable: '" + executable + "' not found, please check config")
throw new QException("executable: '" + executable + "' not found, please check config")
BiopetQScript.addError("executable: '" + executable + "' not found, please check config")
}
BiopetCommandLineFunctionTrait.executableCache += oldExecutable -> executable
BiopetCommandLineFunctionTrait.executableCache += executable -> executable
......@@ -101,9 +100,8 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
case ioe: java.io.IOException => logger.warn("Could not use 'which', check on executable skipped: " + ioe)
}
}
val md5 = BiopetCommandLineFunctionTrait.executableMd5Cache(executable)
if (md5 == null) addJobReportBinding("md5sum_exe", md5)
else addJobReportBinding("md5sum_exe", "None")
val md5 = BiopetCommandLineFunctionTrait.executableMd5Cache.get(executable)
addJobReportBinding("md5sum_exe", md5.getOrElse("None"))
}
final protected def preCmdInternal {
......@@ -120,6 +118,11 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
protected val versionExitcode = List(0) // Can select multiple
private def getVersionInternal: String = {
if (versionCommand == null || versionRegex == null) return "N/A"
val exe = new File(versionCommand.trim.split(" ")(0))
if (!exe.exists()) {
//BiopetQScript.addError("executable '" + exe + "' does not exist")
return "N/A"
}
val stdout = new StringBuffer()
val stderr = new StringBuffer()
def outputLog = "Version command: \n" + versionCommand +
......
......@@ -33,7 +33,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
var outputDir: String = {
val temp = Config.getValueFromMap(Config.global.map, ConfigValueIndex(this.configName, configPath, "output_dir"))
if (temp.isEmpty) throw new IllegalArgumentException("No output_dir defined in config")
if (temp.isEmpty) ""
else {
val t = temp.get.value.toString
if (!t.endsWith("/")) t + "/" else t
......@@ -54,7 +54,8 @@ trait BiopetQScript extends Configurable with GatkLogging {
final def script() {
outputDir = config("output_dir")
if (!outputDir.endsWith("/")) outputDir += "/"
if (outputDir.isEmpty) outputDir = new File(".").getAbsolutePath()
else if (!outputDir.endsWith("/")) outputDir += "/"
init
biopetScript
......@@ -63,11 +64,15 @@ trait BiopetQScript extends Configurable with GatkLogging {
case _ =>
}
for (function <- functions) function match {
case f: BiopetCommandLineFunctionTrait => f.afterGraph
case f: BiopetCommandLineFunctionTrait => {
f.checkExecutable
f.afterGraph
}
case _ =>
}
Config.global.writeReport(qSettings.runName, outputDir + ".log/" + qSettings.runName)
if (new File(outputDir).canWrite) Config.global.writeReport(qSettings.runName, outputDir + ".log/" + qSettings.runName)
else BiopetQScript.addError("Output dir: '" + outputDir + "' is not writeable")
BiopetQScript.checkErrors
}
......@@ -82,15 +87,23 @@ trait BiopetQScript extends Configurable with GatkLogging {
object BiopetQScript extends Logging {
private val errors: ListBuffer[Exception] = ListBuffer()
def addError(msg: String): Unit = {
def addError(error: String, debug: String = null): Unit = {
val msg = error + (if (debug != null && logger.isDebugEnabled) "; " + debug else "")
errors.append(new Exception(msg))
}
protected def checkErrors: Unit = {
if (!errors.isEmpty) {
for (e <- errors) {
logger.error(e.getMessage)
logger.debug(e.getStackTrace.mkString("Stack trace:\n", "\n", "\n"))
logger.error("*************************")
logger.error("Biopet found some errors:")
if (logger.isDebugEnabled) {
for (e <- errors) {
logger.error(e.getMessage)
logger.debug(e.getStackTrace.mkString("Stack trace:\n", "\n", "\n"))
}
} else {
val set = errors.map(_.getMessage).toSet
set.toList.sorted.foreach(logger.error(_))
}
throw new IllegalStateException("Biopet found errors")
}
......
......@@ -51,7 +51,7 @@ class Fastqc(val root: Configurable) extends BiopetCommandLineFunction {
override def afterGraph {
this.checkExecutable
val fastqcDir = executable.substring(0, executable.lastIndexOf("/"))
val fastqcDir = new File(executable).getParent
contaminants = contaminants match {
// user-defined contaminants file take precedence
......
......@@ -335,8 +335,8 @@ object ConfigUtils extends Logging {
val exist = valueExists(value)
if (!exist)
BiopetQScript.addError("Value does not exist but is required, key: " + value.requestIndex.key +
" module: " + value.requestIndex.module +
(if (value.requestIndex.path != Nil) " path: " + value.requestIndex.path.mkString("->") else ""))
" module: " + value.requestIndex.module,
(if (value.requestIndex.path != Nil) " path: " + value.requestIndex.path.mkString("->") else null))
exist
}
......
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