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

Changes in config class

parent 385bfef9
{
"reference": "bla",
"bedtools": { "exe": "test"},
"samtools": { "exe": "test"}
}
......@@ -50,12 +50,12 @@ class BamMetrics(val root:Configurable) extends QScript with BiopetQScript {
else targetInterval.output, targetInterval.output, targetDir))
val strictOutputBam = new File(targetDir, inputBam.getName.stripSuffix(".bam") + ".overlap.strict.bam")
add(BedtoolsIntersect(this, inputBam, bedFile, strictOutputBam, minOverlap = config("strictintersectoverlap", 1.0)), true)
add(BedtoolsIntersect(this, inputBam, bedFile, strictOutputBam, minOverlap = config("strictintersectoverlap", default=1.0)), true)
add(SamtoolsFlagstat(this, strictOutputBam))
add(BiopetFlagstat(this, strictOutputBam, targetDir))
val looseOutputBam = new File(targetDir, inputBam.getName.stripSuffix(".bam") + ".overlap.loose.bam")
add(BedtoolsIntersect(this, inputBam, bedFile, looseOutputBam, minOverlap = config("looseintersectoverlap", 0.01)), true)
add(BedtoolsIntersect(this, inputBam, bedFile, looseOutputBam, minOverlap = config("looseintersectoverlap", default=0.01)), true)
add(SamtoolsFlagstat(this, looseOutputBam))
add(BiopetFlagstat(this, looseOutputBam, targetDir))
......
package nl.lumc.sasc.biopet.pipelines.bammetrics.scripts
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
import nl.lumc.sasc.biopet.core.config.Configurable
import nl.lumc.sasc.biopet.function.PythonCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.{Input, Output, Argument}
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import java.io.File
class CoverageStats(val root:Configurable) extends PythonCommandLineFunction {
......
package nl.lumc.sasc.biopet.core
import org.broadinstitute.gatk.utils.commandline._
import scala.sys.process._
import nl.lumc.sasc.biopet.core.config._
abstract class BiopetCommandLineFunction extends BiopetCommandLineFunctionTrait {
protected def cmdLine: String
final def commandLine: String = {
......
......@@ -40,8 +40,8 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
if (threads > 1) nCoresRequest = Option(threads)
if (vmem == null) {
if (configContains("vmem")) vmem = config("vmem")
else if (!defaultVmem.isEmpty) vmem = defaultVmem
vmem = config("vmem")
if (vmem == null && !defaultVmem.isEmpty) vmem = defaultVmem
}
if (vmem != null) jobResourceRequests :+= "h_vmem=" + vmem
jobName = this.analysisName + ":" + firstOutput.getName
......@@ -101,15 +101,15 @@ trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurab
}
def getThreads(default:Int) : Int = {
val maxThreads: Int = config("maxthreads", 8)
val threads: Int = config("threads", default)
val maxThreads: Int = config("maxthreads", default=8)
val threads: Int = config("threads", default=default)
if (maxThreads > threads) return threads
else return maxThreads
}
def getThreads(default:Int, module:String) : Int = {
val maxThreads: Int = config("maxthreads", 8, module)
val threads: Int = config("threads", default, module)
val maxThreads: Int = config("maxthreads", default=8, submodule=module)
val threads: Int = config("threads", default=default, submodule=module)
if (maxThreads > threads) return threads
else return maxThreads
}
......
......@@ -9,6 +9,7 @@ trait MultiSampleQScript extends BiopetQScript {
final def runSamplesJobs : Map[String,Map[String,File]] = {
var output: Map[String,Map[String,File]] = Map()
samples = config("samples")
if (samples == null) samples = Map()
if (globalConfig.contains("samples")) for ((key,value) <- samples) {
var sample = Configurable.any2map(value)
if (!sample.contains("ID")) sample += ("ID" -> key)
......
......@@ -107,7 +107,7 @@ class Config(var map: Map[String,Any]) extends Logging {
val requestedIndex = ConfigValueIndex(module,path,key)
if (contains(requestedIndex)) return foundCache(requestedIndex)
else {
logger.error("Value in config could not be found but it seems required, inde: " + requestedIndex)
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)
}
}
......
......@@ -10,25 +10,43 @@ trait Configurable extends Logging {
protected val configName = getClass.getSimpleName.toLowerCase
protected val configFullPath = configName :: configPath
def config(key:String) = globalConfig(configName, configPath, key)
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 config(key:String, default:Any = null, submodule:String = null, required:Boolean = false): 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 (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)
}
//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, module:String) = globalConfig.contains(module, configName :: configPath, key)
//def configContains(key:String) = globalConfig.contains(configName, configPath, key)
def configContains(key:String, submodule:String = null) = {
val m = if (submodule != null) submodule else configName
val p = if (submodule != null) configName :: configPath else configPath
globalConfig.contains(m, p, key)
}
implicit def configValue2file(value:ConfigValue) = new File(Configurable.any2string(value.value))
implicit def configValue2string(value:ConfigValue) = Configurable.any2string(value.value)
implicit def configValue2long(value:ConfigValue) = Configurable.any2long(value.value)
implicit def configValue2int(value:ConfigValue) = Configurable.any2int(value.value)
implicit def configValue2optionInt(value:ConfigValue) = Option(Configurable.any2int(value.value))
implicit def configValue2double(value:ConfigValue) = Configurable.any2double(value.value)
implicit def configValue2optionDouble(value:ConfigValue) = Option(Configurable.any2double(value.value))
implicit def configValue2boolean(value:ConfigValue) = Configurable.any2boolean(value.value)
implicit def configValue2list(value:ConfigValue) = Configurable.any2list(value.value)
implicit def configValue2stringList(value:ConfigValue) = Configurable.any2stringList(value.value)
implicit def configValue2stringSet(value:ConfigValue) = Configurable.any2stringList(value.value).toSet
implicit def configValue2map(value:ConfigValue) = Configurable.any2map(value.value)
implicit def configValue2file(value:ConfigValue): File = if (value != null) new File(Configurable.any2string(value.value)) else null
implicit def configValue2string(value:ConfigValue): String = if (value != null) Configurable.any2string(value.value) else null
implicit def configValue2long(value:ConfigValue): Long = if (value != null) Configurable.any2long(value.value) else 0
implicit def configValue2optionLong(value:ConfigValue): Option[Long] = if (value != null) Option(Configurable.any2long(value.value)) else None
implicit def configValue2int(value:ConfigValue): Int = if (value != null) Configurable.any2int(value.value) else 0
implicit def configValue2optionInt(value:ConfigValue): Option[Int] = if (value != null) Option(Configurable.any2int(value.value)) else None
implicit def configValue2double(value:ConfigValue): Double = if (value != null) Configurable.any2double(value.value) else 0
implicit def configValue2optionDouble(value:ConfigValue): Option[Double] = if (value != null) Option(Configurable.any2double(value.value)) else None
implicit def configValue2boolean(value:ConfigValue): Boolean = if (value != null) Configurable.any2boolean(value.value) else false
implicit def configValue2optionBoolean(value:ConfigValue): Option[Boolean] = if (value != null) Option(Configurable.any2boolean(value.value)) else None
implicit def configValue2list(value:ConfigValue): List[Any] = if (value != null) Configurable.any2list(value.value) else null
implicit def configValue2stringList(value:ConfigValue): List[String] = if (value != null) Configurable.any2stringList(value.value) else null
implicit def configValue2stringSet(value:ConfigValue): Set[String] = if (value != null) Configurable.any2stringList(value.value).toSet else null
implicit def configValue2map(value:ConfigValue): Map[String, Any] = if (value != null) Configurable.any2map(value.value) else null
}
object Configurable extends Logging {
......
package nl.lumc.sasc.biopet.function
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline._
import java.io.File
......
package nl.lumc.sasc.biopet.function
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.queue.function.InProcessFunction
import org.broadinstitute.gatk.utils.commandline._
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import java.io.File
import scala.sys.process._
import scala.sys.process.Process
class Ln(val root:Configurable) extends InProcessFunction with Configurable {
this.analysisName = getClass.getSimpleName
......
package nl.lumc.sasc.biopet.function
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
//import org.broadinstitute.sting.queue.function.CommandLineFunction
import org.broadinstitute.gatk.utils.commandline._
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import java.io.File
class Pbzip2(val root:Configurable) extends BiopetCommandLineFunction {
......@@ -13,16 +12,16 @@ class Pbzip2(val root:Configurable) extends BiopetCommandLineFunction {
@Output(doc="Unzipped file")
var output: File = _
executable = config("exe", "pbzip2")
executable = config("exe", default="pbzip2")
var decomrpess = true
var memory: Int = config("memory", 1000)
var memory: Option[Int] = config("memory")
override val defaultVmem = (memory * 2 / 1000) + "G"
override val defaultVmem = (memory.getOrElse(1000) * 2 / 1000) + "G"
override val defaultThreads = 2
override def beforeCmd {
memory = memory * threads
if (!memory.isEmpty) memory = Option(memory.get * threads)
}
def cmdLine = required(executable) +
......
package nl.lumc.sasc.biopet.function
import java.io.FileOutputStream
import nl.lumc.sasc.biopet.core._
import org.broadinstitute.gatk.utils.commandline._
import java.io.File
import org.broadinstitute.gatk.utils.commandline.{Input}
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import scala.collection.JavaConversions._
trait PythonCommandLineFunction extends BiopetCommandLineFunction {
@Input(doc="Python script", required=false)
var python_script: File = _
executable = config("python_exe", "python")
executable = config("exe", default="python", submodule="python")
protected var python_script_name : String = _
def setPythonScript(script:String) { setPythonScript(script,"") }
......
package nl.lumc.sasc.biopet.function
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline._
import java.io.File
......@@ -12,7 +12,7 @@ class Sha1sum(val root:Configurable) extends BiopetCommandLineFunction {
@Output(doc="Unzipped file")
var output: File = _
executable = config("exe","sha1sum")
executable = config("exe", default="sha1sum")
def cmdLine = required(executable) + required(input) + " > " + required(output)
}
\ No newline at end of file
package nl.lumc.sasc.biopet.function
import nl.lumc.sasc.biopet.core._
import nl.lumc.sasc.biopet.core.config._
import org.broadinstitute.gatk.utils.commandline._
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{Input, Output}
import java.io.File
class Zcat(val root:Configurable) extends BiopetCommandLineFunction {
......@@ -12,7 +12,7 @@ class Zcat(val root:Configurable) extends BiopetCommandLineFunction {
@Output(doc="Unzipped file")
var output: File = _
executable = config("exe", "zcat")
executable = config("exe", default="zcat")
def cmdLine = required(executable) + required(input) + " > " + required(output)
}
......
......@@ -3,7 +3,7 @@ package nl.lumc.sasc.biopet.function.bedtools
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
abstract class Bedtools extends BiopetCommandLineFunction {
executable = config("exe", "bedtools", "bedtools")
executable = config("exe", default="bedtools", submodule="bedtools")
override def versionCommand = executable + " --version"
override val versionRegex = """bedtools (.*)""".r
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ class BedtoolsIntersect(val root:Configurable) extends Bedtools {
var output: File = _
@Argument(doc="Min overlap", required=false)
var minOverlap: Double = config("minoverlap", 1E-9)
var minOverlap: Option[Double] = config("minoverlap")
@Argument(doc="Only count", required=false)
var count: Boolean = false
......@@ -29,7 +29,7 @@ class BedtoolsIntersect(val root:Configurable) extends Bedtools {
def cmdLine = required(executable) + required("intersect") +
required(inputTag, input) +
required("-b", intersectFile) +
required("-f", minOverlap) +
optional("-f", minOverlap) +
conditional(count, "-c") +
" > " + required(output)
}
......@@ -41,7 +41,7 @@ object BedtoolsIntersect {
bedtoolsIntersect.input = input
bedtoolsIntersect.intersectFile = intersect
bedtoolsIntersect.output = output
if (minOverlap > 0) bedtoolsIntersect.minOverlap = minOverlap
if (minOverlap > 0) bedtoolsIntersect.minOverlap = Option(minOverlap)
bedtoolsIntersect.count = count
return bedtoolsIntersect
}
......
......@@ -23,10 +23,10 @@ class CalculateHsMetrics(val root:Configurable) extends Picard {
var perTargetCoverage: File = _
@Argument(doc="Reference file", required = false)
var reference: File = config("reference", "")
var reference: File = config("reference")
@Argument(doc="METRIC_ACCUMULATION_LEVEL", required=false)
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel", List())
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel")
@Argument(doc="BAIT_SET_NAME", required = false)
var baitSetName: String = _
......
......@@ -11,38 +11,39 @@ class CollectAlignmentSummaryMetrics(val root:Configurable) extends Picard {
var input: File = _
@Argument(doc="MAX_INSERT_SIZE", required = false)
var maxInstertSize: Int = config("maxInstertSize", 100000)
var maxInstertSize: Option[Int] = config("maxInstertSize")
@Argument(doc="ADAPTER_SEQUENCE", required = false)
var adapterSequence: List[String] = config("adapterSequence", Nil)
var adapterSequence: List[String] = config("adapterSequence")
@Argument(doc="IS_BISULFITE_SEQUENCED", required = false)
var isBisulfiteSequenced: Boolean = config("isBisulfiteSequenced", false)
var isBisulfiteSequenced: Option[Boolean] = config("isBisulfiteSequenced")
@Output(doc="The output file to write statistics to", required = true)
var output: File = _
@Argument(doc="Reference file", required = false)
var reference: File = config("reference", "")
var reference: File = config("reference")
@Argument(doc="ASSUME_SORTED", required = false)
var assumeSorted: Boolean = config("assumeSorted", false)
var assumeSorted: Boolean = config("assumeSorted", default=true)
@Argument(doc="METRIC_ACCUMULATION_LEVEL", required=false)
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel", List())
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel")
@Argument(doc="STOP_AFTER", required = false)
var stopAfter: Long = config("stopAfter", 0)
var stopAfter: Option[Long] = config("stopAfter")
override def commandLine = super.commandLine +
required("INPUT=", input, spaceSeparated=false) +
required("OUTPUT=", output, spaceSeparated=false) +
optional("REFERENCE_SEQUENCE=", reference, spaceSeparated=false) +
repeat("METRIC_ACCUMULATION_LEVEL=", metricAccumulationLevel, spaceSeparated=false) +
required("MAX_INSERT_SIZE=", maxInstertSize, spaceSeparated=false) +
required("IS_BISULFITE_SEQUENCED=", isBisulfiteSequenced, spaceSeparated=false) +
optional("MAX_INSERT_SIZE=", maxInstertSize, spaceSeparated=false) +
optional("IS_BISULFITE_SEQUENCED=", isBisulfiteSequenced, spaceSeparated=false) +
optional("ASSUME_SORTED=", assumeSorted, spaceSeparated=false) +
optional("STOP_AFTER=", stopAfter, spaceSeparated=false)
optional("STOP_AFTER=", stopAfter, spaceSeparated=false) +
repeat("ADAPTER_SEQUENCE=", adapterSequence, spaceSeparated=false)
}
object CollectAlignmentSummaryMetrics {
......
......@@ -20,19 +20,19 @@ class CollectGcBiasMetrics(val root:Configurable) extends Picard {
var outputSummary: File = _
@Argument(doc="Reference file", required = false)
var reference: File = config("reference", "")
var reference: File = config("reference", required=true)
@Argument(doc="Window size", required = false)
var windowSize: Int = config("windowsize", 100)
var windowSize: Option[Int] = config("windowsize")
@Argument(doc="MINIMUM_GENOME_FRACTION", required=false)
var minGenomeFraction: Double = config("mingenomefraction", 1.0E-5)
var minGenomeFraction: Option[Double] = config("mingenomefraction")
@Argument(doc="ASSUME_SORTED", required=false)
var assumeSorted: Boolean = config("assumesorted", false)
var assumeSorted: Boolean = config("assumesorted", default=true)
@Argument(doc="IS_BISULFITE_SEQUENCED", required=false)
var isBisulfiteSequinced: Boolean = config("isbisulfitesequinced", false)
var isBisulfiteSequinced: Option[Boolean] = config("isbisulfitesequinced")
override def afterGraph {
if (outputChart == null) outputChart = new File(output + ".pdf")
......@@ -48,7 +48,7 @@ class CollectGcBiasMetrics(val root:Configurable) extends Picard {
optional("WINDOW_SIZE=", windowSize, spaceSeparated=false) +
optional("MINIMUM_GENOME_FRACTION=", minGenomeFraction, spaceSeparated=false) +
conditional(assumeSorted, "ASSUME_SORTED=TRUE") +
conditional(isBisulfiteSequinced, "IS_BISULFITE_SEQUENCED=TRUE")
conditional(isBisulfiteSequinced.getOrElse(false), "IS_BISULFITE_SEQUENCED=TRUE")
}
object CollectGcBiasMetrics {
......
......@@ -17,25 +17,25 @@ class CollectInsertSizeMetrics(val root:Configurable) extends Picard {
var outputHistogram: File = _
@Argument(doc="Reference file", required = false)
var reference: File = config("reference", "")
var reference: File = config("reference")
@Argument(doc="DEVIATIONS", required = false)
var deviations: Double = config("deviations", 10.0)
var deviations: Option[Double] = config("deviations")
@Argument(doc="MINIMUM_PCT", required=false)
var minPct: Double = config("minpct", 0.05)
var minPct: Option[Double] = config("minpct")
@Argument(doc="ASSUME_SORTED", required=false)
var assumeSorted: Boolean = config("assumesorted", false)
var assumeSorted: Boolean = config("assumesorted", default=true)
@Argument(doc="STOP_AFTER", required=false)
var stopAfter: Long = config("metricaccumulationlevel", 0)
var stopAfter: Option[Long] = config("stopAfter")
@Argument(doc="METRIC_ACCUMULATION_LEVEL", required=false)
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel", List())
var metricAccumulationLevel: List[String] = config("metricaccumulationlevel")
@Argument(doc="HISTOGRAM_WIDTH", required=false)
var histogramWidth: Int = config("histogramWidth", 0)
var histogramWidth: Option[Int] = config("histogramWidth")
override def afterGraph {
if (outputHistogram == null) outputHistogram = new File(output + ".pdf")
......@@ -49,8 +49,8 @@ class CollectInsertSizeMetrics(val root:Configurable) extends Picard {
required("REFERENCE_SEQUENCE=", reference, spaceSeparated=false) +
optional("DEVIATIONS=", deviations, spaceSeparated=false) +
repeat("METRIC_ACCUMULATION_LEVEL=", metricAccumulationLevel, spaceSeparated=false) +
(if (stopAfter > 0) optional("STOP_AFTER=", stopAfter, spaceSeparated=false) else "") +
(if (histogramWidth > 0) optional("HISTOGRAM_WIDTH=", histogramWidth, spaceSeparated=false) else "") +
optional("STOP_AFTER=", stopAfter, spaceSeparated=false) +
optional("HISTOGRAM_WIDTH=", histogramWidth, spaceSeparated=false) +
conditional(assumeSorted, "ASSUME_SORTED=TRUE")
}
......
Supports Markdown
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