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