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

Change getVersion to Option[String]

parent 15e4e777
......@@ -135,10 +135,10 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
protected val versionExitcode = List(0)
/** Executes the version command */
private def getVersionInternal: String = {
if (versionCommand == null || versionRegex == null) return "N/A"
private def getVersionInternal: Option[String] = {
if (versionCommand == null || versionRegex == null) return None
val exe = new File(versionCommand.trim.split(" ")(0))
if (!exe.exists()) return "N/A"
if (!exe.exists()) return None
val stdout = new StringBuffer()
val stderr = new StringBuffer()
def outputLog = "Version command: \n" + versionCommand +
......@@ -147,25 +147,28 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
val process = Process(versionCommand).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n"))
if (!versionExitcode.contains(process.exitValue)) {
logger.warn("getVersion give exit code " + process.exitValue + ", version not found \n" + outputLog)
return "N/A"
return None
}
for (line <- stdout.toString.split("\n") ++ stderr.toString.split("\n")) {
line match {
case versionRegex(m) => return m
case versionRegex(m) => return Some(m)
case _ =>
}
}
logger.warn("getVersion give a exit code " + process.exitValue + " but no version was found, executable correct? \n" + outputLog)
return "N/A"
return None
}
/** Get version from cache otherwise execute the version command */
def getVersion: String = {
def getVersion: Option[String] = {
if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable))
preProcesExecutable
if (!BiopetCommandLineFunctionTrait.versionCache.contains(executable))
BiopetCommandLineFunctionTrait.versionCache += executable -> getVersionInternal
return BiopetCommandLineFunctionTrait.versionCache(executable)
if (!BiopetCommandLineFunctionTrait.versionCache.contains(versionCommand))
getVersionInternal match {
case Some(version) => BiopetCommandLineFunctionTrait.versionCache += versionCommand -> version
case _ =>
}
BiopetCommandLineFunctionTrait.versionCache.get(versionCommand)
}
/**
......
......@@ -64,8 +64,8 @@ class Fastqc(val root: Configurable) extends BiopetCommandLineFunction {
// otherwise, use default contaminants file (depending on FastQC version)
case None =>
val defaultContams = getVersion match {
case "v0.11.2" => new File(fastqcDir + "/Configuration/contaminant_list.txt")
case _ => new File(fastqcDir + "/Contaminants/contaminant_list.txt")
case Some("v0.11.2") => new File(fastqcDir + "/Configuration/contaminant_list.txt")
case _ => new File(fastqcDir + "/Contaminants/contaminant_list.txt")
}
config("contaminants", default = defaultContams)
}
......@@ -76,8 +76,8 @@ class Fastqc(val root: Configurable) extends BiopetCommandLineFunction {
// otherwise, check if adapters are already present (depending on FastQC version)
case None =>
val defaultAdapters = getVersion match {
case "v0.11.2" => Option(new File(fastqcDir + "/Configuration/adapter_list.txt"))
case _ => None
case Some("v0.11.2") => Option(new File(fastqcDir + "/Configuration/adapter_list.txt"))
case _ => None
}
defaultAdapters.collect { case adp => config("adapters", default = adp) }
}
......
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