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

Made a global config

parent 5c3e9590
...@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.core ...@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.core
import java.io.File import java.io.File
import java.io.PrintWriter import java.io.PrintWriter
import nl.lumc.sasc.biopet.core.config.Configurable import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
import org.broadinstitute.gatk.utils.commandline.Argument import org.broadinstitute.gatk.utils.commandline.Argument
import org.broadinstitute.gatk.queue.QSettings import org.broadinstitute.gatk.queue.QSettings
import org.broadinstitute.gatk.queue.function.QFunction import org.broadinstitute.gatk.queue.function.QFunction
...@@ -25,7 +25,7 @@ trait BiopetQScript extends Configurable { ...@@ -25,7 +25,7 @@ trait BiopetQScript extends Configurable {
var functions: Seq[QFunction] var functions: Seq[QFunction]
final def script() { final def script() {
for (file <- configfiles) globalConfig.loadConfigFile(file) for (file <- configfiles) Config.global.loadConfigFile(file)
if (!outputDir.endsWith("/")) outputDir += "/" if (!outputDir.endsWith("/")) outputDir += "/"
init init
biopetScript biopetScript
...@@ -33,7 +33,7 @@ trait BiopetQScript extends Configurable { ...@@ -33,7 +33,7 @@ trait BiopetQScript extends Configurable {
case f: BiopetCommandLineFunctionTrait => f.afterGraph case f: BiopetCommandLineFunctionTrait => f.afterGraph
case _ => case _ =>
} }
val configReport = globalConfig.getReport val configReport = Config.global.getReport
val configReportFile = new File(outputDir + qSettings.runName + ".configreport.txt") val configReportFile = new File(outputDir + qSettings.runName + ".configreport.txt")
configReportFile.getParentFile.mkdir configReportFile.getParentFile.mkdir
val writer = new PrintWriter(configReportFile) val writer = new PrintWriter(configReportFile)
......
package nl.lumc.sasc.biopet.core package nl.lumc.sasc.biopet.core
import nl.lumc.sasc.biopet.core.config.Configurable import nl.lumc.sasc.biopet.core.config.{ Config, Configurable }
trait MultiSampleQScript extends BiopetQScript { trait MultiSampleQScript extends BiopetQScript {
type LibraryOutput <: AbstractLibraryOutput type LibraryOutput <: AbstractLibraryOutput
...@@ -20,7 +20,7 @@ trait MultiSampleQScript extends BiopetQScript { ...@@ -20,7 +20,7 @@ trait MultiSampleQScript extends BiopetQScript {
final def runSamplesJobs() { final def runSamplesJobs() {
samplesConfig = config("samples") samplesConfig = config("samples")
if (samplesConfig == null) samplesConfig = Map() if (samplesConfig == null) samplesConfig = Map()
if (globalConfig.contains("samples")) for ((key, value) <- samplesConfig) { if (Config.global.contains("samples")) for ((key, value) <- samplesConfig) {
var sample = Configurable.any2map(value) var sample = Configurable.any2map(value)
if (!sample.contains("ID")) sample += ("ID" -> key) if (!sample.contains("ID")) sample += ("ID" -> key)
if (sample("ID") == key) { if (sample("ID") == key) {
......
...@@ -105,6 +105,8 @@ class Config(var map: Map[String, Any]) extends Logging { ...@@ -105,6 +105,8 @@ class Config(var map: Map[String, Any]) extends Logging {
} }
object Config { object Config {
val global = new Config
def valueToMap(input: Any): Map[String, Any] = { def valueToMap(input: Any): Map[String, Any] = {
input match { input match {
case m: Map[_, _] => return m.asInstanceOf[Map[String, Any]] case m: Map[_, _] => return m.asInstanceOf[Map[String, Any]]
......
...@@ -6,7 +6,7 @@ import scala.language.implicitConversions ...@@ -6,7 +6,7 @@ import scala.language.implicitConversions
trait Configurable extends Logging { trait Configurable extends Logging {
val root: Configurable val root: Configurable
val globalConfig: Config = if (root != null) root.globalConfig else new Config() //val globalConfig: Config = if (root != null) root.globalConfig else new Config()
def configPath: List[String] = if (root != null) root.configFullPath else List() def configPath: List[String] = if (root != null) root.configFullPath else List()
protected lazy val configName = getClass.getSimpleName.toLowerCase protected lazy val configName = getClass.getSimpleName.toLowerCase
protected lazy val configFullPath = configName :: configPath protected lazy val configFullPath = configName :: configPath
...@@ -29,15 +29,15 @@ trait Configurable extends Logging { ...@@ -29,15 +29,15 @@ trait Configurable extends Logging {
throw new IllegalStateException("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 } else return null
} }
if (d == null) return globalConfig(m, p, key, freeVar) if (d == null) return Config.global(m, p, key, freeVar)
else return globalConfig(m, p, key, d, freeVar) else return Config.global(m, p, key, d, freeVar)
} }
def contains(key: String, submodule: String = null, freeVar: Boolean = true) = { def contains(key: String, submodule: String = null, freeVar: Boolean = true) = {
val m = if (submodule != null) submodule else configName val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath val p = if (submodule != null) configName :: configPath else configPath
globalConfig.contains(m, p, key, freeVar) || !(Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) == None) Config.global.contains(m, p, key, freeVar) || !(Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) == None)
} }
} }
......
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