diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala index 1c557e5223634fdc14d992313e006bca6b141c90..c0d8747dde7d5598acc80ea7e85b9c3c5ec72941 100644 --- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala +++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala @@ -5,13 +5,15 @@ */ package nl.lumc.sasc.biopet.extensions.gatk.broad -import nl.lumc.sasc.biopet.core.{ Version, CommandLineResources, Reference, BiopetJavaCommandLineFunction } +import nl.lumc.sasc.biopet.core._ import org.broadinstitute.gatk.engine.phonehome.GATKRunReport import org.broadinstitute.gatk.queue.extensions.gatk.CommandLineGATK trait GatkGeneral extends CommandLineGATK with CommandLineResources with Reference with Version { memoryLimit = Option(3) + var executable: String = config("java", default = "java", submodule = "java", freeVar = false) + override def subPath = "gatk" :: super.subPath jarFile = config("gatk_jar") @@ -20,6 +22,7 @@ trait GatkGeneral extends CommandLineGATK with CommandLineResources with Referen override def defaultCoreMemory = 4.0 override def faiRequired = true + override def dictRequired = true if (config.contains("intervals")) intervals = config("intervals").asFileList if (config.contains("exclude_intervals")) excludeIntervals = config("exclude_intervals").asFileList @@ -39,5 +42,8 @@ trait GatkGeneral extends CommandLineGATK with CommandLineResources with Referen override def versionExitcode = List(0, 1) def versionCommand = "java" + " -jar " + jarFile + " -version" - override def getVersion = super.getVersion.collect { case v => "Gatk " + v } + override def getVersion = { + executable = BiopetCommandLineFunction.preProcessExecutable(executable).path + super.getVersion.collect { case v => "Gatk " + v } + } } diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala index 45dbe227c72cd10243b38ea9865ed01f4ad493bc..5b84bcc39a75ea5a1ea25b5b6288c7caba595cbc 100644 --- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala +++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala @@ -91,50 +91,19 @@ trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction => } - /** can override this value is executable may not be converted to CanonicalPath */ + /** + * Can override this value is executable may not be converted to CanonicalPath + * @deprecated + */ val executableToCanonicalPath = true /** * Checks executable. Follow full CanonicalPath, checks if it is existing and do a md5sum on it to store in job report */ protected[core] def preProcessExecutable() { - if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { - if (executable != null) { - if (!BiopetCommandLineFunction.executableCache.contains(executable)) { - try { - val oldExecutable = executable - val buffer = new StringBuffer() - val cmd = Seq("which", executable) - val process = Process(cmd).run(ProcessLogger(buffer.append(_))) - if (process.exitValue == 0) { - executable = buffer.toString - val file = new File(executable) - if (executableToCanonicalPath) executable = file.getCanonicalPath - else executable = file.getAbsolutePath - } else Logging.addError("executable: '" + executable + "' not found, please check config") - BiopetCommandLineFunction.executableCache += oldExecutable -> executable - BiopetCommandLineFunction.executableCache += executable -> executable - } catch { - case ioe: java.io.IOException => - logger.warn(s"Could not use 'which' on '$executable', check on executable skipped: " + ioe) - } - } else executable = BiopetCommandLineFunction.executableCache(executable) - - if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { - if (new File(executable).exists()) { - val is = new FileInputStream(executable) - val cnt = is.available - val bytes = Array.ofDim[Byte](cnt) - is.read(bytes) - is.close() - val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase - BiopetCommandLineFunction.executableMd5Cache += executable -> temp - } else BiopetCommandLineFunction.executableMd5Cache += executable -> "file_does_not_exist" - } - } - } - val md5 = BiopetCommandLineFunction.executableMd5Cache.get(executable) - addJobReportBinding("md5sum_exe", md5.getOrElse("None")) + val exe = BiopetCommandLineFunction.preProcessExecutable(executable) + executable = exe.path + addJobReportBinding("md5sum_exe", exe.md5.getOrElse("N/A")) } /** executes checkExecutable method and fill job report */ @@ -230,7 +199,49 @@ trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction => } /** stores global caches */ -object BiopetCommandLineFunction { +object BiopetCommandLineFunction extends Logging { private[core] val executableMd5Cache: mutable.Map[String, String] = mutable.Map() private[core] val executableCache: mutable.Map[String, String] = mutable.Map() + + private case class Executable(path: String, md5: Option[String]) + def preProcessExecutable(executable: String): Executable = { + if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { + if (executable != null) { + if (!BiopetCommandLineFunction.executableCache.contains(executable)) { + try { + val oldExecutable = executable + val buffer = new StringBuffer() + val cmd = Seq("which", executable) + val process = Process(cmd).run(ProcessLogger(buffer.append(_))) + if (process.exitValue == 0) { + val file = new File(buffer.toString) + BiopetCommandLineFunction.executableCache += executable -> file.getAbsolutePath + } else { + Logging.addError("executable: '" + executable + "' not found, please check config") + BiopetCommandLineFunction.executableCache += executable -> executable + } + } catch { + case ioe: java.io.IOException => + logger.warn(s"Could not use 'which' on '$executable', check on executable skipped: " + ioe) + BiopetCommandLineFunction.executableCache += executable -> executable + } + } + + if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) { + val newExe = BiopetCommandLineFunction.executableCache(executable) + if (new File(newExe).exists()) { + val is = new FileInputStream(executable) + val cnt = is.available + val bytes = Array.ofDim[Byte](cnt) + is.read(bytes) + is.close() + val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase + BiopetCommandLineFunction.executableMd5Cache += newExe -> temp + } else BiopetCommandLineFunction.executableMd5Cache += newExe -> "file_does_not_exist" + } + } + } + Executable(BiopetCommandLineFunction.executableCache(executable), + BiopetCommandLineFunction.executableMd5Cache.get(executable)) + } }