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

Added commandline support for config

parent 2d1626f6
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,12 @@ import scala.collection.mutable.ListBuffer ...@@ -30,9 +30,12 @@ import scala.collection.mutable.ListBuffer
*/ */
trait BiopetQScript extends Configurable with GatkLogging { trait BiopetQScript extends Configurable with GatkLogging {
@Argument(doc = "JSON config file(s)", fullName = "config_file", shortName = "config", required = false) @Argument(doc = "JSON / YAML config file(s)", fullName = "config_file", shortName = "config", required = false)
val configfiles: List[File] = Nil val configfiles: List[File] = Nil
@Argument(doc = "JSON config file(s)", fullName = "config_value", shortName = "cv", required = false)
val configValues: List[String] = Nil
var outputDir: File = { var outputDir: File = {
Config.getValueFromMap(globalConfig.map, ConfigValueIndex(this.configName, configPath, "output_dir")) match { Config.getValueFromMap(globalConfig.map, ConfigValueIndex(this.configName, configPath, "output_dir")) match {
case Some(value) => new File(value.asString).getAbsoluteFile case Some(value) => new File(value.asString).getAbsoluteFile
...@@ -61,7 +64,11 @@ trait BiopetQScript extends Configurable with GatkLogging { ...@@ -61,7 +64,11 @@ trait BiopetQScript extends Configurable with GatkLogging {
* Script from queue itself, final to force some checks for each pipeline and write report * Script from queue itself, final to force some checks for each pipeline and write report
*/ */
final def script() { final def script() {
outputDir = config("output_dir").asFile.getAbsoluteFile if (config.contains("output_dir")) outputDir = config("output_dir").asFile.getAbsoluteFile
else {
outputDir = new File(".").getAbsoluteFile
BiopetQScript.addError("No output_dir defined in config")
}
init init
biopetScript biopetScript
......
...@@ -42,6 +42,17 @@ trait PipelineCommand extends MainCommand with GatkLogging { ...@@ -42,6 +42,17 @@ trait PipelineCommand extends MainCommand with GatkLogging {
if (t >= argsSize) throw new IllegalStateException("-config needs a value") if (t >= argsSize) throw new IllegalStateException("-config needs a value")
Config.global.loadConfigFile(new File(args(t + 1))) Config.global.loadConfigFile(new File(args(t + 1)))
} }
if (args(t) == "-cv" || args(t) == "--config_value") {
val v = args(t + 1).split("=")
require(v.size == 2, "Value should be formatted like 'key=value' or 'path:path:key=value'")
val value = v(1)
val p = v(0).split(":")
val key = p.last
val path = p.dropRight(1).toList
Config.global.addValue(key, value, path)
}
if (args(t) == "--logging_level" || args(t) == "-l") { if (args(t) == "--logging_level" || args(t) == "-l") {
args(t + 1).toLowerCase match { args(t + 1).toLowerCase match {
case "debug" => Logging.logger.setLevel(org.apache.log4j.Level.DEBUG) case "debug" => Logging.logger.setLevel(org.apache.log4j.Level.DEBUG)
......
...@@ -79,6 +79,19 @@ class Config(var map: Map[String, Any], ...@@ -79,6 +79,19 @@ class Config(var map: Map[String, Any],
} }
} }
/**
* Add a single vallue to the config
* @param key key of value
* @param value value itself
* @param path Path to value
* @param default if true value is put in default map
*/
def addValue(key: String, value: Any, path: List[String] = Nil, default: Boolean = false): Unit = {
val valueMap = path.foldRight(Map(key -> value))((a, b) => Map(a -> b))
if (default) defaults = mergeMaps(valueMap, defaults)
else map = mergeMaps(valueMap, map)
}
protected[config] var notFoundCache: List[ConfigValueIndex] = List() protected[config] var notFoundCache: List[ConfigValueIndex] = List()
protected[config] var foundCache: Map[ConfigValueIndex, ConfigValue] = Map() protected[config] var foundCache: Map[ConfigValueIndex, ConfigValue] = Map()
protected[config] var defaultCache: Map[ConfigValueIndex, ConfigValue] = Map() protected[config] var defaultCache: Map[ConfigValueIndex, ConfigValue] = Map()
......
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