Skip to content
Snippets Groups Projects
Commit 82597e1f authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added a freeVar option to the config

parent 7a63ece8
No related branches found
No related tags found
No related merge requests found
......@@ -73,9 +73,10 @@ class Config(var map: Map[String, Any]) extends Logging {
var defaultCache: Map[ConfigValueIndex, ConfigValue] = Map()
def contains(s: String): Boolean = map.contains(s)
def contains(requestedIndex: ConfigValueIndex): Boolean = contains(requestedIndex.module, requestedIndex.path, requestedIndex.key)
def contains(module: String, path: List[String], key: String): Boolean = {
val requestedIndex = ConfigValueIndex(module, path, key)
def contains(requestedIndex: ConfigValueIndex, freeVar:Boolean): Boolean = contains(requestedIndex.module, requestedIndex.path, requestedIndex.key, freeVar)
def contains(requestedIndex: ConfigValueIndex): Boolean = contains(requestedIndex.module, requestedIndex.path, requestedIndex.key, true)
def contains(module: String, path: List[String], key: String, freeVar:Boolean = true): Boolean = {
val requestedIndex = ConfigValueIndex(module, path, key, freeVar)
if (notFoundCache.contains(requestedIndex)) return false
else if (foundCache.contains(requestedIndex)) return true
else {
......@@ -89,12 +90,13 @@ class Config(var map: Map[String, Any]) extends Logging {
foundCache += (requestedIndex -> ConfigValue.apply(requestedIndex, ConfigValueIndex(module, submodules2, key), p(key)))
return true
}
val p2 = getMapFromPath(submodules2)
//logger.debug("p2: " + p2)
if (p2.contains(key)) {
foundCache += (requestedIndex -> ConfigValue.apply(requestedIndex, ConfigValueIndex(module, submodules2, key), p2(key)))
return true
if (freeVar) {
val p2 = getMapFromPath(submodules2)
//logger.debug("p2: " + p2)
if (p2.contains(key)) {
foundCache += (requestedIndex -> ConfigValue.apply(requestedIndex, ConfigValueIndex(module, submodules2, key), p2(key)))
return true
}
}
submodules2 = submodules2.init
}
......@@ -104,7 +106,7 @@ class Config(var map: Map[String, Any]) extends Logging {
if (p.contains(key)) { // Module is not nested
foundCache += (requestedIndex -> ConfigValue.apply(requestedIndex, ConfigValueIndex(module, Nil, key), p(key)))
return true
} else if (this.contains(key)) { // Root value of json
} else if (this.contains(key) && freeVar) { // Root value of json
foundCache += (requestedIndex -> ConfigValue.apply(requestedIndex, ConfigValueIndex("", Nil, key), get(key)))
return true
} else { // At this point key is not found on the path
......@@ -117,24 +119,27 @@ class Config(var map: Map[String, Any]) extends Logging {
private def get(key: String): Any = map(key)
private def get(key: String, default: Any): Any = if (contains(key)) get(key) else default
def apply(module: String, path: List[String], key: String, default: Any): ConfigValue = {
def apply(module: String, path: List[String], key: String, default: Any = null, freeVar:Boolean = true): ConfigValue = {
val requestedIndex = ConfigValueIndex(module, path, key)
if (contains(requestedIndex)) return foundCache(requestedIndex)
else {
if (contains(requestedIndex, freeVar)) return foundCache(requestedIndex)
else if (default != null) {
defaultCache += (requestedIndex -> ConfigValue.apply(requestedIndex, null, default, true))
return defaultCache(requestedIndex)
}
}
def apply(module: String, path: List[String], key: String): ConfigValue = {
val requestedIndex = ConfigValueIndex(module, path, key)
if (contains(requestedIndex)) return foundCache(requestedIndex)
else {
} else {
logger.error("Value in config could not be found but it seems required, index: " + requestedIndex)
throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
}
}
// def apply(module: String, path: List[String], key: String, freeVar:Boolean = true): ConfigValue = {
// val requestedIndex = ConfigValueIndex(module, path, key)
// if (contains(requestedIndex, freeVar)) return foundCache(requestedIndex)
// else {
// logger.error("Value in config could not be found but it seems required, index: " + requestedIndex)
// throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
// }
// }
private def getMapFromPath(path: List[String]): Map[String, Any] = {
var returnMap: Map[String, Any] = map
for (m <- path) {
......
package nl.lumc.sasc.biopet.core.config
class ConfigValueIndex(val module: String, val path: List[String], val key: String) {
override def toString = "Module = " + module + ", path = " + path + ", key = " + key
class ConfigValueIndex(val module: String, val path: List[String], val key: String, val freeVar:Boolean = true) {
override def toString = "Module = " + module + ", path = " + path + ", key = " + key + ", freeVar = " + freeVar
}
object ConfigValueIndex {
private var cache: Map[(String, List[String], String), ConfigValueIndex] = Map()
def apply(module: String, path: List[String], key: String): ConfigValueIndex = {
if (!cache.contains(module, path, key)) cache += ((module, path, key) -> new ConfigValueIndex(module, path, key))
def apply(module: String, path: List[String], key: String, freeVar:Boolean = true): ConfigValueIndex = {
if (!cache.contains(module, path, key)) cache += ((module, path, key) -> new ConfigValueIndex(module, path, key, freeVar))
return cache(module, path, key)
}
}
\ No newline at end of file
......@@ -10,27 +10,27 @@ trait Configurable extends Logging {
protected val configName = getClass.getSimpleName.toLowerCase
protected val configFullPath = configName :: configPath
def config(key: String, default: Any = null, submodule: String = null, required: Boolean = false): ConfigValue = {
def config(key: String, default: Any = null, submodule: String = null, required: Boolean = false, freeVar:Boolean = true): ConfigValue = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
if (!configContains(key, submodule) && default == null) {
if (!configContains(key, submodule, freeVar) && default == null) {
if (required) {
logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
} else return null
}
if (default == null) return globalConfig(m, p, key)
else return globalConfig(m, p, key, default)
if (default == null) return globalConfig(m, p, key, freeVar)
else return globalConfig(m, p, key, default, freeVar)
}
//def config(key:String, default:Any) = globalConfig(configName, configPath, key, default)
//def config(key:String, default:Any, module:String) = globalConfig(module, configName :: configPath, key, default)
//def configContains(key:String) = globalConfig.contains(configName, configPath, key)
def configContains(key: String, submodule: String = null) = {
def configContains(key: String, submodule: String = null, freeVar:Boolean = true) = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
globalConfig.contains(m, p, key)
globalConfig.contains(m, p, key, freeVar)
}
implicit def configValue2file(value: ConfigValue): File = if (value != null) new File(Configurable.any2string(value.value)) else null
......
......@@ -19,7 +19,7 @@ class Fastqc(val root: Configurable) extends BiopetCommandLineFunction {
var output: File = _
executable = config("exe", default = "fastqc")
var java_exe: String = config("exe", default = "java", submodule = "java")
var java_exe: String = config("exe", default = "java", submodule = "java", freeVar = false)
var kmers: Option[Int] = config("kmers")
var quiet: Boolean = config("quiet")
var noextract: Boolean = config("noextract")
......
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